Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Integer Keys - Data Structures - Exams, Exams of Data Structures and Algorithms

Main points of this exam paper are: Integer Keys, Array Representation, Complete Binary, Binary Tree, Each Node, Complete K-Ary, Ary Trees, Storing Complete, Probe Function, Table Implementation

Typology: Exams

2012/2013

Uploaded on 04/02/2013

shashidhar_p43
shashidhar_p43 🇮🇳

4.5

(53)

80 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS61B Midterm 2 Fall 1997
1) (2 points) Given the following BST, show its value after deleting 95.
2) (2 points) Given a BST, there are some keys that, if inserted will increase the height of the tree. For the
BST below, list all the integer keys (distinct from those already in the tree) for which this is true. If no such
keys exist, explain why not. (Each key should increase the height if inserted alone, not with other keys.)
3) (4 points) For a given set of keys there are many possible BSTs. Right and left rotations (as defined for
Red-Black trees), produce legal BSTs from others. For the BST given below, give another BST with the same
keys that CANNOT be formed by performing a sequence of left and right rotations on T. If no such tree
exists, explain why not.
CS61B Midterm 2 Fall 1997
1
pf3
pf4
pf5

Partial preview of the text

Download Integer Keys - Data Structures - Exams and more Exams Data Structures and Algorithms in PDF only on Docsity!

CS61B Midterm 2 Fall 1997

  1. (2 points) Given the following BST, show its value after deleting 95.

  2. (2 points) Given a BST, there are some keys that, if inserted will increase the height of the tree. For the BST below, list all the integer keys (distinct from those already in the tree) for which this is true. If no such keys exist, explain why not. (Each key should increase the height if inserted alone, not with other keys.)

  3. (4 points) For a given set of keys there are many possible BSTs. Right and left rotations (as defined for Red-Black trees), produce legal BSTs from others. For the BST given below, give another BST with the same keys that CANNOT be formed by performing a sequence of left and right rotations on T. If no such tree exists, explain why not.

  1. (2 points) Given the following Red-Black tree, show its value after inserting the key 29. (Mark the red nodes with an "R" and black nodes with "B" and show the black nulls at the leaves as in your homework assignment.

  2. (2 points) Show the value of the following heap after performing one remove() operation.

Fill in answer above (leaving unused elements blank).

  1. (4 points) In class we discussed the array representation of a complete binary tree. This same idea can be used for storing complete k-ary trees in which each node has at most k children, rather than 2 children. Assume the first element of the array is left blank, as in class.

a) Give a formula for finding the jth child of node i in such a tree.

lookupByKey2(String) -- takes only a String key to lookup by k

deleteByKey1(int) -- delete by k

deleteByKey2(String) -- which takes a String key.

All of these operations should work in O(1) time. Give a 1 sentence description of your data structure and draw a picture of it. Your picture should contain at least one stored object with fields k1 and k2.

  1. (6 points) Fill in the function below to perform a right rotation on the left child of a tree node p. You may assume that p, its left child, and its left child's children are all non-null.

class TreeNode { left TreeNode; right TreeNode; Object data }

void rotateRightOnLeftChild (TreeNode p) {

  1. (3 points) The performance of quickSort depends on the order of elements in the input array. Give an input array containing the integers 0 through 8 that will make quickSort perform at its worst, i.e., will maximize the number of comparisons requred by quickSort. (Assume the pivot is chosen as the middle element as in the book and notes.)