Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is my Trie class public interface. can someone help me implement this function using TRIE data structure? void insert(const string& key, const ValueType& value)

image text in transcribed

here is my Trie class public interface.

image text in transcribed

can someone help me implement this function using TRIE data structure?

void insert(const string& key, const ValueType& value) The inser0 method associates the specified key with the specified value in your trie, e.g. "GATTACA" 42 by adding the appropriate nodes (if any are required) to the trie, and then adding the specified value (e.g., 42) to the existing set of values in the appropriate node. A given key inserted in the trie may map to onc or more values, c.g., "GATTACA" > 142, 17, 32, 42, 42, 19, 17), and those values may include duplicates. Here's how you might define a trie variable that maps strings to ints and insert a few items: Trie trie; // This is like std: :multimap<:string trie trie.insert gattaca> (42, 17) trie.insert("GATTACA", 42); // GATTACA > f42, 17, 42) trie.insert("GCTTACA", 30); GCTTACA > (30) There are a number of ways you can associate a given trie node with one or more values, including having a vector or list of values associated with cach trie nodc. You can choosc any approach you wish. Your insert0 function must run in O(L*C) time where L is the length of the inserted key and C is the average number of children per node in your trie. With a clever approach, you may be able to gct your insertO function to run in O(L) time, but this is not required. void insert(const string& key, const ValueType& value) The inser0 method associates the specified key with the specified value in your trie, e.g. "GATTACA" 42 by adding the appropriate nodes (if any are required) to the trie, and then adding the specified value (e.g., 42) to the existing set of values in the appropriate node. A given key inserted in the trie may map to onc or more values, c.g., "GATTACA" > 142, 17, 32, 42, 42, 19, 17), and those values may include duplicates. Here's how you might define a trie variable that maps strings to ints and insert a few items: Trie trie; // This is like std: :multimap<:string trie trie.insert gattaca> (42, 17) trie.insert("GATTACA", 42); // GATTACA > f42, 17, 42) trie.insert("GCTTACA", 30); GCTTACA > (30) There are a number of ways you can associate a given trie node with one or more values, including having a vector or list of values associated with cach trie nodc. You can choosc any approach you wish. Your insert0 function must run in O(L*C) time where L is the length of the inserted key and C is the average number of children per node in your trie. With a clever approach, you may be able to gct your insertO function to run in O(L) time, but this is not required

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Write formal proposal requests.

Answered: 1 week ago

Question

Write an effective news release.

Answered: 1 week ago

Question

Identify the different types of proposals.

Answered: 1 week ago