Question: Implement algorithm TreeSearch(x, k). For k = 1 to 20, call TreeSearch(x, k) where x is the root node of the tree from Part A.
Implement algorithm TreeSearch(x, k). For k = 1 to 20, call TreeSearch(x, k) where x is the root node of the tree from Part A. Output True if k was found and output the value of its parent. Otherwise output false. (In Java Programming)
1.Searching for a node with a given key, k: TreeSearch(x,k) // x is the node where search starts if (x == NULL or k == x.Key) return x else if (k < x.Key) return TreeSearch(x.Left,k) else return TreeSearch(x.Right,k)
2. Minimum and Maximum keys TreeMin(x) while (x.Left!= NULL) x = x.Left return x; TreeMax(x) while (x.Right!= NULL) x = x.Right return x;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
