Ghulam Ishaq Khan Institute of
Engineering Sciences and Technology
Faculty of Computer Sciences and Engineering
CS221: Data Structures and Algorithms, FALL 2023
Assignment No. 3
Instructor: Dr. Qamar Abbas Date: 30/11/2023
Total Marks: 40 Deadline: 08/12/2023
Instructions:
• This is an individual assignment. No Late Submission is allowed.
• Getting unauthorized help on assignment may result in ZERO credit for the assignment.
• Append the screenshot of output of each question with the code on a word/pdf file.
• You are also required to submit a notepad file containing all the codes with the question
number.
Q # 1: [CLO-2 Code only] Sort an array of 10,000 elements using quicksort as follows:
a. Sort the array using pivot as the middle element of the array.
b. Sort the array using pivot as the median of the first, last, and middle elements of the
array.
c. Sort the array using pivot as the middle element of the array. However, when the size
of any sublist reduces to less than 20, sort the sublist using insertion sort.
d. Sort the array using pivot as the median of the first, last, and middle elements of the
array. When the size of any sublist reduces to less than 20, sort the sublist using insertion
sort.
e. What is the effect of choice of pivot made in previous parts on the complexity of the
algorithm.
Q # 2: [CLO-2 Show the pictorial view only, Code not required]. Consider an array with
values {14, 7, 3, 12, 9, 11, 6, 12}. Use Merge sort to sort the array.
Q # 3: [CLO-3 Code not required]
a. Draw the BST where the data value at each node is an integer and the values are
entered in the following order: 36, 22, 10, 44, 42.
b. Draw the BST after the following insertions have been done in the tree of part (a): 16,
25, 3, 23,24.
c. Now draw the tree after deletions of 42, 23 and 22 in this order.
d. Write down the order on which the node values are reached when the BST of part (c)
is traversed.
• in inorder
• in postorder
• in preorder
e. What is the height of the tree of part (c)? Which nodes have maximal depth in the tree of
part (c)?
Q # 4: [CLO-3 Code not required] Given the following AVL Tree:
a. Draw the resulting BST after 5 is removed, but before any rebalancing takes place.
Label each node in the resulting tree with its balance factor. Replace a node with both
children using an appropriate value from the node's left child.
b. Now rebalance the tree that results from (a). 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.
Q # 5: [CLO-3 Code not required] The keys 24, 39, 31, 46, 48, 34, 19, 5, and 29 are inserted
(in the order given) into an initially empty AVL tree. Show the AVL tree after each insertion.