0% found this document useful (0 votes)
6 views2 pages

2223 22CLC01 Final - Lab

Uploaded by

Ming Ming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

2223 22CLC01 Final - Lab

Uploaded by

Ming Ming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Structures & Algorithms 22CLC01

Final Lab – 22CLC01


75 minutes

You are asked to write a C/C++ functions:


Given the tree structure:
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
};

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:

Root folder named StudentID


File name: StudentID-XX.zip
Example: 22121234-08.zip

You might also like