0% found this document useful (0 votes)
0 views

Assignment5

The document is an assignment for the Algorithm Lab course at the Indian Institute of Technology Patna, focusing on binary search trees (BST). It includes tasks such as inserting nodes, searching for a key, performing in-order traversal, finding a predecessor, determining a common ancestor, and calculating average comparisons during insertion. The assignment is to be submitted as a C++ file named 5.cpp and is worth a total of 20 marks.

Uploaded by

Laksh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Assignment5

The document is an assignment for the Algorithm Lab course at the Indian Institute of Technology Patna, focusing on binary search trees (BST). It includes tasks such as inserting nodes, searching for a key, performing in-order traversal, finding a predecessor, determining a common ancestor, and calculating average comparisons during insertion. The assignment is to be submitted as a C++ file named 5.cpp and is worth a total of 20 marks.

Uploaded by

Laksh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Indian Institute of Technology Patna

Department of Mathematics
MA2101: Algorithm Lab
Assignment 5
Full Marks: 20

Filename should be 5.cpp.

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]

You might also like