[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.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your 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.
Pro service tips
How to get the most out of your experience with MyCoursebay
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Nurse
Great work! Thank you for the quality you put in each assignment.
Customer 452707, February 4th, 2022
Other
great
Customer 452813, June 25th, 2022
Social Work and Human Services
Great Work!
Customer 452587, November 2nd, 2021
Management
Great job
Customer 452643, October 31st, 2021
Criminal Justice
Great work! Followed directions to the latter.
Customer 452485, September 1st, 2021
Nursing
Thanks
Customer 452521, May 13th, 2021
Other
AWESOME
Customer 452813, June 20th, 2022
Nursing
Perfectly done! Thanks again.
Customer 452707, July 18th, 2022
Nursing
Perfectly done!
Customer 452707, July 18th, 2022
Social Work and Human Services
Excellent Work
Customer 452587, November 22nd, 2021
Ethics
thank you
Customer 452493, March 15th, 2021
Nursing
Always perfect!!! Don is the best!
Customer 452453, July 27th, 2021
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
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
NEW

Thank you for choosing MyCoursebay. Your presence is a motivation to us. All papers are written from scratch. Plagiarism is not tolerated. Order now for a 15% discount

Order Now