Question

. (4 points-Completeness) Implementing Multiway Trie Below is C++ node class defined as class MultiwayTrie f class Node publi
(b) (2 points-Completeness)Write the implementation of the find method of the MultiwayTrie class method below. /* Return true
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(a)

void insert(string word)

{

    struct Node *crawl = root;

    for (int i = 0; i < word.length(); i++)

    {

        int index = word[i] - 'a';

        if (!Crawl->children[index]) { // If not present inserts word into trie

struct Node *t = new Node;   

crawl->children[index] = t;

}

        crawl = crawl->children[index];

    }

crawl->word = true;    //mark leaf node as end

}

(b)

bool find(string word)

{

    struct Node *crawl = root;   

    for (int i = 0; i < word.length(); i++)

    {

        int index = word[i] - 'a';

        if (!crawl->children[index])

            return false;

        crawl = crawl->children[index];

    }

  

    return (crawl != NULL && crawl->word);

}

Add a comment
Know the answer?
Add Answer to:
. (4 points-Completeness) Implementing Multiway Trie Below is C++ node class defined as class MultiwayTrie f...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this assignment you’ll implement a data structure called a trie, which is used to answer...

    In this assignment you’ll implement a data structure called a trie, which is used to answer queries regarding the characteristics of a text file (e.g., frequency of a given word). This write-up introduces the concept of a trie, specifies the API you’re expected to implement, and outlines submission instructions as well as the grading rubric. Please carefully read the entire write-up before you begin coding your submission. Tries A trie is an example of a tree data structure that compactly...

  • Summary You will write an application to build a tree structure called Trie for a dictionary...

    Summary You will write an application to build a tree structure called Trie for a dictionary of English words, and use the Trie to generate completion lists for string searches. Trie Structure A Trie is a general tree, in that each node can have any number of children. It is used to store a dictionary (list) of words that can be searched on, in a manner that allows for efficient generation of completion lists. The word list is originally stored...

  • Need help with these two questions String outputBreadthFirstSearch(): returns a string represenng a breadth first traversal....

    Need help with these two questions String outputBreadthFirstSearch(): returns a string represenng a breadth first traversal. So, for example, for the tree shown in Figure 1, the method should output the string "bcaahttaetersse" 4. String outputDepthFirstSearch(): returns a string represenng a pre order depth first traversal. So, for example, for the tree shown in Figure 1, the method should output the string "batcathateersse This is my code so far public class Trie { final TrieNode root; public Trie() { this.root...

  • Question - modify the code below so that for a node, the value of every node...

    Question - modify the code below so that for a node, the value of every node of its right subtree is less the node, and the value of each node of its left subtree is greater than the node. - create such a binary tree in the Main method, and call the following method:  InOrder(Node theRoot),  PreOrder(Node theRoot),  PostOrder(Node theRoot),  FindMin(),  FindMax(),  Find(int key) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;...

  • Instructions Create a class BettterTree that extends OurTree, to facilitate the following. Update: if extending the...

    Instructions Create a class BettterTree that extends OurTree, to facilitate the following. Update: if extending the class is too much, you can modify class OurTree. In our discussions about OurTree, we focused on nodes and their left and right children. For each node in the tree, is there another node of interest in addition to its children? If yes, how would you extend OurTree for that? How will the behavior of addNode method change? OurTree Code: public class OurTree {...

  • Using the following implementation of Tree class Node   {   public int iData;              // data item (key)   public...

    Using the following implementation of Tree class Node   {   public int iData;              // data item (key)   public double dData;           // data item   public Node leftChild;         // this node's left child   public Node rightChild;        // this node's right child   public void displayNode()      // display ourself      {      System.out.print('{');      System.out.print(iData);      System.out.print(", ");      System.out.print(dData);      System.out.print("} ");      }   }  // end class Node //------------------------------------------------------------------ import java.io.IOException; import java.util.Stack; public class Tree { private Node root; // first node of tree // ------------------------------------------------------------- public Tree() // constructor { root = null; }...

  • 3. (Gaddis Exercises 20.4) Tree Height Write a recursive member function for the BinaryTree class that...

    3. (Gaddis Exercises 20.4) Tree Height Write a recursive member function for the BinaryTree class that returns the height of the tree. The height of the tree is the number of levels it contains. Demonstrate the function in a driver program. CPP FILE CODE: #include "BinaryTree.h" #include <iostream> using namespace std; BinaryTree::BinaryTree() { root = NULL; } BinaryTree::~BinaryTree() { destroy(root); } bool BinaryTree::search(int data) { return search(data, root); } void BinaryTree::insert(int data) { insert(data, root); } void BinaryTree::traverseInOrder() { traverseInOrder(root);...

  • Can anyone help me to convert below code from c# to c++? // C#: public class...

    Can anyone help me to convert below code from c# to c++? // C#: public class TernaryTree { private Node m_root = null; private void Add(string s, int pos, ref Node node) { if (node == null) { node = new Node(s[pos], false); } if (s[pos] < node.m_char) { Add(s, pos, ref node.m_left); } else if (s[pos] > node.m_char) { Add(s, pos, ref node.m_right); } else { if (pos + 1 == s.Length) { node.m_wordEnd = true; } else {...

  • Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the...

    Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the beginning(root) of the linked list. 2. A removeFromBeginning() function, that removes the node from the beginning of the linked list and assigns the next element as the new beginning(root). 3. A traverse function, that iterates the list and prints the elements in the linked list. For the insertAtBeginning(Node newNode) function: 1. Check if the root is null. If it is, just assign the new...

  • Question B1 You are given the following Java classes: public class Queue { private static class...

    Question B1 You are given the following Java classes: public class Queue { private static class Node { Object object; Node next; Node () { object = null; next = null; } Node (Object object, Node next) { this.object = object; this.next = next; private Node header; private int size = 0; // size shows the no of elements in queue public Object dequeue () { if (size == 0 ) { return null; else { Object remove_object = header.object;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT