University of Michigan 
EECS 281 Data Structures and Algorithms 
Homework 3 
Spring Semester, 2014 
 
Assigned:   06/02/14, 12:00pm 
Due:   06/11/14, 11:55pm 
Instructions: Homework is on 5 pages and is worth 25 total points. You must complete all                               
problems. Enter all responses into the CTools Test Center. For Test Center questions, be sure                             
to press the finish button to officially submit your answers. Please be sure to double check your                                 
submissions via a confirmation from CTools before deciding that the homework is submitted. A                           
key for the homework set will be posted after the due date. 
 
 
Clarifications:  
● Assume all C++ code to be C++11­standard compliant (compiled with ­std=c++11). 
● For all questions involving AVL tree operations, assume that replacements for deleted                       
nodes are found in the left subtree of the deleted node, that any rotation(s) necessary to                               
rebalance the tree are performed directly after each insertion/deletion, and that a node is                           
considered unbalanced if the absolute value  of its balance is greater than 1. 
● Questions involving complexity assume worst­case inputs and seek tightest bounds                   
unless otherwise specified. 
 
Homework Goals:
● Demonstrate comprehensive understanding of various sorting algorithms 
● Use tree­based data structures such as binary trees, binary search trees, and balanced 
binary search trees (AVL) 
● Apply various traversal methods to tree­based data structures 
● Understand the operational complexities of hashing 
● Understand common hash table collision resolution schemes 
 
 
 
Honor Code: This work is to be completed individually.  Collaboration is not allowed. 
Potential violations will be reported to the honor council. By submitting, you confirm                         
that you have neither given nor received unauthorized help on this assignment. 
Problem 1: Sorting methods (5 points)
The following problem shows snapshots of an array of integers in the process of being sorted. 
The first snapshot is the starting array.  The second and third snapshots show the array after 
one and two iterations of the algorithm, respectively.  Label each sequence of snapshots with the 
appropriate sorting method from the table below. 
 
a. SELECTION SORT  b. QUICK SORT  c. BUBBLE SORT  d. MERGE SORT  e. INSERTION SORT 
 
 
1.1 [16, 0, 7, 5, 19, 17, 23, 2, 10, 0, 5, 13, 0, 5, 16] 
[0, 16, 7, 5, 19, 17, 23, 2, 10, 0, 5, 13, 0, 5, 16] 
[0, 7, 16, 5, 19, 17, 23, 2, 10, 0, 5, 13, 0, 5, 16] 
[0, 5, 7, 16, 19, 17, 23, 2, 10, 0, 5, 13, 0, 5, 16] 
 
 
1.2 [16, 0, 7, 5, 19, 17, 23, 2, 10, 0, 5, 13, 0, 5, 16] 
[5, 0, 7, 5, 5, 0, 13, 2, 10, 0, 16, 23, 17, 19, 16] 
[2, 0, 0, 5, 5, 0, 5, 13, 10, 7, 16, 23, 17, 19, 16] 
[0, 0, 0, 2, 5, 5, 5, 13, 10, 7, 16, 23, 17, 19, 16] 
 
 
1.3 [16, 0, 7, 5, 19, 17, 23, 2, 10, 0, 5, 13, 0, 5, 16] 
[16, 0, 7, 5, 19, 17, 23, 2, 10, 0, 5, 0, 13, 5, 16]  
[0, 7, 16, 5, 17, 19, 23, 0, 2, 5, 10, 0, 5, 13, 16] 
[0, 5, 7, 16, 17, 19, 23, 0, 0, 2, 5, 5, 10, 13, 16] 
 
 
1.4 [16, 0, 7, 5, 19, 17, 23, 2, 10, 0, 5, 13, 0, 5, 16] 
[0, 7, 5, 16, 17, 19, 2, 10, 0, 5, 13, 0, 5, 16, 23] 
[0, 5, 7, 16, 17, 2, 10, 0, 5, 13, 0, 5, 16, 19, 23] 
[0, 5, 7, 16, 2, 10, 0, 5, 13, 0, 5, 16, 17, 19, 23] 
 
 
1.5 [16, 0, 7, 5, 19, 17, 23, 2, 10, 0, 5, 13, 0, 5, 16] 
[16, 0, 7, 5, 19, 17, 16, 2, 10, 0, 5, 13, 0, 5, 23] 
[16, 0, 7, 5, 5, 17, 16, 2, 10, 0, 5, 13, 0, 19, 23] 
[16, 0, 7, 5, 5, 0, 16, 2, 10, 0, 5, 13, 17, 19, 23] 
 
 
Problem 2: AVL Tree Operations (5 points) 
Answer the following fill in the blank and multiple choice questions on CTools Test Center given 
the AVL tree below. 
 
