You are on page 1of 1

Sheet (Tree)

1. Draw a binary search tree (BST) after inserting the following values in this order: 10,
5, 15, 13, 7, 2, 9, 6, 11, and 20.

2. Traverse the previous tree in the three different traversal approaches covered in the
lecture (preorder, inorder and postorder traversal).

3. Write a C function that increment all the values of a given binary tree by one.

4. Write a C function to search for a specific value in a binary tree and return 1 if found
and 0 otherwise.

5. Write a C function to search for a specific value in a BST and return 1 if found and 0
otherwise.

6. Write the definition of the C function, leaves_count that takes a pointer to the root
node of a binary tree as input and returns the number of leaves in a binary tree.

7. Given a binary search tree and a value k, please find a node in the binary search tree
whose value is closest to k.

8. Write a C function that traverses a binary tree level by level. In other words, the root
is visited first, then the immediate children of the root, then the grandchildren of the
root, and so on.

9. Given the preorder and inorder traversal sequences of a binary tree as follows:
preorder: ABCDEFGHIJKLM inorder: CEDFBAHJIKGML
Draw the binary tree.

10. From the following tree, show by


drawing how to:

a) Delete the value 45 in two


different ways.
b) Delete the value 89.
c) Delete the value 36.

You might also like