[SOLVED] Write a c++ program to add word to the prefix tree

I’m studying and need help with a Computer Science question to help me learn.

Struggling to find relevant content or pressed for time? – Don’t worry, we have a team of professionals to help you on
[SOLVED] Write a c++ program to add word to the prefix tree
Get a 15% Discount on this Paper
Order Now

A prefix tree is a data structure that stores a collection of words in a tree structure. Each node in a prefix tree represents a single character in a word, and it has up to 26 children, one for each letter of the alphabet. Since words can appear inside other words, prefix tree nodes also keep track of whether a word ends after their character.

For example, the prefix tree containing the words be, bee, bed, best, and cat would look like the tree below (nodes that end words have a double circle):

prefixtree.png

Note that the root node doesn’t have an associated letter; the first letter of the word is a child of the root node. Also, nodes will never have more than one child for the same letter: the words “be”, “bee”, “bed”, and “best” all share the “b” node below the root.

Your task for this lab is to implement two member functions for a PrefixTree class. The first member function is addWord. This function accepts a string, and it adds nodes to the PrefixTree so that this word is included. For example, to add the word “car” to the tree above, you would need to add a new node containing “r” below the “a” node. To add “dog”, you would need to add 3 new nodes (“d”, “o”, and “g”) below the root node.

The second member function to implement is contains. This function accepts a string and returns whether that word has been added to the PrefixTree. The prefix tree above contains “be”, but it doesn’t contain “beer” or “bes”.

You have been provided with some code to get you started.

The most relevant member functions are described below:

  • PrefixTree::getRoot(): returns the root node of the PrefixTree
  • PrefixTreeNode::getChild(char): returns the child of this node corresponding to the given letter (null pointer if that child doesn’t exist)
  • PrefixTreeNode::addChild(char): adds a child to this node that corresponds to the given letter
  • PrefixTreeNode::isFinal(): returns whether this node is the end of a word
  • PrefixTreeNode::setFinal(bool): changes whether this node ends a word

The provided driver file accepts 4 different commands. The “quit” command ends the program, while typing “add word” will add a word to the PrefixTree (replace “word” with what you want to add). Typing “search word” will print out whether the tree contains that word, and typing “print” will print out a representation of the PrefixTree. The print functionality prints children after their parent, and if a node has multiple children, they appear as a comma-separated list in parentheses. Letters that end a word are capitalized. For example, the prefix tree in the example above would be printed as “(bE(D,E,sT),caT)”. The print function is already implemented, so you can use this to test your addWord function.

You should submit a source file that contains the definitions of the missing addWord and contains member functions of PrefixTree.

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
Sign up, place your order, and leave the rest to our professional paper writers in less than 2 minutes.
step 1
Upload assignment instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
s
Get personalized services with MyCoursebay
One writer for all your papers
You can select one writer for all your papers. This option enhances the consistency in the quality of your assignments. Select your preferred writer from the list of writers who have handledf your previous assignments
Same paper from different writers
Are you ordering the same assignment for a friend? You can get the same paper from different writers. The goal is to produce 100% unique and original papers
Copy of sources used
Our homework writers will provide you with copies of sources used on your request. Just add the option when plaing your order
What our partners say about us
We appreciate every review and are always looking for ways to grow. See what other students think about our do my paper service.
Philosophy
i got the paper a bit late but it is good quality will for sure come back and use this website.
Customer 452611, September 9th, 2021
ENVIRONMENT SCIENCE
GOOD
Customer 452813, June 19th, 2022
Nurse
Great work! Thank you for the quality you put in each assignment.
Customer 452707, February 4th, 2022
Other
Great work! Thank so much!
Customer 452707, March 1st, 2022
Other
Amazing work
Customer 452909, September 4th, 2024
Human Resources Management (HRM)
Thanks
Customer 452701, August 15th, 2023
Other
I appreciate your work. Thank you????
Customer 452949, September 15th, 2023
Nursing
Thank you!!!
Customer 452557, June 26th, 2021
Nursing
Always a job well done. I really appreciate the hard work.
Customer 452453, January 4th, 2021
Human Resources Management (HRM)
Thank you so much.
Customer 452701, August 14th, 2023
Accounting
Thanks for your support
Customer 452701, February 3rd, 2022
Nursing
Top notch quality!
Customer 452453, February 16th, 2023
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat

Good News ! We now help with PROCTORED EXAM. Chat with a support agent for more information