Trie Data Structure: Implementation, Analysis & White House Shuffle

Verified

Added on  2023/06/11

|7
|721
|301
Homework Assignment
AI Summary
This assignment provides a detailed solution for implementing a Trie data structure, including an analysis of its time and space complexity. It explains how a trie is an ordered tree structure used to store a dynamic set or associative array, where keys are typically strings. The solution discusses the implementation details, focusing on node structure and traversal methods, especially for identifying leaf nodes. It also delves into the time complexity of creating a trie structure, which is O(n*m), where n is the number of strings and m is the length of the longest string. Furthermore, the assignment includes a class diagram and context of 'White House Shuffle' to demonstrate a practical application of tree structures, specifically addressing scenarios of hiring and firing employees and maintaining hierarchical order. The document includes code file and output screen.
Document Page
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Data Structure
1
Document Page
Table of Contents
1. Description.........................................................................................................................................1
2. Time and Space Complexity Analysis..............................................................................................2
3. Class Diagram....................................................................................................................................2
2
Document Page
1. Description
A trie is an arranged tree information structure that is utilized to store a dynamic set or
acquainted cluster where the keys are normally strings. Dissimilar to a twofold hunt tree, no node
in the tree stores the key related with that node, rather, its situation in the tree characterizes the
key with which it is related. Every one of the relatives of a node have a typical prefix of the
string related with that node, and the root is related with the unfilled string. Qualities are
typically not related with each node, just with leaves and some inward nodes that compare to
keys of intrigue.
A leaf node is the one whose left and right kid nodes are invalid. So we can print all leaf
nodes by crossing the tree, checking if the left and right nodes are invalid and after that printing
that leaf node. The rationale is particularly like post arrange traversal yet rather than simply
printing node, we first check if both left and right elements are invalid or not.
The Code File is attached below.
The output Screen is shown below.
3
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
2. Time and Space Complexity Analysis
The complexity to make a trie structure is O(n*m). Each time we navigate a string and
add it to the current structure, we play out a couple of activities like introducing. This is be that
as it may, a steady time task. It takes O(1) to make another node. It isn't really O(1) however
O(C) where C is a steady. This is rehashed in the most pessimistic scenario for every one of the
strings with length m. Here m would be the length of the longest string (most pessimistic
scenario many-sided quality) which would be rehashed for every one of the strings and
subsequently) (n*m). We have effectively considered the length in factor m and our C is a
consistent.
3. Class Diagram
President Donald Trump sta ed his underlying organization with people who helped himff
get chose. Anyway from that point forward, there has been a record measure of turnover in the
organization and they believe they require help keeping things straight. The white house's
progressive structure can be spoken to by a tree. Trump is the leader of the association. He has
two direct subordinates, Sessions and Pompeo. Individuals from the association who are
immediate subordinates of a similar part are positioned by their separate rank. In the outline, the
position of such individuals diminishes from left to right. For instance, Sessions has higher
position than Pompeo.
At the point when a part contracts an immediate subordinate, the recently enlisted
subordinate has bring down status than some other direct subordinates of a similar part. For
instance, if Trump contracts Kelly at that point Trumps coordinate subordinates are Sessions,
Pompeo and Kelly arranged by diminishing position. There is another approach while firing a
representative to streamline the procedure of substitution. There are two conceivable situations.
On the off chance that the casualty (the individual who gets fired) had no subordinates, at that
point he or she will just be dropped from the white house's pecking order. In the event that the
casualty had any subordinates, at that point his or her most noteworthy positioning (by status)
coordinate subordinate will be elevated to fill the subsequent opening. The advanced individual
will likewise acquire the casualty's status. Presently, if the advanced individual additionally had a
few subordinates, at that point his or her most astounding positioning direct subordinate will also
4
Document Page
be advanced, and the advancements will course down the chain of importance until the point
when a man having no subordinates has been advanced.
5
Document Page
6
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]