Describe an algorithm to determine if the nodes of some binary tree - T ( n nodes ) can be assigned with ranks s.t. T could be considered a WAVL - TREE.
The algorithm should be as efficient as possible.
Definition of a WAVL tree : https://en.wikipedia.org/wiki/WAVL_tree
Properties of WVAL Trees.
Consist of collection of nodes of two types. External Nodes and Internal Nodes.
In that way, the final n/2 operations in the AVL tree will take at least (n/2)logn time, while in the WAVL it will take n/2 time (can be proved with potential function).
WAVL (weak AVL trees) are a relaxed variant of an older rank-balanced BST, the AVL tree. Rank-balanced trees are trees in which every node has an integer rank that corresponds roughly to the height of the node (within c log h to be exact, where c is a constant and h is the height of the tree). Given these ranks, different rank rules can be defined to give different BSTs. In a WAVL tree, the rank difference between any two adjacent nodes can only be 1 or 2, where leaves always have rank 0, and leaves have two "dummy nodes" as children with rank -1. They use rotations as a constant-time restructuring primitive and guarantee that during insertion and deletion, at most two rotations will be performed. The rank rule together with the rebalancing algorithms guarantee an upper bound of 2 log n for the height of the tree.
Insertion into WAVL trees is done the same way as insertion in standard BSTs, but a series of rebalancing steps must be done from the newly inserted node, possibly up to the root. Deletion is also done as it is in standard BSTs, with a series of rebalancing steps up to the root. Searches are performed identically to searches in standard BSTs.
Rank-Balanced Binary Search Trees These notes describe a relaxation of AVL trees. These trees have properties like those of redblack trees but are slightly easier to maintain. In particular, rebalancing after an insertion or a deletion takes one single or double rotation and logarithmic time worst case, O(1) time amortized. Red-black trees require up to three single rotations for a deletion, AVL trees a logarithmic number.
A ranked binary tree is a binary tree whose nodes have integer ranks, with leaves having rank zero and missing nodes having rank minus one. If x is a child, the rank difference of x, ∆x, is the rank of its parent minus the rank of x. The rank of a ranked tree is the rank of its root. An AVL tree is a ranked binary tree such that every child has rank difference one or two and every node has at least one child with rank difference one. We call this the balance condition. In an AVL tree the rank of a node is its height; this will no longer be true when we relax the balance condition.
To represent an AVL tree we store with each node pointers to its children and, if it is a child, a bit that indicates whether its rank difference is one or two; we do not need to store ranks explicitly

