CS140 Homework 12

  1. Suppose I want to create a searching application which supports the following three operations:

    Further suppose that:

    Which data structure would you choose to implement this search application? Justify your answer and be specific about which type of binary tree (balanced versus unbalanced), hash table (separate chaining versus open addressing), or linked list (singly-linked versus doubly-linked) you would use.

  2. Show the hash table that results if the integers 22, 28, 17, 21, 32 are inserted into the following hash table using:

               -----------------------
          0    |                     |
    	   |                     |
               -----------------------
          1	   |                     |
    	   |                     |
               -----------------------
          2    |                     |
    	   |                     |
               -----------------------
          3	   |                     |
    	   |                     |
               -----------------------
          4	   |                     |
    	   |                     |
               -----------------------
          5	   |                     |
    	   |                     |
               -----------------------
          6	   |                     |
    	   |                     |
               -----------------------
          7	   |                     |
    	   |                     |
               -----------------------
          8	   |                     |
    	   |                     |
               -----------------------
          9	   |                     |
    	   |                     |
               -----------------------
         10	   |                     |
    	   |                     |
               -----------------------
    

  3. Show the hash table that results if the integers 22, 28, 17, 21, 32 are inserted into the following hash table using:

    You should append integers to the end of your lists.
               -----------------------
          0    |                     |
    	   |                     |
               -----------------------
          1	   |                     |
    	   |                     |
               -----------------------
          2    |                     |
    	   |                     |
               -----------------------
          3	   |                     |
    	   |                     |
               -----------------------
          4	   |                     |
    	   |                     |
               -----------------------
          5	   |                     |
    	   |                     |
               -----------------------
          6	   |                     |
    	   |                     |
               -----------------------
          7	   |                     |
    	   |                     |
               -----------------------
          8	   |                     |
    	   |                     |
               -----------------------
          9	   |                     |
    	   |                     |
               -----------------------
         10	   |                     |
    	   |                     |
               -----------------------
    

  4. Show the binary search tree that results if the integers 22, 28, 17, 21, 32 are inserted into an initially empty tree.

  5. Show the result of doing a single left rotation about the node 30. Do not worry if the rotation increases the height of the tree. All I care about is whether you know how to perform a rotation.
                              20
    			/    \
    		      10     30
    		       \    /  \
    		       15  25  35
    
  6. Behold the following tree that violates the AVL condition:
                               ---100--
    			  /        \
    		       -50-        200
    		      /    \          \
    		    25     75        300
    		          /  \
    		         62  85
                                /
    			   80
    

  7. Pretend that Dr. Plank's bstree library has been rewritten so that keys can be integers rather than char *'s. Everything else remains the same (i.e., function names, parameters, parameter types, etc). Write a function that reads integers from an inputstruct and inserts them into one of Dr. Plank's bstree's. For each integer store the line number associated with the integer. Do not worry about duplicate integers. Once all the integers have been read, print them in descending order, along with their line numbers. Do not worry about compiling or executing this function or about potential errors. Here is the function signature. You may assume that the inputstruct has already been created:
    	void sort_integers(IS input_file);
    	
    If your input file is:
    	23 18 17
    	16 
    	22 58
    	
    then your output would look like:
    	58	3
    	23	1
    	22	3
    	18	1
    	17	1
    	16	2