Other Group members present:
___________________ ___________________ ___________________Resources used:
In a binary search tree, each node contains a single data element and
"small" and "large" pointers to sub-trees (i.e. left
and
right
). A binary tree may be defined as follows:
Below is a binary search tree with the
numbers 1 through 5.
Now, consider the data as a circular doubly linked list.
The challenge is to take an ordered binary tree and rearrange the internal pointers to make a circular doubly linked list out of it. The left pointer should play the role of prev and the right pointer should play the role of next. The list should be arranged so that the nodes are in increasing order.
treeToList(Node root)
that takes an ordered
binary tree and rearranges the internal pointers to make a circular
doubly linked list out of the tree nodes. The prev pointers
should be stored in the left field and the next pointers should be
stored in the right field. The list should be arranged so that the
nodes are in increasing order. Return the head pointer to the new
list. The operation can be done in O(n) time -- essentially operating
on each node once.
18 10 15 12 6 3 8 14 13
The code in Trie.java shows how to add a word and how to look up a word. The picture below shows a trie containing the words that follow.
do, dog, dogma, ,dot, dote, ha, we, wed, weptThe black dot in each node indicates a
isWord
field
having value true
in some node; if there is no black dot
the isWord
field is false
.
Trie
method prefixList
that stores in an ArrayList all the words in a trie for which
prefix
is a prefix, e.g., if prefix
is tid, the list returned might contain:
tidal, tide, tides, tidied, tidiness, tidy, tidyingYou can use any existing code in writing the method.