*Note that a binary search tree, T, provides almost everything you need in order to implement your system, since it can maintain a sorted set of items so as to perform insertions and removals based on their keys (which in this case are birth dates). It also supports nearest-neighbor queries, in that, for any key k, we can perform a search in T for the smallest key that is greater than or equal to k, or, alternatively, for the largest key that is less than or equal to k. Given either of the nodes in T storing such a key, we can then perform a forward or backward inorder traversal of T starting from that point to list neighboring smaller or larger keys.
Algorithm IterativeTreeSearch(k, T):
Input: A search key k and a binary search tree, T
Output: A node in T that is either an internal node storing key k or the external node where an item with key k would belong in T if it existed
v ← T.root()
while v is not an external node do
if k = key(v) then
return v
else if k < key(v) then
v ← T.leftChild(v)
else v ← T.rightChild(v)
return v
As mentioned above, the worst-case performance of searching in a binary search tree can be as bad as linear time, since the time to perform a search is proportional to the height of the search tree. Such a performance is no better than that of looking through all the elements in a set to find an item of interest. In order to avoid this poor performance, we need ways of maintaining the height of a search tree to be logarithmic in the number of nodes it has.
Balanced Binary Search Trees The primary way to achieve logarithmic running times for search and update operations in a binary search tree, T, is to perform restructuring actions on T based on specific rules that maintain some notion of “balance” between sibling subtrees in T. We refer to a binary search tree that can maintain a height of O(log n) through such balancing rules and actions as a balanced binary search tree. Intuitively, the reason balance is so important is that when a binary search tree T is balanced, the number of nodes in the tree increases exponentially as one moves down the levels of T. Such an exponential increase in size implies that if T stores n items, then it will have height O(log n).
Algorithm restructure(x):
Input: A node x of a binary search tree T that has both a parent y and a grandparent z
Output: Tree T after a trinode restructuring (which corresponds to a single or double rotation) involving nodes x, y, and z
1: Let (a, b, c) be a left-to-right (inorder) listing of the nodes x, y, and z, and let (T0, T1, T2, T3) be a left-to-right (inorder) listing of the four subtrees of x, y, and z that are not rooted at x, y, or z.
2: Replace the subtree rooted at z with a new subtree rooted at b.
3: Let a be the left child of b and let T0 and T1 be the left and right subtrees of a, respectively.
4: Let c be the right child of b and let T2 and T3 be the left and right subtrees of c, respectively.
5: Recalculate the heights of a, b, and c, (or a “standin” function for height), from the corresponding values stored at their children, and return b.
Describe an algorithm to determine if the nodes of some binary tree - T ( n...
Describe an algorithm that checks if a given binary tree T is a binary search tree. Analyze your algorithm by giving its asymptotic runtime. Show your work.
In a binary tree, the balance ratio of node v, bal(v), is the number of nodes in the left subtree of node v divided by the sum of the number of nodes in the right and left subtrees of node v. bal(a leaf node) = ½. A tree T is said to be ε-balanced if, for all nodes v in T, ½ - ε < bal(v) < ½ + ε. Design an efficient recursive algorithm that determines whether a binary...
Let T be a proper binary tree. Given a node v ∈ T, the imbalance of v, denoted imbalance(v), is defined as the difference, in absolute value, between the number of leaves of the left subtree of v and the number of leaves of the right subtree of v. (If v is a leaf, then imbalance(v) is defined to be 0.) Define imbalance(T) = maxv∈T imbalance(v). (a) Provide an upper bound to the imbalance of a proper binary tree with...
Show that the tree height of a height-balanced binary search tree with n nodes is O(log n). (Hint: Let T(h) denote the fewest number of nodes that a height-balanced binary search tree of height h can have. Express T(h) in terms of T(h-1) and T(h-2). Then, find a lower bound of T(h) in terms of T(h-2). Finally, express the lower bound of T(h) in terms of h.)
Let T be a binary tree with n nodes and let f() be the level
numbering function of the positions of T
f suggests a epteseniatñion of a binary tree Tty in el marabering function f suggests a f an aray-ased wucture A. with the lt of the array We show an etample of an an el ermbering funcion f sugests a represeuani sl Wr show an example of an antay baed rerjesctanisa od a A with the clement an...
A collection of nodes is arranged as a binary search tree ordered on the field INFO which contains distinct positive integers for each of the nodes. In addition to INFO, LLINK and RLINK, each node has three other fields CLASS SUCC and PRED CLASS is an information field containing a single letter that denotes the class to which the node belongs (there being up to 26 classes). The nodes in each class are arranged as a doubly-linked circular list with...
2. Write a recursive algorithm which computes the number of nodes in a general tree. 3. Show a tree achieving the worst-case running time for algorithm depth. 4. Let T be a tree whose nodes store strings. Give an efficient algorithm that computes and prints, for every node v of T, the string stored at v and the height of the subtree rooted at v. Hin Consider 'decorating' the tree, and add a height field to each node (initialized to...
Is it possible that the preorder traversal of a binary tree T visit the nodes in the reverse order of the postorder traversal of T? If so, give an example: otherwise, argue why this cannot occur.
Design a recursive algorithm that determines whether the number of leaf nodes of a Binary Search Tree (BST) is even or odd. An empty tree has an even number of leaves. A tree consisting of just a root has an odd number of leaves. Your function should return true for an even number of leaves, and false for an odd number of leaves. Analyze the execution time of your algorithm. Giving only the execution time without explanation will not be...
Design a recursive algorithm that determines whether the number of leaf nodes of a Binary Search Tree (BST) is even or odd. An empty tree has an even number of leaves. A tree consisting of just a root has an odd number of leaves. Your function should return true for an even number of leaves, and false for an odd number of leaves. Analyze the execution time of your algorithm. Giving only the execution time without explanation will not be...