The value 4 is inserted into the tree, but no rotations are performed to rebalance the tree.   
 
1 Which node is the deepest unbalanced node?  Give the value the node contains.  
2 What is the balance of this node?   
3 What sequence of rotations must be performed to rebalance the tree?   
 
The value 13 is deleted from the original tree, but no rotations are performed to rebalance the 
tree. 
 
4 What sequence of rotations must be performed to rebalance the tree?   
5 After all rotation(s) necessary to rebalance the tree are performed, which node is the 
parent of the node containing 17?   
 
Problem 3: Methods of Tree Traversal (5 points) 
 
Answer the following fill in the blank questions on CTools Test Center given the AVL tree below.  
 
Perform all rotations necessary to rebalance the tree before calculating a traversal.  
 
IMPORTANT: Write each result of the traversals as a sequence of numbers corresponding to 
the tree’s elements, separated by a dash (‘­‘). For example, if we asked for an in­order traversal 
of the original tree, the answer would be the following:   0­1­4­8­31­63­67­68­79­80 
1. IN­ORDER: after deleting ‘4’   
 
Using the original tree: 
2. POST­ORDER: after deleting ‘67’ and inserting ‘62’ 
 
Using the original tree: 
3. PRE­ORDER: after deleting ‘4’ and ‘1’   
 
Using the original tree: 
4. PRE­ORDER: after deleting ‘80’ and ‘67’, and inserting ‘67’ 
Without resetting the tree:  
5. LEVEL­ORDER: after deleting  ‘8’, ‘63’ and ‘31’   
 
 
 
Problem 4: Hash Tables (5 points): 
Answer the following TRUE/FALSE questions on the Test Center in CTools. 
 
 
 
 
1. For a given hash table size and number of elements, a hash table with more collisions will 
have a greater load factor. 
 
 
 
 
2. The worst case time complexity of a lookup for a hash table employing linear probing is worse 
than the worst case time complexity of a lookup for a hash table using separate chaining. 
 
 
 
 
3. The best case time complexity for a lookup in a full hash table using linear probing is worse 
than the best case time complexity for a lookup in a full hash table using separate chaining. 
 
 
 
 
4. When a hash table using separate chaining is resized, only the first element in each chain 
needs to be rehashed to determine where in the new hash table the chain should be. 
 
 
 
 
5. The worst case time complexity of a lookup in a hash table employing linear probing and 
containing only 1 element is constant time (i.e. the lookup time is independent of the capacity of 
the hash table). 
 
 
 
 
 
 
 
 
 
Problem 5: Conflict Resolution Schemes (5 points) 
Steve is assigned the task of implementing a hash table to store information about the EECS 
281 staff’s favorite sorting methods. He decides to use the following hashing scheme: 
● Hash table size (M) is limited to Mersenne Primes (begins with M = 7) 
● Hash function as listed by the following pseudocode: 
hash(key, SIZE): 
      x := 0 
      for character in key: 
            x += ascii_value(character) 
      return x % SIZE 
 
He then populates his new data structure by inserting (in this order) the following keys:  
paoletti   deorio   kevin   steve   matt   james 
 
Finally, he adds information about each individual, resulting in the following dataset: 
 
Index  Key  Value 
0  steve  Sleepsort 
1     
2  kevin  Bogosort 
3  james  Timsort 
4  matt  Flashsort 
5  paoletti  Introsort 
6  deorio  Chickensort 
 
Which of the following methods of conflict resolution could have produced these results? 
 
a. Linear Probing  b. Quadratic Probing  c. Separate Chaining  d. Double Hashing* 
e. A and B  f. B and C  g. A and C  i. A, B, and C 
j. A, B, and D  k. B, C, and D  l. A, B, C, D  m. None of the above 
 
* Compute your result for Double Hashing using the following algorithm: 
h’(key) = (h(key) + j * Pn­1 * (h(key) ­ Pn­1)) % M 
where j = 1,2,3…, and Pn is the current Mersenne prime. 
A list of known Mersenne primes is available at 
http://mersennewiki.org/index.php/List_of_known_Mersenne_primes 

Homework3