submit100 trie README solution.ccwhere you indicate how long the assignment took and with whom you collaborated in your README file. All work, code and otherwise, should be in your file solution.cc.
These problems are designed as a review of the algorithms, data
structures, and techniques we have discussed to date. You must
acknowledge in writing anyone with whom you check answers. You may
discuss approaches, but each person should turn in an individual
write-up of the problems. Please keep discussions at a high-level,
i.e., discuss algorithms and methods for solving problems, but not the
specific code that solves the problems.
Tries storing words are implemented with the following declarations:
The routine PrintTrie
below can be used to print all the strings stored in a trie.
You might model the function on the function TrieUnion below
and the hint that follows.
To summarize: make recursive calls to determine what's in the
trie-intersection below, and examine isWord fields to determine if the
current node/path represents a word in the intersection. Return an
empty trie unless there is something below or the current node/path is
in the intersection.
Part A (4 points)
Draw diagrams for both the adjacency list and adjacency matrix
representations of the graph above.
Write out a possible vertex ordering for both depth-first and breadth-first
traversals of the graph starting at vertex 0.
When is a binary tree a search tree (4 points)
Write a function IsBST that evaluates to
true if its parameter is a binary search tree and false otherwise.
Complexity I (2 points)
What is the asymptotic complexity of the code you wrote in the previous
problem? Support your answer.
Number Nodes (4 points)
Using the same declaration for binary trees as in the first problem,
write a function LevelNumber
that numbers each node in a binary
tree with the node's distance from the root. The root should be numbered
with zero, the root's children with distance 1, etc. You may find it
useful to write another function called from LevelNumber. Do not
worry about destroying the info field values already in the tree. Do
not use an auxiliary queue or other structure.
Trie some Times
A trie is a tree in which each node has as many (potential)
children as there are characters in whatever alphabet is being used. In
this problem assume that the alphabet is lower case letters 'a' -- 'z',
with the 'a'-child the zero-th child (i.e., map 'a'->0, ... 'z'->25).
Problem 1 : AddToTrie (4 points)
Write a function AddToTrie that adds a string to a trie. Note:
there is no recursion necessary (although recursion is ok). Traverse
the trie, following a branch for each letter of the string s.
If there is no branch to take, create one using new before
taking it.
Problem 2: TrieIntersect (4 points) OPTIONAL
Write a function TrieIntersect that returns a trie that is the
intersection of two tries.
Graph Stuff
Part B (4 points)
Owen L. Astrachan
Last modified: Tue Apr 29 09:43:48 EDT