Docsity

CS61B Spring 2003 Exam 3: Problem Set, Exams of Data Structures and Algorithms

Toggle sidebar
bg1
CS61B (Yelick) Spring 2003
Version 1
Exam 3
April 21, 2003
Do not open this booklet until you are told to begin!
There are 20 points on this exam. Read each problem carefully, and avoid spending too much
time on any one question.
Problem 0 (1 point, 2 minutes): Identification
Fill out your name, your neighbors’ names, and other information in this grid. You may do this
before you are told to begin.
Your name: Your cs61b login:
Person to your left: Lab time:
Person to your right: Lab TA’s name:
Do not open this booklet until you are told to begin!
Grading: Do not write below this line. The following grid will be used for grading.
Problem
0 1 2 3 4 5 6 7 8 Total
Possible 1 2 2 3 1.5 3 1.5 3 3 20
Score
pf3
pf4
pf5

Partial preview of the text

Download CS61B Spring 2003 Exam 3: Problem Set and more Exams Data Structures and Algorithms in PDF only on Docsity!

CS61B (Yelick) Spring 2003

Version 1

Exam 3

April 21, 2003

Do not open this booklet until you are told to begin!

There are 20 points on this exam. Read each problem carefully, and avoid spending too much time on any one question.

Problem 0 (1 point, 2 minutes): Identification

Fill out your name, your neighbors’ names, and other information in this grid. You may do this before you are told to begin.

Your name: Your cs61b login: Person to your left: Lab time: Person to your right: Lab TA’s name:

Do not open this booklet until you are told to begin!

Grading: Do not write below this line. The following grid will be used for grading.

Problem 0 1 2 3 4 5 6 7 8 Total Possible 1 2 2 3 1.5 3 1.5 3 3 20 Score

Problem 1: (2 points, 4 minutes) Heaps

Suppose that there are N distinct values in a binary max heap (the maximum is at the top). In an array representation, which positions could be occupied by the 4th^ largest element? List all that apply. Assume the heap index starts at 0.

  1. 0
  2. 1 or 2
  3. 3,4,5, or 6
  4. 7 through 14
  5. 15 or higher

Answer: __________

Problem 2: (2 points, 4 minutes) BSTs

Consider the BST created by inserting the following characters in the given order into an initially empty BST, where the ordering operation is alphabetical: A E F G B D C

For which of the following insert orders will the same BST be created? List all that produce the same BST.

  1. C A B E G D F
  2. A F E G D B C
  3. A E B G C D F
  4. A E G C F D B
  5. E A G B D F C

Answer: __________

Problem 3: (3 points, 8 minutes) 2-3-4 Trees

Part A. Given a 2-3-4 tree (called a (2,4) tree in the book) in which all external/sentinel nodes are at depth 3, what is smallest number of keys the tree may have? (Not counting external nodes, this tree has height 2.)

Answer: __________

Part B. Assume your tree from Part A contains even keys 2-2*N, where N is your answer to Part A. What sequence of 2-3-4 operations, as they are defined in the book and lecture notes, will produce your tree from part A? Your answer should have as few operations as possible.

Answer:

Problem 7: (3 points, 10 minutes) Dijkstra’s Algorithm

Run Dijkstra’s Algorithm on the following graph to compute the shortest path from 0 to 7. At each step show the contents of the distance vector (D in the book and d in the lecture notes) after each vertex is visited. Give the resulting path by listing the edges.

visited vertex

D[0] D[1] D[2] D[3] D[4] D[5] D[6] D[7]

Problem 8: (3 points, 10 minutes) Prim-Jarnik Algorithm

Run the Prim-Jarnik Algorithm on the following graph starting from the vertex 0. Show the vector of best-weights-so-far, which is called the D in the book and d in the lecture notes, after each vertex is visited. At each step indicate which vertex is being visited. Also show the final tree by listing the edges in the tree.

visited vertex

D[0] D[1] D[2] D[3] D[4] D[5] D[6] D[7]