Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
► Not a solution
► An algorithm
► Good solution
Although it requires more complicated data structures, Prim's algorithm for a minimum
spanning tree is better than Kruskal's when the graph has a large number of vertices.
► False
► False
► unknown
graphs?
► Lists require less space than matrices but take longer to find the weight of an edge
(v1,v2)
► Lists require less space than matrices and they are faster to find the weight of
an edge (v1,v2)
► Lists require more space than matrices but are faster to find the weight of an edge
(v1,v2)
If a graph has v vertices and e edges then to obtain a spanning tree we have to delete
► v edges.
► v – e + 5 edges
► v + e edges.
► Non-optimal
► Exponential
► Polynomial
► True
► False
Question No: 10 ( Marks: 1 ) - Please choose one
The greedy part of the Huffman encoding algorithm is to first find two nodes with larger
frequency.
► True
The codeword assigned to characters by the Huffman algorithm have the property that no
► True
Huffman algorithm uses a greedy approach to generate a postfix code T that minimizes
► True
Shortest path problems can be solved efficiently by modeling the road map as a graph.
► False
Dijkestra’s single source shortest path algorithm works if all edges weights are non-
► True
► True
The term “coloring” came form the original application which was in architectural
design.
► False
In the clique cover problem, for two vertices to be in the same group, they must be
► False
► False
The difference between Prim’s algorithm and Dijkstra’s algorithm is that Dijkstra’s
► False
Question No: 21 ( Marks: 1 ) - Please choose one
We do sorting to,
After partitioning array in Quick sort, pivot is placed in a position such that
► Values smaller than pivot are on left and larger than pivot are on right ( page 35)
► Values larger than pivot are on left and smaller than pivot are on right
► False
In counting sort, once we know the ranks, we simply _________ numbers to their final
► Delete
► Mark
► arrange
Question No: 25 ( Marks: 1 ) - Please choose one
problems.
► False
matrix C. There are (p . r) total entries in C and each takes _________ to compute.
► O (1)
► O (n2)
► O (n3)
►Using ASCII standard the string abacdaacac will be encoded with __________ bits.
80 ( page 99)
160
320
100
►Using ASCII standard the string abacdaacac will be encoded with 160 bits.
True
►Using ASCII standard the string abacdaacac will be encoded with 320 bits.
True
True
► Non-optimal
► Exponential
► Polynomial
Huffman algorithm uses a greedy approach to generate a postfix code T that minimizes
► True
1: What is the time complexity to extract a vertex from the priority queue in Prim’s
algorithm?
• v.v
• e.e
• log(e)
• both of above
• none of above
3: Kruskal's algorithm (choose best non-cycle edge) is better than Prim's (choose best tree
• False
4: You have an adjacency list for G, what is the time complexity to compute Graph
transpose G^T ?
• V+e (page-116)
• v.e
• v
• e
5: What general property of the list indicates that the graph has an isolated vertex?
• Breadth first search is shortest path algorithm that works on un-weighted graphs.
• Depth first search is shortest path algorithm that works on un-weighted graphs.
graphs?
• Lists require less space than matrices but take longer to find the weight of an edge
(v1,v2)
• Lists require less space than matrices and they are faster to find the weight of an
• Lists require more space than matrices and they take longer to find the weight of
9: Suppose that a graph G = (V,E) is implemented using adjacency lists. What is the
• O(|V |^2)
• O(|V |^2|E|)
• O(|V | + |E|)
10: The relationship between number of back edges and number of cycles in DFS is,
bits
• 64
• 128
• 96 rep
• 120
12: What is the time complexity to extract a vertex from the priority queue in Prim’s
algorithm?
• v.v
• e.e
• log
13: the analysis of selection algorithm shows the total running time is indeed------------in n.
• arithmetic
• geometric
• linear (page-37)
• orthogonal
(1) In Prim’s algorithm, the additional information maintained by the algorithm is the
length of the shortest edge from vertex v to points already in the tree.
A) TRUE
C) UNKNOWN
(2) Although it requires more complicated data structures, Prim's algorithm for a
minimum spanning tree is better than Kruskal's when the graph has a large number of vertices.
B) FALSE
C: UNKNOWN
A) TRUE. (Page-171)
B) FALSE
C) UNKNOWN
(II) Both Dijkstra’s algorithm and Bellman-Ford are based on performing repeated relaxations
• Only I
• Only III
I. [10,7,7,2,4,6]
II. [10,7,6,2,4,7]
III. [10,6,7,2,4,6]
IV. [6,6,7,2,4,10]
• Only II (page-140)
• Only IV
• Both II and IV
7. Which of the shortest path algorithms would be most appropriate for finding paths in
I.Dijkstra’s Algorithm
• Only II
• Only III
• Yes
• No
11. The recurrence relation of Tower of Hanoi is given below
? 1 if n =1 (page 30)
T n =?
-133( )
In order to move a tower of 6 rings from one peg to another, how many moves are
required?
• 15
• 7
• 63
• 32
• None of these
13. Is 22n= O?
2n -26? ?
14. If, in a DFS forest of digraph G = (V, E), f[u] = f[v] for an edge (u, v) ? E then the
edge is called
• Forward edge
• Cross Edge
• Tree Edge
• None of these
16. Best and worst case times of an algorithm may be same.
• False
17. Can an adjacency matrix for a directed graph ever not be square in shape?
• Yes ()
• No
• (log n) order
as many as,
• T(n) (page37)
• T(n / 2)
• log n
• n/2+n/4
• T(n^2)
• T(n)
• T( log n)
5. One of the clever aspects of heaps is that they can be stored in arrays without using any
_______________.
• constants
• variables
• functions
6. the analysis of Selection algorithm, we eliminate a constant fraction of the array with
• linear
• arithmetic
• exponent
7:. Sieve Technique applies to problems where we are interested in finding a single item
• n items (page34)
• phases
• pointers
• constant
• phases (page34)
• numbers
• integers
• routines
9. For the heap sort, access to nodes involves simple _______________ operations.
• arithmetic (page41)
• binary
• algebraic
• logarithmic
10. The analysis of Selection algorithm shows the total running time is indeed
________in n,
• arithmetic
• geometric
• orthogonal
• pivot
• Sieve
• Selection
• T(n)
• T( log n)
• T(n log n)
13. A heap is a left-complete binary tree that conforms to the
• (log n) order
• in-order traversal
• pre-order traversal
• post-order traversal
15. The reason for introducing Sieve Technique algorithm is that it illustrates a very
• greedy nature
• 2-dimension Maxima
we can sort,
• upper
• average
• log n
• in-order traversal
• pre-order traversal
• post-order traversal
• True (page34)
• False
• T(n)
• T( log n)
• T(n log n)
• pivot
• Sieve
• Selection
• mathematically
• precisely
• accurately
25: The reason for introducing Sieve Technique algorithm is that it illustrates a very
• greedy nature
• 2-dimension Maxima
• false
27: In the analysis of Selection algorithm, we make a number of passes, in fact it could be
as many as,
• T(n)
• T(n / 2)
• n/2+n/4
• pivot
• Sieve
• Selection
• (log n) order
• T(n^2) (repeat)
• T(n)
• T( log n)
• T(n log n)
31: One of the clever aspects of heaps is that they can be stored in arrays without using
any _______________.
• pointers (repeat)
• constants
• variables
• functions
32: Sorting is one of the few problems where provable ________ bonds exits on how fast
we can sort,
• upper
• lower (repeat)
• average
• log n
• mathematically
• precisely
• accurately
• False
37: Heaps can be stored in arrays without using any pointers; this is due to the
• right-complete
• tree nodes
• tree leaves
38: How many elements do we eliminate in each time for the Analysis of Selection
algorithm?
• n / 2 elements
• n / 4 elements
• 2 n elements
41: : In the analysis of Selection algorithm, we make a number of passes, in fact it could
be as many as,
• T(n)
• T(n / 2)
• n/2+n/4
42: The sieve technique is a special case, where the number of sub problems is
just
• 5
• Many
• 1 (pag 34)
• few
► Mechanical machine
► Electronics machine
► Σ notation
► Θnotation
► Flowchart (sure)
► Asymptotic notation
► 256MB
► 512MB
► 100GB
What type of instructions Random Access Machine (RAM) can execute? Choose best
answer
► Algebraic and logic
What will be the total number of max comparisons if we run brute-force maxima
► n2 (not sure)
► 2n/n
► n
► 8n
► O(logn)
► O(n) (sure)
► O(nlogn)
► O(n2)
For(j=1; j<n;j++)
For(k=1; k<15;k++)
{
Do_something_constant();
► O(n)
► O(n2 log n)
► O(n2)
Factorial (n){
if (n=1)
return 1
else
return (n * Factorial(n-1))
► T(n) = T(n-1) +1
► T(n) = nT(n-1) +1
► T(n)= T(n-1) +n
► Ο(n log n)
► Ο(n2 log n)
► Ο(log2 n)
When we call heapify then at each level the comparison performed takes time
► True
► False (page 171)
► unknown
Question No: 4 ( Marks: 1 ) - Please choose one
What is generally true of Adjacency List and Adjacency Matrix representations of graphs?
► Lists require less space than matrices but take longer to find the weight of an edge
(v1,v2)
► Lists require less space than matrices and they are faster to find the weight of an
edge (v1,v2)
► Lists require more space than matrices and they take longer to find the weight of an edge
(v1,v2)
► Lists require more space than matrices but are faster to find the weight of an edge (v1,v2)
► None of these
Question No: 6 ( Marks: 1 ) - Please choose one
Maximum number of vertices in a Directed Graph may be |V2|
► True
► False (vertices “n”)
►
►
►
►
► Values smaller than pivot are on left and larger than pivot are on right
► Values larger than pivot are on left and smaller than pivot are on right
FINALTERM EXAMINATION
Fall 2008
notation
Flowchart
Asymptotic notation
notation
Lower bounds
Upper bounds
Merge sort makes two recursive calls. Which statement is true after these recursive calls finish,
Elements in each half of the array are sorted amongst themselves (page 28)
Elements in the first half of the array are less than or equal to elements in the second half
of the array
Sedgewick
Mellroy
Coreman
O(logn)
O(n)
O(2n)
Question No: 7 ( Marks: 1 ) - Please choose one
If a graph has v vertices and e edges then to obtain a spanning tree we have to delete v edges.
v
e + 5 edges
v + e edges.
None of these
Can an adjacency matrix for a directed graph ever not be square in shape?
Yes
No
One of the clever aspects of heaps is that they can be stored in arrays without using any
_______________.
constants
variables
functions
False
O(2k)
O(N)
The Huffman codes provide a method of encoding data inefficiently when coded using
ASCII standard.
True
Using ASCII standard the string abacdaacac will be encoded with __________ bits.
80 (page 99)
160
320
100
Using ASCII standard the string abacdaacac will be encoded with 160 bits.
True
Using ASCII standard the string abacdaacac will be encoded with 320 bits.
True
Using ASCII standard the string abacdaacac will be encoded with 100 bits.
True
Using ASCII standard the string abacdaacac will be encoded with 32 bytes
True
The greedy part of the Huffman encoding algorithm is to first find two nodes with
smallest frequency.
False
The greedy part of the Huffman encoding algorithm is to first find two nodes with
character frequency
True
Huffman algorithm uses a greedy approach to generate an antefix code T that minimizes
True
Depth first search is shortest path algorithm that works on un-weighted graphs.
True
False (page 153)
Dijkestra s single source shortest path algorithm works if all edges weights are nonnegative and
there are no negative cost cycles.
False
Dijkestra s single source shortest path algorithm works if all edges weights are negative
True
Flase
k
ij d
True
Flase
the case with DP algorithms, we will avoid recursive evaluation by generating a table
for d(k)ij
Question No: 26 ( Marks: 1 ) - Please choose one
The term coloring came form the original application which was in map drawing.
False
In the clique cover problem, for two vertices to be in the same group, they must
be_______________each other.
Apart from
Far from
Near to
In the clique cover problem, for two vertices to be in the same group, they must be apart
True
The difference between Prims algorithm and Dijkstra s algorithm is that Dijkstra s
False
The difference between Prim s algorithm and Dijkstra s algorithm is that Dijkstra s
FINALTERM EXAMINATION
Spring 2010
CS502- Fundamentals of Algorithms (Session - 4)
Although it requires more complicated data structures, Prim's algorithm for a minimum
spanning tree is better than Kruskal's when the graph has a large number of vertices.
True
False
False
unknown
Question No: 4 ( Marks: 1 ) - Please choose one
Lists require less space than matrices but take longer to find the weight of an edge
(v1,v2)
Lists require less space than matrices and they are faster to find the weight of
an edge (v1,v2
Lists require more space than matrices and they take longer to find the weight of an
edge (v1,v2)
Lists require more space than matrices but are faster to find the weight of an edge
(v1,v2)
Question No: 5 ( Marks: 1 ) - Please choose one
If a graph has v vertices and e edges then to obtain a spanning tree we have to
delete
v edges.
v – e + 5 edges v + e
edges.
None of these
True
False
Optimal page102
Non-optimal
Exponential
Polynomial
True
False
True
False
Question No: 10 ( Marks: 1 ) - Please choose one
The greedy part of the Huffman encoding algorithm is to first find two nodes with larger
frequency
True
False
The codeword assigned to characters by the Huffman algorithm have the property that
no codeword is the postfix of any other.
True
True
Shortest path problems can be solved efficiently by modeling the road map
as a graph.
True Page 153
False
Dijkestra’s single source shortest path algorithm works if all edges weights are non-
negative and there are negative cost cycles.
True
True
The term “coloring” came form the original application, which was in architectural design?
True
False Page 173
Which was in architectural design?
True
In the clique cover problem, for two vertices to be in the same group, they must be adjacent to
each other.
True page 176
False
The difference between Prim’s algorithm and Dijkstra’s algorithm is that Dijkstra’s algorithm
uses a different key.
True Page 149-154
False
Keep the algorithm run in linear order keep the algorithm run in
(log n) order
Keep elements in increasing or decreasing order
After partitioning array in Quick sort, pivot is placed in a position such that
Values smaller than pivot are on left and larger than pivot are on right
Values larger than pivot are on left and smaller than pivot are on right
Pivot is the first element of array Pivot is the last element of array
True
False
In counting sort, once we know the ranks, we simply numbers to their final positions in an
output array.
Delete copy
Page 57
Mark
arrange
True Page 75
False
CS502 - Fundamentals of Algorithms
No of inputs
Size o elements
O(n^2)
O(nlogn)
O(n+k) (Right Answer) Not sure
O(n^3)
Large
Medium
Not known
Small (ref.Book.page-95)
Quick sort is based on divide and conquer paradigm; we divide the problem on base of
pivot element and:
None of above.
There is relationship between number of back edges and number of cycles in DFS
(V+E) (Page-138)
V.E
What is the time complexity to extract a vertex from the priority queue in Prim’s?
Algorithm?
V.V
E.E
log (E)
Dijkstra’s algorithm:
Has greedy approach to find all shortest paths
Has both greedy and dynamic approach to find all shortest paths
Has greedy approach to compute single source shortest paths to all other vertices (page-154)
Has both greedy and dynamic approach to compute single source shortest paths to all other
vertices.
What algorithm technique is used in the implementation of Kruskal solution for the
MST?
Greedy Technique (Page-142)
Divide-and-Conquer Technique
Dynamic Programming Technique
The algorithm combines more than one of the above techniques
What is the time complexity to extract a vertex from the priority queue in Prim’s
algorithm?
O (log E)
? (V)
? (V+E)
O (log V) (Page-152)
Which is true statement in the following?
Kruskal’s algorithm is used to find minimum spanning tree of a graph, time complexity of this
algorithm is O(EV)
Both of above
Kruskal's algorithm (choose best non-cycle edge) is better than Prim’s (choose best Tree
edge) when the graph has relatively few edges) (page-149)Not sure
The relationship between number of back edges and number of cycles in DFS is,
Kruskal's algorithm (choose best non-cycle edge) is better than Prim's (choose best tree
True (page-149)
False
What is the time complexity to extract a vertex from the priority queue in Prim’s
Algorithm?
log (V)(page-152)
V.V
E.E
log (E)
Suppose that a graph G = (V,E) is implemented using adjacency lists. What is the
complexity of a breadth-first traversal of G?
O(|V |^2)
O(|V |^2|E|)
O(|V | + |E|)
What is generally true of Adjacency List and Adjacency Matrix representations of graphs?
Lists require less space than matrices but take longer to find the weight of an edge (v1,v2)
Lists require less space than matrices and they are faster to find the weight of an edge (v1,
v2) ( Right Answer)
Lists require more space than matrices and they take longer to find the weight of an edge (v1, v2)
Lists require more space than matrices but are faster to find the weight of an edge (v1, v2)
What general property of the list indicates that the graph has an isolated vertex?
None of above
Using ASCII standard the string “abacdaacacwe” will be encoded with __________ bits
64
128
120
(u, v) where u and v are not ancestor or descendent of one another (page-129)
None of above
Breadth first search is shortest path algorithm that works on un-weighted graphs (Page-
153)
Depth first search is shortest path algorithm that works on un-weighted graphs.
None of above
Suppose that a graph G = (V,E) is implemented using adjacency lists. What is the
complexity of a breadth-first traversal of G?
O(|V |^2)
O(|V |^2|E|)
O(|V | + |E|)
What general property of the list indicates that the graph has an isolated vertex?
BFS
Level order
DFS
Cross edge is :
(u, v) where u and v are not ancestor or descendent of one another (Page-129)
What algorithm technique is used in the implementation of Kruskal solution for the MST?
Divide-and-Conquer Technique
Kruskal's algorithm (choose best non-cycle edge) is better than Prim's (choose best tree
edge) when the graph has relatively few
True (page-149)
False
You have an adjacency list for G, what is the time complexity to compute Graph transpose
G^T.?
?(V + E) ref.Book(Page-323)
? (V E)
? (V)
? (V^2)
A digraph is strongly connected if for every pair of vertices u, v e V, u can reach v and vice
versa. (page-135)
A digraph is strongly connected if for at least one pair of vertex u, v e V, u can reach v and vice
versa.
A digraph is strongly connected if at least one third pair of vertices u, v e V, u can reach v and
vice versa.
The relationship between number of back edges and number of cycles in DFS is,
“There is some simple relationship between the number of back edges and the number of
cycles.”
What algorithm technique is used in the implementation of Kruskal solution for the MST?
Divide-and-Conquer Technique
………………………………………………………………………………………………………