View
217
Download
0
Category
Preview:
Citation preview
Exam #1 Analysis of Algorithms Page 1Open Book June 13, 1995
NAME:_________________________________________________(10 Points)
1. For the following program, what is the order of the running time? For an input valueof N, what value does func1 return? (10 Points)
int func1(int N){
int A,I,J;
A=0;for (I=0 ; I<N ; I++){
for (J=I ; J>=0 ; J--){
A++;}
}return A;
}
Exam #1 Analysis of Algorithms Page 2Open Book June 13, 1995
2. For the following program, what is the order of the running time? For an input valueof N, what value does func2 return? (10 Points)
int func2(int N){
int A,I,J;
A=0;for (I=0 ; I<N/2 ; I++){
A++;}for (J=I ; J<N ; J++){
A++;}return A;
}
Exam #1 Analysis of Algorithms Page 3Open Book June 13, 1995
3. For the following program, what is the order of the running time? For an input valueof N, what value does func3 return? (10 Points)
int func3(int N){
int A;
if (N<=0){
return 0;}else{
A = func3(N-1);A += N;return A;
}}
Exam #1 Analysis of Algorithms Page 4Open Book June 13, 1995
4. What is the worst case order of each of the following sortingalgorithms? (20 Points)
Insertion Sort______________________
Bubble Sort _______________________
Selection Sort _____________________
Merge Sort________________________
Quick Sort ________________________
Heap Sort_________________________
Radix Sort_________________________
5. How many comparisons does Insertion Sort do to sort the followinglist? (10 Points)
1, 3, 5, 7, 0, 2, 4, 6
6. How many comparisons does Selection Sort do to sort the following list? (10 Points)
1, 3, 5, 7, 0, 2, 4, 6
Exam #1 Analysis of Algorithms Page 5Open Book June 13, 1995
7. How many times must Heapify (DownHeap) be called to convert the following listinto a heap? Show the array after it is converted to a heap. (10 Points)
1, 2, 3, 4, 5, 6, 7, 8
8. Show the lists and the merging process (as I did in class), for MergeSort on thefollowing list. (10 Points)
6, 3, 8, 5, 2, 1, 4, 7
Exam #2 Analysis of Algorithms Page 1Open Book July 20, 1995
NAME:__________________________________________________________
1. What important historical event occured on this date in 1969? (10 points.)
2. For the following program, what is the order of the running time? For an input valueof N, what value does func1 return? (10 Points)
int func1(int N){
int A,I,J,K;
A=0;for (I=0 ; I<N ; I++){
for (J=0 ; J<N ; J++){
for (K=0 ; K<J ; K++){
A++;}
}}return A;
}
Sorry, son. I said “No Extra Books!”
Exam #2 Analysis of Algorithms Page 2Open Book July 20, 1995
3. For each of the following Algorithms, write the name of the algorithm on the line thatcorresponds to its worst-case running time. Insertion Sort, Bubble Sort, SelectionSort, Merge Sort, Quicksort, Heap Sort, Radix sort.(10 Points)
O(lg n) _______________________________________________________
O(n) _________________________________________________________
O(n lg n) _____________________________________________________
O(n2)_________________________________________________________
O(n3) ________________________________________________________
4. Suppose you have a hash table with 10 entries, each of which is the head of a linkedlist. Suppose you add 100 keys to this table. In the worst case how manycomparisons will it take to determine that a key is NOT in the table? Answer thequestion assuming both a maximum and a minimum number of collisions.(10 Points)
In hashing, as in life,the fewer the collisions, the better.
Exam #2 Analysis of Algorithms Page 3Open Book July 20, 1995
5. The following is a red-black tree. The fat edges represent RED edges, the thin edgesrepresent BLACK edges. The numbers in the vertices are the keys. Show how thistree will look after adding the key 14. (10 Points)
20
10
15
12 17
8
40
Yet another use for trees.
Exam #2 Analysis of Algorithms Page 4Open Book July 20, 1995
6. Find the shortest path from A to B. Which vertices are in the tree when the algorithmterminates? (10 Points)
A
B
x1
x2
x3
x4
x5
x6
x7
x8
x9
x10
x11
x12
x13x14
x15
x16
x17
x18
x19
x20
x21
x22
x23
x24
x25
1
1
1
1
11
1
1
1
11
1
13
14
20
22
1010
1 1
1
1
11
10
1010
10
1010
10
10
10
10
10
10
10
10
10
1010
10
10
10
While it may be necessary to explore thewrong path, it’s important not to stray
too far in the wrong direction
Exam #2 Analysis of Algorithms Page 5Open Book July 20, 1995
7. Find the minimum spanning tree of the following graph. Circle the weights that belongto the minimum spanning tree in the following graph. (10 Points)
1
2
3
45
6
7
8
9
10
12
13
1415
1617
1819
2011
21
22
23
24
25
8. Find biconnected components of the following graph. (10 Points)
A
B
C
D
E
F
G
H
J
K
BiDirectional Connections
Exam #2 Analysis of Algorithms Page 6Open Book July 20, 1995
9. Find the strongly connected components of the following graph. (10 Points)
A B
C
D
E
F
G
H
JK L
M
N
P
10. What does it mean to say that a problem, such as Satisfiability, is NP-Complete? (10Points)
Miller Time
Analysis of Algorithms Test #1 Oct 3, 1995
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (10 Points)
Prog1(N:Integer)begin
I := 0;While (I<N)
Print “Hello World”;I := I + 1;
EndWhileend
2. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (10 Points)
Prog1(N:Integer)Begin
For I := 1 to N doFor J := 1 to I do
Print “Hello World”;EndFor
EndForEnd
Analysis of Algorithms Test #1 Oct 3, 1995
100 Points Open Book, Open Notes Full Period
Page 2
3. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (Remember the summations that appear inChapter 1.) (10 Points)
Prog1(N:Integer)Begin
For I := 1 to N doFor J := 1 to I do
For K := 1 to I doPrint “Hello World”;
EndForEndFor
EndForEnd
4. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (10 Points)
Prog1(N:Integer)Begin
if N > 0 ThenFor I := 1 to N do
Print “Hello World”;EndForProg1(N/2);Prog1(N/2);
EndIfEnd
Analysis of Algorithms Test #1 Oct 3, 1995
100 Points Open Book, Open Notes Full Period
Page 3
5. Place the following functions in ascending order by growth rate. If two functions havethe same growth rate, say so. (20 Points)
1. n2
2. log10 n
3. 2n
4. n
5. n3
6. nn
7. ln n
8. 2n + n5
9. n3 + 2n2 + n + 1
10. 3n
11. lg n
12. 5n
6. Professor Gooms of the University of Florida has invented a new algorithm forsearchng an ordered list. The algorithm has no loops in it. There is somethingsuspicious about this. What is it? (10 Points)
My growth rate has always exceededlg n!
Analysis of Algorithms Test #1 Oct 3, 1995
100 Points Open Book, Open Notes Full Period
Page 4
7. In Quicksort, all comparisons are done in the Split algorithm. If you make the splitalgorithm twice as fast, what happens to the order of the algorithm? What happens tothe actual running time? (10 Points)
8. Fill in the following table. (20 Points.)
Algorithm Worst Case Order Average Case Order Extra Space Required
InsertionSort
QuickSort
MergeSort
HeapSort
(Well, Almost Nothing!)
There’s nothing more repulsive than an Ugly Test!
Analysis of Algorithms Test #1 Nov 7, 1995
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. Find the biconnected components in the following graph. (20 points.)
1
2
3
4
5
6 7
8
9
10
11
12
13
(You may not need to use all lines.)
Component Number Vertices
1
2
3
4
5
6
7
8
9
Analysis of Algorithms Test #1 Nov 7, 1995
100 Points Open Book, Open Notes Full Period
Page 2
2. Find the strongly connected components of the following graph. (20 points)
1
2
3
4
5
6
7 8
9 10
11
12
13
14
15
16
17
18
(You may not need to use all lines.)
Component Number Vertices
1
2
3
4
5
6
7
8
9
10
Analysis of Algorithms Test #1 Nov 7, 1995
100 Points Open Book, Open Notes Full Period
Page 3
11
3. Find the minimum spanning tree for the following graph. Indicate which edges arepart of the minimum spanning tree. (10 points)
x1
x2
x3
x4
x5
x6
x7x8
x9
x10
x11
x12
x13 x14
x15
x16
x17 x18
x19
x20
x21
1 2
3
4
5
6
7
8
9
10
11
12
13
14
1516
17
1819
20
21
22 23
24
25
2627 28
29
3031
32
4. In the following graph, find the shortest path from A to B. Indicate which edges arepart of the shortest path. (10 points)
x2
x3
x4
x5
x6
x7
x8
x9
x10
x11
x12
x13
x14
x15
x16
x17
x18 x19
x20
x21
x22
x23
x24
x25
x26
x27 x28
x29
x30
A
B
1
2
1
2
3
12
3
1
2
2
3
1
1 1
1
22
3
12
1
14 18
8
1214
3 7
10
12
2410
10
15
7
22 1
1
11
1
1
32
27
4522 26
31
34
OK, what happened to all the bugs?
Analysis of Algorithms Test #1 Nov 7, 1995
100 Points Open Book, Open Notes Full Period
Page 4
5. Suppose the MST algorithm has been run on the following graph, starting with vertexx1. Suppose that vertex x5 has just been added to the graph. At this point, whichvertices are in the tree, which vertices are Fringe vertices, and which vertices areunseen? (10 points)
x1
x2
x3
x4
x5x6
x7
x8 x9 x10
x11
x121
2
34
5
6
7
8
9
1011
12
13
14
15
16
17
1819
Vertex Tree/Fringe/Unseen
x1
x2
x3
x4
x5
x6
x7
x8
x9
x10
x11
Yeah! What happened to all the bugs?
Analysis of Algorithms Test #1 Nov 7, 1995
100 Points Open Book, Open Notes Full Period
Page 5
x12
6. Suppose the Shortest Path algorithm is being used to find the shortest path from A toB. Suppose that vertex x5 has just been added to the tree. At this point, whichvertices are Tree vertices, which vertices are Fringe vertices, and which vertices areUnseen? For the Tree vertices and the Fringe vertices, what is the current distancefrom vertex A when x5 is added to the tree? (10 points)
x2
x3x4
x5
x6x7 x8
x9
x10 x11
AB
11
1
1
1
10
10
10
10
10
1010
10
10
10
10
1010
1010
You ate them all yourself, didn’t you.?
Analysis of Algorithms Test #1 Nov 7, 1995
100 Points Open Book, Open Notes Full Period
Page 6
Vertex Tree/Fringe/Unseen Distance
A
x2
x3
x4
x5
x6
x7
x8
x9
x10
x11
B
7. For the following graph, list the vertices in the order they would be visited during adepth-first-search, and during a breadth-first-search. Start with vertex x1. (20 points)
x1
x2
x3 x4
x5
x6
x7
x8
x9
x12
x11
x10
Analysis of Algorithms Test #1 Nov 7, 1995
100 Points Open Book, Open Notes Full Period
Page 7
Order Depth FirstSearch
Breadth First Search
1st
2nd
3rd
4th
5th
6th
7th
8th
9th
10th
11th
12th
And now for something
completely different!
Analysis of Algorithms Test #3 Dec 7, 1995
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. What is the order of the following algorithm? How many times does the followingalgorithm print the word “Hello”? Express both results as a function of N. (15points.)
MyAlg(long N){
for (I=0 ; I<N ; I++){
for (J=0 ; J<N ; J++){
for (K=0 ; K<N ; K++){
for (L=0 ; L<K ; L++){
Print "Hello!";}
}}
}}
Analysis of Algorithms Test #3 Dec 7, 1995
100 Points Open Book, Open Notes Full Period
Page 2
2. Suppose someone figured out that it was possible to compute the value of a 2x2matrix using only 4 multiplications and 10 additions. Suppose that it was notnecessary to use the commutative law anywhere in this method. How fast wouldStrassen’s Matrix Multiply be if you used this method. (Use recurrence relations tojustify your answer.) (15 Points)
Analysis of Algorithms Test #3 Dec 7, 1995
100 Points Open Book, Open Notes Full Period
Page 3
3. The following 16 numbers are being used to compute a 16 point discrete FFT (as inthe book.) First 8 2-point FFT’s are computed, then 4 4 point FFTs then 2 8 pointFFTs and finally 1 16 point FFT, as in the diagram below. Write the numbers in thecorrect order for computing the 2-point FFTs. (15 Points)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
OriginalNumbers
Write thenew numbershere.
Analysis of Algorithms Test #3 Dec 7, 1995
100 Points Open Book, Open Notes Full Period
Page 4
4. What does it mean to say that a problem P is NP-Complete? (20 Points)
5. Give a diagram similar to that on P. 214 for the string ABABBAABA. (10 Points.)
Analysis of Algorithms Test #3 Dec 7, 1995
100 Points Open Book, Open Notes Full Period
Page 5
6. The following is an example of a straight-line program for the polynomial x2+2x+1.temp1 = x*x;temp2 = 2*xFinal = temp1+temp2+1
Create a straight-line program for 3x4+5x3+7x2+4x+2, but make sure that yourprogram is optimal. (10 Points)
Analysis of Algorithms Test #3 Dec 7, 1995
100 Points Open Book, Open Notes Full Period
Page 6
7. Show the following red-black tree after adding the element 45. The fat edges are red,the black edges are skinny. (15 Points)
60
30
35
4033
25
12
82
9677
Analysis of Algorithms Test #1 Oct 2, 1996
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (10 Points)
Prog1(N:Integer)begin
For I := 1 to N+1 DoPrint “Hello World”;
EndForI := 0;While (I<N)
Print “Hello World”;I := I + 1;
EndWhileend
2. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (10 Points)
Prog1(N:Integer)Begin
For I := 1 to N doProg2(I);
EndForEnd
Prog2(N:Integer)Begin
For I := 1 to N doPrint “Hello World”;
EndForEnd
Analysis of Algorithms Test #1 Oct 2, 1996
100 Points Open Book, Open Notes Full Period
Page 2
3. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (Remember the summations that appear inChapter 1.) (10 Points)
Prog1(N:Integer)Begin
For I := 1 to N doFor J := 1 to I do
Print “Hello World”;EndForFor K := N/2 to N do
Print “Hello World”;EndFor
EndForEnd
4. For an input N, how many times does the following program print “Hello World”?(Order is sufficient.) What is the order of the algorithm? (10 Points)
Prog1(N:Integer)
Analysis of Algorithms Test #1 Oct 2, 1996
100 Points Open Book, Open Notes Full Period
Page 3
Beginif N > 0 Then
For I := 1 to N doPrint “Hello World”;
EndForProg1(N/2);
EndIfEnd
Analysis of Algorithms Test #1 Oct 2, 1996
100 Points Open Book, Open Notes Full Period
Page 4
5. Place the following functions in ascending order by growth rate. If two functions havethe same growth rate, say so. (20 Points)
1. n2
2. ln n
3. 2n
4. n/10000
5. n5.1
6. n!
7. ln2 n
8. n5
9. n5lg n
10. (2.1)n
11. lg n
12. n2+2n+1
6. Suppose a list of numbers, is sorted into reverse order. Is this list a heap? Inparticular, is the following list a heap? Justify your answer.(10 Points)
10 9 8 7 6 5 4 3 2 1
Analysis of Algorithms Test #1 Oct 2, 1996
100 Points Open Book, Open Notes Full Period
Page 5
7. Show How Merge Sort will sort the keys in this list. (15 Points)
8 7 6 5 4 3 2 1
8. Show how the Quicksort Split Algorithm will split the following list. Show theposition of the pivot point. (15 Points.)
7 5 14 12 16 2 13 1 6 4 11 10 8 3 15 9
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. Find the biconnected components in the following graph. (20 points.)
1 2
3
45
6
78 9 10
1112
1314
15 1617
1819
20
(You may not need to use all lines.)
Component Number VerticesVertices
11
22
33
44
55
66
77
88
99
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 2
1010
2. Find the strongly connected components of the following graph. (20 points)
1 23 4
56
7 8 9
10 11
1213
1415
16 17
18
19 20(You may not need to use all lines.)
Component Number Vertices
1
2
3
4
5
6
7
8
9
10
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 3
11
3. Find the minimum spanning tree for the following graph. Indicate which edges arepart of the minimum spanning tree. (15 points)
1 2 3
4 5 6 7
8 9 10 11 12
13 14 15 16
17 18 19 20
1
2
345
67
8
9
10
11
12
13
1415
16
17 18
19
20
21
22
23
24 25
26
27
28
29
30 31
32
3334
35
3637
38 3940
41
42
43 4445
Draw the edges of the MST into the following diagram.
1 2 3
4 5 6 7
8 9 10 11 12
13 14 15 16
17 18 19 20
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 4
4. In the following graph, find the shortest path from A to B. Indicate which edges arepart of the shortest path. Fill in the table with minimum distances. (15 points)
AB
12
3
45
6 7 89
10 11 1213
14 1516
17182
7
2
6
12
14
12
15
1 1
1
11
1
2 2 2
2
2
119
18
17
19
252119
28
Distance from A to: Minimum Distance
B
11
12
13
15
1
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 5
5. Show the Binary Search Tree that you get when you add the following integers in thegiven order. (10 points)
10, 9, 30, 55, 12, 17, 15, 31, 22, 81, 6, 1, 5
6. In the following binary search trees, the fat edges represent red edges, while the thinedges represent black edges. This tree is illegal. Show how to fix it. (10 points)
40
51
67
8259
63
65
61
38
12
9 20
47
55
57
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 6
7. For the following graph, list the vertices in the order they would be visited during adepth-first-search, and during a breadth-first-search. Start with vertex 1. (10 points)
12 3
4 56
7 8 910
1112
1314
151617
1819
2021
Order Depth FirstSearch
Breadth First Search
1st2nd3rd4th5th6th7th8th9th10th11th12th13th14th15th16th17th18th19th20th
Analysis of Algorithms Test #3 Dec 13, 1996
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. What is the order of the following algorithm? (15 points.)
MyAlg(long N){
if (N>0){
Print “HELLO”MyAlg(N/2);MyAlg(N/2);
}}
2. Professor Gooms of the University of Florida has invented a new Matrix MultiplyAlgorithm, similar to Strassen’s Matrix Multiply, except that Professor Gooms’salgorithm requires 16 multiplications and 2 additions to multiply a 2x2 matrix. IsProfessor Gooms going to win the Turing Award this year because of this? Why orwhy not, and PLEASE BE SPECIFIC!(15 Points)
Analysis of Algorithms Test #3 Dec 13, 1996
100 Points Open Book, Open Notes Full Period
Page 2
3. The following 16 numbers are being used to compute a 16 point discrete FFT (as inthe book.) First 8 2-point FFT’s are computed, then 4 4 point FFTs then 2 8 pointFFTs and finally 1 16 point FFT, as in the diagram below. Write the numbers in thecorrect order for computing the 2-point FFTs. (15 Points)
Analysis of Algorithms Test #3 Dec 13, 1996
100 Points Open Book, Open Notes Full Period
Page 3
4. What does it mean to say that a problem Q is NP-Complete? (20 Points)
5. Give a diagram similar to that on P. 214 for the string AAAABBAAAABA. (10Points.)
Analysis of Algorithms Test #3 Dec 13, 1996
100 Points Open Book, Open Notes Full Period
Page 4
6. Part 1: The following is an example of a straight-line program for the polynomialwrite an optimal program for computing the value of 5th degree polynomials. Thecoefficients will be supplied in a global array A, which is indexed from 0 through 5.Part 2: While you’re at it, write an optimal program for computing x13, assumingthat x is another global variable. (10 Points)
Analysis of Algorithms Test #3 Dec 13, 1996
100 Points Open Book, Open Notes Full Period
Page 5
7. Show the following red-black tree after adding the element 45. The fat edges are red,the black edges are skinny. (15 Points)
Analysis of Algorithms Test #1 Oct 2, 1997
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (10 Points)
Prog1(N:Integer)begin
If N > 1 ThenFor I := 1 to N do
Print “Hello World”EndforProg1(N/2);
Endifend
2. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (10 Points)
Prog1(N:Integer)Begin
For I := 1 to N doFor J := I to N do
Print “Hello World”;EndFor
EndForEnd
Analysis of Algorithms Test #1 Oct 2, 1997
100 Points Open Book, Open Notes Full Period
Page 2
3. For an input N, how many times does the following program print “Hello World”?What is the order of the algorithm? (10 Points)
Prog1(N:Integer)Begin
For I := 1 to N doFor J := 1 to N do
For K := 1 to N doPrint “Hello World”;
EndForEndFor
EndForEnd
4. Professor Gooms from the University of Florida claims to have invented a new Mergealgorithm that can merge two lists in-place doing only 1 comparsion. If you used thisalgorithm in Merge Sort, what would the order of this new algorithm? ProfessorGooms claims that it would be Θ(lg2 n). Is he correct? Is it likely that his algorithmreally works? (20 Points)
Analysis of Algorithms Test #1 Oct 2, 1997
100 Points Open Book, Open Notes Full Period
Page 3
5. Place the following functions in ascending order by growth rate. If two functions havethe same growth rate, say so. (20 Points)
1. n3
2. lg n
3. 1.00001n
4. n/10000
5. n1024
6. n!
7. lg2 n
8. n3.0001
9. n3lg n
10. nn
11. log30 n
12. n
6. Is the following list a heap? Justify your answer. If it isn’t a heap, show how the heapconstruction portion of the Heapsort algorithm will convert this to a heap. (10 Points)
3 8 4 2 7 9 1 10 5 6
Analysis of Algorithms Test #1 Oct 2, 1997
100 Points Open Book, Open Notes Full Period
Page 4
7. Sort the following binary numbers using radix sort. Show each step. (10 Points)
Are all seven steps necessary? If not, say why not, and skip the extra steps.
Number Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 701010
10101
11111
10100
10111
01011
01111
01100
01101
11101
00011
00101
00001
01110
11110
11100
Analysis of Algorithms Test #1 Oct 2, 1997
100 Points Open Book, Open Notes Full Period
Page 5
8. Show how the Quicksort Split Algorithm will split the following list. Show theposition of the pivot point. (10 Points.)
8 3 13 9 2 7 10 1 14 6 12 4 15 5 11
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. Find the biconnected components in the following graph. (15 points.)
(You may not need to use all lines.)
Component Number VerticesVertices
11
22
33
44
55
66
77
88
99
1010
1 2
3
4 5
6
7
89
1011
12
13
14
15
16
17 19
18
20
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 2
2. Find the strongly connected components of the following graph. (15 points)
(You may not need to use all lines.)
Component Number Vertices
11
22
33
44
55
66
77
88
99
1010
1111
1
2
3
4
5
6
7
8
910
11
12
13
14
15
16
17
18
1920
21
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 3
3. Find the minimum spanning tree for the following graph. Indicate which edges are
part of the minimum spanning tree. (15 points)
Draw the edges of the MST into the following diagram.
1 23
4
56
7 89
1011 12 13
14
15
16 17
1819
20
21
1 23
4
56
7 89
1011 12 13
14
15
16 17
1819
20
21
1
1
2
1
1
11
1
1
1
1
2
2
2
2
2
2
2
2
3
3
3
4
56
7 8
9
4
7
8
9
67
89
6
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 4
4. In the following graph, find the shortest path from A to B. Indicate which edgesare part of the shortest path. Fill in the table with minimum distances. (15 points)
Distance from A to: Minimum Distance
BB
1111
1212
33
66
1616
1
1
1
1
1
1
11
12
2
2
2
2
3
43
3
4 4
4
5
55
6
7
6
7
8
7
9
AB
1
2
3
4
56
789
10
11
12 13 14
15
16
17
18
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 5
5. Assume that you have run the Biconnected Component algorithm on the followinggraph, and have obtained the following start times. Fill in the table by providing theback value for each vertex. (15 points)
Vertex Start Time Back Value
1 1
2 3
3 4
4 9
5 5
6 8
7 13
8 10
9 6
10 2
11 11
12 7
13 12
1
2
3 5
6
4
7
8
910
11
1213
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 6
6. Show the shortest-path TREE that will be computed by Dijkstra’s shortest pathalgorithm for the following graph. All edges have the weight 1. The shortest pathcomputation starts at Vertex A, and ends at Vertex B. (15 points)
A
B
Analysis of Algorithms Test #2 Nov 6, 1995
100 Points Open Book, Open Notes Full Period
Page 7
7. For the following graph, list the vertices in the order they would be visited during adepth-first-search, and during a breadth-first-search. Start with vertex 1. (10 points)
Order Depth FirstSearch
Breadth First Search
1st2nd3rd4th5th6th7th8th9th10th11th12th13th14th15th
1
2
3
4
5
6
7
8
9
10 1112 1314 15
Analysis of Algorithms Test #3 Dec 11, 1997
100 Points Open Book, Open Notes Full Period
Page 1
NAME ______________________________________________________________
1. Show the binary search tree that will be created if the following values are added inthe given order. (15 points.)
5, 4, 2, 1, 3, 9, 7, 6, 10, 13 11, 12, 17, 32, 14
Analysis of Algorithms Test #3 Dec 11, 1997
100 Points Open Book, Open Notes Full Period
Page 2
2. Given the following two matrices, how many multiplications will be done byStrassen's Matrix Multiply to compute the final result? Show the sub-matrices thatwill be used at the first level of recurrsion.(15 Points)
7 9 20 13 122 176 124 149
63 32 11 27 113 191 179 164
22 55 89 37 143 183 132 199
21 28 91 66 121 101 155 133
Number of Multiplies:
Sub Matrices:
Analysis of Algorithms Test #3 Dec 11, 1997
100 Points Open Book, Open Notes Full Period
Page 3
3. What does it mean to say that a problem R is NP-Complete? (20 Points)
4. Write an optimal straight-line program for computing x11. (15 Points.)
Analysis of Algorithms Test #3 Dec 11, 1997
100 Points Open Book, Open Notes Full Period
Page 4
5. Using only addition and multiplication, write an optimal program for computing the
polynomial: Ax5+Bx4+Cx3+Dx2+Ex+F (15 Points)
Recommended