Chris Pollett > Old Classes > CS146 ( Print View ) Grades: |Sec6|Sec8| Course Info:
|
HW#3 --- last modified January 16 2019 00:35:12..A solution set is posted here. Due date: Oct. 17 ========= Files to be submitted: cs146sec6hw3file1.java(sec 8 if that's your section) ====================== The following problems from the book are due start of class Oct. 17: 4.19, 4.27, 4.28, 4.43, 5.19. Purpose: To gain experience with BSTs, AVL trees, B-trees, and extendible ======== hashing. Specification: ============== cs146sec6hw3file1 is an application which you will use to graphically see that AVL trees stay balanced as you perform insertions. It is run from the command line with a line like java cs146sec6hw3file1 300 200 15 200 It would then create a 300x200 pixel JFrame, and an empty AVL tree called theTree. The application then generates 15 random numbers less than 200 (use Math.random()). (Of course, if we change the command line number 300 or 200 then the frame size would be different and if we change 15 or 200 then the number of random numbers we generate or their range changes.) After generating a number the application inserts this number into theTree. Once all these inserts are done, the application draws the tree in the JFrame. Comments ======== (1) You should draw the int's stored in the nodes in you draw (use g.drawString(string,x,y); ). (2) Feel free to use the code from the book for AVL trees. (3) To insert int's into the tree use the Integer wrapper class. This implements the Comparable interface. (4) As a hint on how to draw the tree you should try to use a postorder traversal. After drawing all the subtrees for the children of the root draw an edge between between each of these subtrees and the root then draw the root node. You might want your postorder drawing method to have as a parameter the coordinates for a rectangle on which the tree is supposed to draw itself. Point Breakdown =============== 4.19..................................1pt 4.27..................................1pt 4.28..................................1pt 4.43..................................1pt 5.19..................................1pt Department coding guidelines followed.1pt Random int's are inserted into AVL tree as described above.............1pt Tree is correctly draw in frame.......1pt Total.................................8pts A solution set is posted here. |