Assignment5
Assignment5
Department of Mathematics
MA2101: Algorithm Lab
Assignment 5
Full Marks: 20
1. Write a function for inserting a node in a binary search tree. Construct a binary
search tree by inserting the keys, {23, 87, 45, 90, 60, 27, 53, 92, 77, 18, 7, 97, 25} in
any order you like. [3]
Write a function for searching for a key value in a BST and search 53 in the
BST. Your function should return the address of the node containing 53. [3]
Write a functions for in-order traversal in a BST. Print the keys while visiting
the nodes in the traversal. [3]
Write a function for finding predecessor of a given node. Find the predecessor
node of the node containing 53. [3]
Write a function for finding the common ancestor which is at maximum level of
two given nodes. Find the common ancestor which is at maximum level of the
nodes containing 53 and 25. [4]
Write the code for calculating average number of comparisons done while in-
serting the keys {23, 87, 45, 90, 60, 27, 53, 92, 77, 18, 7, 97, 25}. That is, add the
number of comparisons for each permutation of these keys and divide that by
the number of permutation. [4]