0% found this document useful (0 votes)
12 views3 pages

Fall2021 Test2

Yo

Uploaded by

5wp4bkzgp2
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)
12 views3 pages

Fall2021 Test2

Yo

Uploaded by

5wp4bkzgp2
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/ 3

CS3424 – DATA STRUCTURES

FINAL EXAM – FALL 2021


Duration : 3hrs 00 Min
Material forbidden

PART I: DEFINITIONS
Define the following words or phrases related to trees: binary tree, Strictly Binary tree, Full Binary
Tree, Complete Binary Tree, Binary Search Tree, AVL Tree, 2-4 Tree, B-Tree, Red-Black Tree,
balance factor, left-heavy, and right-heavy, 2-node, 3-node, and 4-node, external node, black depth.

PART II: SHORT QUESTIONS AND ALGORITHMS

1. In a binary tree, what is the maximum number of nodes a height n?


2. Prove that the maximum number of nodes in a tree of height h is 2h+1 – 1.
3. Show how a binary tree can be represented using an array.
4. Enumerate the three ways of traversing a binary tree and provide for each a recursive
method implementing it.
5. What is the maximum/minimum height for an AVL tree of 3 nodes, 5 nodes, and 7 nodes?
6. If an AVL tree has a height of 3, what maximum number of nodes can the tree have? What
minimum number of nodes can the tree have?
7. Present in a table the Time Complexities for the basic operations (search, insert, update,
delete) in RBTree, AVLTree, and Tree234.

PART III: PRACTICE


Exercise 1: BST
1. Consider the following binary search tree (BST).
a. List all the possible insertion orders (i.e., permutations) of the keys that could have
produced this BST.
b. Draw the same BST after the insertion of keys: 6, 45, 32, 98, 55, and 69, in this order
c. Draw the BST resulting from the deletion of keys 9 and 45 from the BST resulting from
question 1.b.
2. Draw the binary search tree obtained when the keys 1, 2, 3, 4, 5, 6, 7 are inserted in the
given order into an initially empty tree. What is the problem of the tree you get? Why is it
a problem? How could you modify the insertion algorithm to solve this problem? Justify
your answer.

Exercise 2. AVL
1. Given the following AVL Tree:

a. Draw the resulting AVL after 5 is removed, but before any rebalancing takes place. Label
each node in the resulting tree with its balance factor.
b. Now rebalance the tree that results from (i). Draw a new tree for each rotation that occurs
when rebalancing the AVL Tree (you only need to draw one tree that results from an RL
or LR rotation). You do not need to label these trees with balance factors.
2. Show the change of an AVL tree when inserting 1, 2, 3, 4, 10, 9, 7, 5, into the tree, in this
order.
3. For the tree built in the preceding question, show its change after 1, 2, 3, 4, 10, 9, 7, 5, are
deleted from the tree in this order.
Exercise 3: 2-4 trees and B-Trees
1. Explain how to search an element from a 2-4 tree.
2. Show the change of a 2–4 tree when inserting 1, 2, 3, 13, 4, 0,11, 10, 9, 7, 5, 8, and 6 into
it, in this order.
3. Show the process to sequentially delete 90, 52, 17, 32, and 68 from the following 2-4 tree

4. Construct a B-Tree of order 5 for the following data: 1, 6, 7, 2, 11, 5, 10, 13, 12, 20, 16, 24,
3, 4, 18, 19, 14, 25
Exercise 4: Red black trees
1. What are the three properties that characterize a red black tree?
2. How do you convert a 2-4 tree to a red black tree? Illustrate with an example.
3. How do you convert a red black tree to a 2-4 tree? Illustrate with an example.
4. Show the change of the tree when inserting 1, 2, 3, 4, 10, 9, 7, 5, 8, and 6 into it, in this
order.
5. For the tree built in the preceding question, show the change of the tree after deleting 1, 2,
3, 4, 10, 9, 7, 5, 8, and 6 from it in this order.

You might also like