CS140 Homework 12

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

  2. 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
    
  3. Behold the following tree that violates the AVL condition:
                               ---100--
    			  /        \
    		       -50-        200
    		      /    \          \
    		    25     75        300
    		          /  \
    		         62  85
                              \ 
    			   70
    

  4. Using the binary search tree library from lab 8, write a function that reads integers from an inputstruct and inserts them into one of your 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
    	
  5. Show the result of inserting 2, 1, 4, 5, 9, 3, 6, 7 into an initially empty AVL tree. You can check your results by using the Java applet on the lecture notes web-page. For each insertion indicate:

  6. 4.28 in Weiss--this exercise will give you more practice with writing recursive functions. I would use the following struct for this problem:
    struct TreeNode {
      struct TreeNode *left;
      struct TreeNode *right;
    };
    
    The value field is irrelevant for this problem.