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

Worksheet for Quiz 3 - Object Oriented Programming I | CMSC 132, Quizzes of Computer Science

Material Type: Quiz; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG II; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Quizzes

Pre 2010

Uploaded on 02/13/2009

koofers-user-0fu
koofers-user-0fu 🇺🇸

10 documents

Partial preview of the text

Download Worksheet for Quiz 3 - Object Oriented Programming I | CMSC 132 and more Quizzes Computer Science in PDF only on Docsity!

CMSC 132 Quiz 3 Worksheet

The third quiz for the course will be on Friday, July 13. The following list provides more information about the quiz:

  • The quiz will be a written quiz (no computer).
  • Closed book, closed notes quiz.
  • Answers must be neat and legible. We recommend that you use pencil and eraser.

The following exercises cover the material to be included in this quiz. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with the TA or instructor during office hours.

Using the following graph for the questions that follow.

1. DFS/BFS

For each of the following exercises, specify the order nodes are visited when performing the appropriate traversal. Pick nodes to visit using alphabetical order (when multiple choices are possible).

a. Apply DFS with A as the start node. b. Apply DFS with C as the start node (assuming edges are undirected). c. Apply BFS with D as the start node. d. Apply BFS with F as the start node (assuming edges are undirected).

2. Single Source Shortest Path

For each of the following exercises, assume that all edges are undirected. Apply Dijkstra’s algorithm. Indicate the cost (for lowest weight path) and predecessor for each node in the graph after completing the algorithm. Also list the order nodes are added to the set of processed nodes.

B

C D A F E 2

For instance, applying Djikstra’s algorithm with C as the start node yields (after C is processed):

Node A B C D E F Cost ∞ 1 0 25 ∞ 8 Predecessor none C none C none C Order added 1

And after all nodes are processed:

Node A B C D E F Cost 10 1 0 5 7 8 Predecessor E C none B D C Order added 6 2 1 3 4 5

The shortest path to A from C is thus C→B→D→E→A, with a cost of 10.

a. Apply Dijkstra’s algorithm with A as the start node. List shortest path to F. b. Apply Dijkstra’s algorithm with B as the start node. List shortest path to F. c. Apply Dijkstra’s algorithm with E as the start node. List shortest path to C.

3. Minimum Spanning Tree

For each of the following exercises, assume that all edges in the graph above are undirected. Find the edges in a minimum spanning tree. List the edges in the order they are added to the MST.

a. Apply Prim’s algorithm (to the graph above) with A as the starting node. b. Apply Prim’s algorithm (to the graph above) with F as the starting node. c. Apply Kruskal’s algorithm (to the graph above).

d. Recalculate all 3 answers using the following graph below instead.

B

C D A E F 2