2223 22CLC01 Final - Lab
2223 22CLC01 Final - Lab
Problem 1 (3.0p)
Given a binary tree, print all nodes whose left sum is equal to the right sum. Explain your
algorithm in comments.
The prototype of the function is as follows: void printNodesWithEqualSums(TreeNode* r);
For example:
Problem 2 (3.0p)
Given a binary tree, write function (and auxiliary functions if needed) to display the keys of all
the nodes in the longest path going from the root to a leaf of the tree. If there are many such
paths, display any of them.
The prototype of the function is as follows: void printLongestPath (TreeNode* r);
Data Structures & Algorithms 22CLC01
Problem 3 (3.0p)
Given the list of numbers as follow: 76, 93, 40, 47, 10, 55.
You are asked to define structure and functions to put those numbers into a hash table of 7
slots (m = 7), using
- The hash function as follows: h1(k) = k mod m.
- The Collision resolution: Linear probing.
And you also need to write these functions:
- bool search(int key, int&val): searching a value for a given key.
- bool delete(int key): deleting a key value pair
Problem 4 (1.0p)
Write the main function to demonstrate all above problems.
Submission: