Sie sind auf Seite 1von 3

Assignment 2: Given on 26/8/2014.

Please submit by 9
th
Sept 2014, 3pm.



A. Check the ADT or data structure that is most appropriate for each of the following problems:


1. You want to build a meeting reminder for a PDA that keeps track of events your schedule and
periodically checks the next event to sound an alarm to remind you of the next thing you need
to do.
o List
o Stack
o Queue
o Priority Queue

2. You want to build a table of contents for a textbook. The textbook consists of chapters, chapters
consist of sections, and sections consist of subsections.
o List
o Tree
o Binary Tree
o Stack


B. List the sequence of nodes visited by preorder, inorder and postorder traversals of the following
tree:
A

B
C
D
E
F
G
H
I J





o Pre-order Traversal : ABDGEHICFJ
o In-order Traversal : GDBHEIACJF
o Post-order Traversal : GDHIEBJFCA

C. Consider the following undirected, weighted graph:




Step through Dijkstras algorithm to calculate the single-source shortest paths from A to every
other vertex. Show your steps in the table. Cross out old values and write in new ones, from left
to right within each cell, as the algorithm proceeds. Finally, indicate the lowest-cost path from
node A to node F.

o Using Dijkstras algorithm
o Known vertices (in order marked known): A B C G E D or F D or F
Vertex Known Cost Path
A Y 0
B Y 1 A
C Y 3 2 A B
D Y 8 7 B E
E Y 6 5 B C
F Y 107 A E
G Y 3 B

o Lowest-cost path from A to F: A to B to C to E to F







D. Consider the following directed, weighted graph:
Using the appropriate algorithm, find the shortest path from A to every other vertex. Show your
steps in a table.





o Using Fords Algorithms
o Known vertices (in order marked known):A B D F C G E
Vertex Known Cost Path
A Y 0
B Y 2 A
C Y 7 A
D Y 4 B
E Y 12 9 AC
F Y 6 D
G Y 8 F





End of Questions

Das könnte Ihnen auch gefallen