Está en la página 1de 66

FINALTERM EXAMINATION

Spring 2010

Question No: 1 ( Marks: 1 ) - Please choose one


An optimization problem is one in which you want to find,
► Not a solution
► An algorithm
► Good solution
► The best solution

Question No: 2 ( Marks: 1 ) - Please choose one


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

Question No: 3 ( Marks: 1 ) - Please choose one


If a problem is in NP, it must also be in P.
► True
► False
► 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)

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

Question No: 6 ( Marks: 1 ) - Please choose one


Maximum number of vertices in a Directed Graph may be |V2|
► True
► False
Question No: 7 ( Marks: 1 ) - Please choose one
The Huffman algorithm finds a (n) _____________ solution.
► Optimal
► Non-optimal
► Exponential
► Polynomial

Question No: 8 ( Marks: 1 ) - Please choose one


The Huffman algorithm finds an exponential solution
► True
► False

Question No: 9 ( Marks: 1 ) - Please choose one


The Huffman algorithm finds a polynomial solution
► 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

Question No: 11 ( Marks: 1 ) - Please choose one


The codeword assigned to characters by the Huffman algorithm have the property that no
codeword is the postfix of any other.
► True
► False

Question No: 12 ( Marks: 1 ) - Please choose one


Huffman algorithm uses a greedy approach to generate a postfix code T that minimizes
the expected length B (T) of the encoded string.
► True
► False

Question No: 13 ( Marks: 1 ) - Please choose one


Shortest path problems can be solved efficiently by modeling the road map as a graph.
► True
► False

Question No: 14 ( Marks: 1 ) - Please choose one


Dijkestra’s single source shortest path algorithm works if all edges weights are non-
negative and there are negative cost cycles.
► True
► False
Question No: 15 ( Marks: 1 ) - Please choose one
Bellman-Ford allows negative weights edges and negative cost cycles.
► True
► False

Question No: 16 ( Marks: 1 ) - Please choose one


The term “coloring” came form the original application which was in architectural
design.
► True
► False

Question No: 17 ( Marks: 1 ) - Please choose one


In the clique cover problem, for two vertices to be in the same group, they must be
adjacent to each other.
► True
► False

Question No: 18 ( Marks: 1 ) - Please choose one


Dijkstra’s algorithm is operates by maintaining a subset of vertices
► True
► False

Question No: 19 ( Marks: 1 ) - Please choose one


The difference between Prim’s algorithm and Dijkstra’s algorithm is that Dijkstra’s
algorithm uses a different key.
► True
► False

Question No: 20 ( Marks: 1 ) - Please choose one


Consider the following adjacency list:
Which of the following graph(s) describe(s) the above adjacency list?

Question No: 21 ( Marks: 1 ) - Please choose one


We do sorting to,
► keep elements in random positions
► keep the algorithm run in linear order
► keep the algorithm run in (log n) order
► keep elements in increasing or decreasing order

Question No: 22 ( Marks: 1 ) - Please choose one


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

Question No: 23 ( Marks: 1 ) - Please choose one


Merge sort is stable sort, but not an in-place algorithm
► True
► False

Question No: 24 ( Marks: 1 ) - Please choose one


In counting sort, once we know the ranks, we simply _________ numbers to their final
positions in an output array.
► Delete
► copy
► Mark
► arrange

Question No: 25 ( Marks: 1 ) - Please choose one


Dynamic programming algorithms need to store the results of intermediate sub-problems.
► True
► False

Question No: 26 ( Marks: 1 ) - Please choose one


A p × q matrix A can be multiplied with a q × r matrix B. The result will be a p × r matrix
C. There are (p . r) total entries in C and each takes _________ to compute.
► O (q)
► O (1)
► O (n2)
► O (n3)

Question No: 27 ( Marks: 2 )


Give a detailed example for 2-d maxima problem.

Let took a point p in 2-dimensional space


given by its integer coordinates, p = (p.x, p.y).

A point p is said to dominated by point q if


p.x ≤ q.x and
p.y ≤ q.y.
Given a set of n points,
P = {p1, p2, . . . , pn} in 2-space
a point is said to be maximal if it is not dominated by any other point in P.

The problem is to output all the maximal points of P. A brute-force algorithm


that ran in Θ(n2) time is used in it. It operated by comparing all pairs of points.
the brute-force algorithm uses no intelligence in pruning out decisions.
For example, once we know that a point pi is dominated by another point pj, we do not
need to use pi for eliminating other points. This follows from the fact that dominance
relation is transitive. If pj dominates pi and pi dominates ph then pj also dominates ph; pi
is not needed.

Question No: 28 ( Marks: 2 )


Differentiate between back edge and forward edge.

For directed graphs edges r classified as:


Back edge: (u, v) where v is an ancestor of u in the tree.
Forward edge: (u, v) where v is a proper descendent of u in the tree.
Cross edge: (u, v) where u and v are not ancestor or descendent of one another. In fact,
the edge may go between different trees of the forest.

Question No: 29 ( Marks: 2 )


How the generic greedy algorithm operates in minimum spanning tree?

Ans:
In undirected, connected graph whose edges have numeric weights are
G = (V, E)
Here’s applying generic greedy algorithm operates in minimum spanning tree is simple.
we maintain a subset of edges E of the graph .
∪ This subset is A.

Initially, A is empty. We will add edges one at a time until A equals the MST.
A subset A ⊆ E is viable if A is a subset of edges of some MST.
An edge (u, v) ∈ E − A is safe if
A ∪ {(u, v)} is viable.
In other words, the choice (u, v) is a safe choice to add so that A can still be extended to
form a MST. if A is viable, it cannot contain a cycle. A generic greedy algorithm operates
by repeatedly adding any safe edge to the current spanning tree.

Question No: 30 ( Marks: 2 )


(k)
What are two cases for computing d ij assuming we already have the previous matrix
d ( k −1) using Floyed-Warshall algorithm?

Ans:
(k)
The two cases for computing d ij assuming we already have the previous matrix d ( k −1)
using Floyed-Warshall algorithm are:
1. Don’t go through vertex k at all.
2. Do go through vertex k

Question No: 31 ( Marks: 3 )


Describe Minimum Spanning Trees Problem with examples.

Question No: 32 ( Marks: 3 )


What is decision problem, also explain with example?

Ans:
A problem is called a decision problem if its output is a simple
• yes or no
• true/false,
• 0/1,
• Accept/reject.)
For example:
The MST decision problem would be a decision problem, Given a weighted graph G and
an integer k, does G have a spanning tree whose weight is at most k?

Question No: 33 ( Marks: 3 )


Prove that the generic TRAVERSE (S) marks every vertex in any connected graph
exactly once and the set of edges (v, parent (v)) with parent (v) ¹ F form a spanning tree
of the graph.

Ans:
Proof:
it should be sured that no vertex is marked more than once. The algorithm marks s. Let
v = s be a vertex and
let s → · · · → u → v be a path from s to v with the minimum number of edges.
Since the graph is connected, such a path always exists. If the algorithm marks u, then it
must put (u, v) into the bag, so it must take (u, v) out of the bag at which point v must be
marked. Thus, by induction on the shortest path distance from s, the algorithm marks
every vertex in the graph.
Call an edge (v, parent(v)) with parent(v) = ∅, a parent edge. For any node v, the path of
parent edges v → parent(v) → parent(parent(v)) → . . . eventually leads back to s. So the
set of parent edges form a connected graph.
both end points of every parent edge are marked, and the number of edges is exactly one
less than the number of vertices. Thus, the parent edges form a spanning tree.

Question No: 34 ( Marks: 5 )


Suppose you could reduce an NP-complete problem to a polynomial time problem in
polynomial time. What would be the consequence?
Question No: 35 ( Marks: 5 )
Prove the following lemma,
Lemma: Given a digraph G = (V, E), consider any DFS forest of G and consider any
edge (u, v) ∈ E. If this edge is a tree, forward or cross edge, then f[u] > f[v]. If this edge
is a back edge, then f[u] ≤ f[v]

Ans:
Proof:

For the non-tree forward and back edges the proof follows directly from the parenthesis
lemma.
For example,
for a forward edge (u, v), v is a descendent of u and so v’s start-finish interval is
contained within u’s implying that v has an earlier finish time.

For a cross edge (u, v) the two time intervals are disjoint. When we were processing u, v
was not white (otherwise (u, v) would be a tree edge), implying that v was started before
u. Because the intervals are disjoint, v must have also finished before u.

Question No: 36 ( Marks: 5 )


What is the cost of the following graph?

Pseudo code of DFS 5

Ans:
DFS procedure can be written
1. recursively or
2. non-recursively.

RECURSIVEDFS(v)
if (v is unmarked )
then mark v
for each edge (v,w)
do RECURSIVEDFS(w)

ITERATIVEDFS(s)
PUSH(s)
while stack not empty
do v ← POP()
if v is unmarked
then mark v
for each edge (v,w)
do PUSH(w)

and prove the DFS algorithm 5


Total 36 Questions,

26 MCQ’s

Using ASCII standard the string abacdaacac will be encoded with __________ bits.
80
160
320
100

Using ASCII standard the string abacdaacac will be encoded with 160 bits.
True
False

Using ASCII standard the string abacdaacac will be encoded with 320 bits.
True
False

Using ASCII standard the string abacdaacac will be encoded with 100 bits.

True
False

Please choose oneConsider the following Huffman Tree


The binary code for the string TEA is

10 00 010
011 00 010
10 00 110
11 10 110

The book written by Al-Khwarzami


Hisab al-jabr w'al mugabalah

The Huffman algorithm finds a (n) _____________ solution.


► Optimal
► Non-optimal
► Exponential
► Polynomial

Huffman algorithm uses a greedy approach to generate a postfix code T that minimizes
the expected length B (T) of the encoded string.
► True
► False

The difference between Prim’s algorithm and Dijkstra’s algorithm is that Dijkstra’s
algorithm uses a different key.
► True
► False
4 Questions of 2 Marks
1. Difference between Prim’s algorithm and Dijikstra’s algorithm.

Ans:

The difference between Prim’s algorithm and Dijkstra’s algorithm is that Dijkstra’s
algorithm uses a different key.

2. What is coloring problem?


3. Is it better that we using brute force approach to solve knap sack
problem, can we do better.

3 Questions of 3 Marks

1. following is the list of adjacency vertex, Identify that is any vertex have
isolated property.
a-------b--c
b------d--e
e------f--d
c-----b---f
f----b
g

2. How Dijikstra’s algorithm operate, give an example.

3 Questions of 5 Marks.

1. What is the reduction, Explain with example. (From Last chapter of handsout)

2. Describe the Minimum spanning Tree with example.

3. What is the cost of following Graph.


1: What is the time complexity to extract a vertex from the priority queue in Prim’s
algorithm?

• log (v)
• v.v
• e.e
• log(e)

2: Which statement is true?

• If a dynamic-programming problem satisfies the optimal-substructure property,


then a locally optimal solution is globally optimal.
• If a greedy choice property satisfies the optimal-substructure property, then a
locally optimal solution is globally optimal.
• both of above
• none of above

3: Kruskal's algorithm (choose best non-cycle edge) is better than Prim's (choose best tree
edge) when the graph has relatively few edges.

• True
• False

4: You have an adjacency list for G, what is the time complexity to compute Graph
transpose G^T ?

• V+e
• v.e
• v
• e

5: What general property of the list indicates that the graph has an isolated vertex?
• There is Null pointer at the end of list.
• The Isolated vertex is not handled in list.
• Only one value is entered in the list.
• There is at least one null list.

6: Which is true statement.

• 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.
• Both of above are true.
• None of above are true.

7: A dense undirected graph is:


• A graph in which E = O(V^2)
• A graph in which E = O(V)
• A graph in which E = O(log V)
• All items above may be used to characterize a dense undirected graph.

8: 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).

9: 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 | |E|)
• O(|V |^2|E|)
• O(|V | + |E|)

10: The relationship between number of back edges and number of cycles in DFS is,

• Both are equal


• Back edges are half of cycles
• Back edges are one quarter of cycles
• There is no relationship between no. of edges and cycles

11: Using ASCII standard the string “abacdaacacwe” will be encoded with __________
bits

• 64
• 128
• 96
• 120

12: What is the time complexity to extract a vertex from the priority queue in Prim’s
algorithm?

• log (V)
• v.v
• e.e
• log

13: the analysis of selection algorithm shows the total running time is indeed------------in
n.

• arithmetic
• geometric
• linear
• orthogonal

14: back edge is

(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
B) FALSE
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.
A) TRUE.
B) FALSE
C: UNKNOWN

(3) If a problem is NP-complete, it must also be in NP.


A) TRUE.
B) FALSE
C) UNKNOWN

(4) What is the worst-case runtime complexity of the following C function


int function(int n){
int i, j, k;
k = n;
for(i=-100; i<10*log(n);i++){
k = k/2;
} for(j=i; j> n; j--){
k=j/2;
}r
return k;
}

What order is the execution of this code


a) O(log n)
b) O(n)
c) O(n log n)
d) O(n2)
e) O(n2 log n)

(4) Which statement is true


(I) The running time of Bellman-Ford algorithm is T (VE)
(II) Both Dijkstra’s algorithm and Bellman-Ford are based on performing repeated
relaxations
(III) The 0-1 knapsack problem is hard to solve

• Only I
• Only III
• Both I and III
• All of these
5) Which of the following arrays represent descending (max) heaps?
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
• Only IV
• Both II and IV
• Both I and III
6. Which of the following statement(s) is/are correct?
(a) O(n log n + n2) = O(n2).
(b) O(n log n + n2) = O(n2 log 2n)
(c) O(c n2) = O(n2) where c is a constant.
(d) O(c n2) = O(c) where c is a constant.
(e) O(c) = O(1) where c is a constant.

• Only (a) & (e)


• Both (c) and (e)

7. Which of the shortest path algorithms would be most appropriate for finding paths in
the graph with negative edge weights and cycles?
I.Dijkstra’s Algorithm
II. Bellman-Ford Algorithm
III. Floyd Warshall Algorithm

• Only II
• Only III
• Both II & III

8. Which of the following orders is not a possible order in which Depth First Search can
visit the vertices of the directed graph shown below?

• ABCEFD
• ACEBFD
• ADFEBC
• ADFBCE
• ABFECD

9. Suppose we have two problems A and B .Problem A is polynomial-time reducible and


problem B is NP-complete. If we reduce problem A into B then problem A becomes NP-
complete

• Yes
• No

10. How can the number of strongly connected components of a graph change if a new
edge is added?
• The number of strongly connected components can be increased.
• The number of strongly connected components can be reduced.
• No change will occur.
• None of these.

11. The recurrence relation of Tower of Hanoi is given below


? 1 if n =1
T n =?
-133( )
2 (T n- +1) 1if n>1
In order to move a tower of 6 rings from one peg to another, how many moves are
required?
• 15
• 7
• 63
• 32

12. Edge (u, v) is a forward edge if


• u is a proper descendant of v in the tree
• v is a proper descendant of u in the tree
• None of these
13. Is 22n= O?
2n -26? ?

• Yes it is possible
• No it is not possible
• None of these

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
• Back edge
• Forward edge
• Cross Edge
• Tree Edge
• None of these

15. How can the number of strongly connected components of a graph change if a new
edge is added?
• The number of strongly connected components can be increased.
• The number of strongly connected components can be reduced.
• No change will occur.
• None of these.
16. Best and worst case times of an algorithm may be same.
• True
• False

17. Can an adjacency matrix for a directed graph ever not be square in shape?
• Yes
• No

18. If an algorithm has a complexity of 2n2+ 4n + 3 for some model of computation (some
set of assumptions) and some complexity measures (such as number of comparison
operations) we could say that it has complexity
(a) O(log n)
2

(b) O(n2)
(c) O(2 + 4 + 3)
(d) all of the above
(e) none of the above
1. In which order we can sort?
• increasing order only
• decreasing order only
• increasing order or decreasing order
• both at the same time

2. heap is a left-complete binary tree that conforms to the ___________


• increasing order only
• decreasing order only
• heap order
• (log n) order

3. 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)
• log n
• n/2+n/4

4. How much time merge sort takes for an array of numbers?


• T(n^2)
• T(n)
• T( log n)
• T(n log n)

5. One of the clever aspects of heaps is that they can be stored in arrays without using any
_______________.
• pointers
• constants
• variables
• functions
6. the analysis of Selection algorithm, we eliminate a constant fraction of the array with
each phase; we get the convergent _______________ series in the analysis
• linear
• arithmetic
• geometric
• exponent
7:. Sieve Technique applies to problems where we are interested in finding a single item
from a larger set of _____________
• n items
• phases
• pointers
• constant
8. The sieve technique works in ___________ as follows
• phases
• numbers
• integers
• routines
9. For the heap sort, access to nodes involves simple _______________ operations.
• arithmetic
• binary
• algebraic
• logarithmic

10. The analysis of Selection algorithm shows the total running time is indeed
________in n,
• arithmetic
• geometric
• linear
• orthogonal

11. Divide-and-conquer as breaking the problem into a small number of


• pivot
• Sieve
• smaller sub problems
• Selection

12. Slow sorting algorithms run in,


• T(n^2)
• T(n)
• T( log n)
• T(n log n)

13. A heap is a left-complete binary tree that conforms to the


• increasing order only
• decreasing order only
• heap order
• (log n) order

14. For the heap sort we store the tree nodes in


• level-order traversal
• in-order traversal
• pre-order traversal
• post-order traversal
15. The reason for introducing Sieve Technique algorithm is that it illustrates a very
important special case of,
• divide-and-conquer,
• decrease and conquer
• greedy nature
• 2-dimension Maxima

16. We do sorting to,


Select correct option:
• keep elements in random positions
• keep the algorithm run in linear order
• keep the algorithm run in (log n) order
• keep elements in increasing or decreasing order
17. Sorting is one of the few problems where provable ________ bonds exits on how fast
we can sort,
Select correct option:
• upper
• lower
• average
• log n

For the heap sort we store the tree nodes in


Select correct option:
• level-order traversal
• in-order traversal
• pre-order traversal
• post-order traversal

18: For the Sieve Technique we take time


• T(nk)
• T(n / 3)
• n^2
• n/3
20: In Sieve Technique we do not know which item is of interest
Select correct option:
• True
• False

21: Slow sorting algorithms run in,


• T(n^2)
• T(n)
• T( log n)
• T(n log n)
22: Divide-and-conquer as breaking the problem into a small number of
• pivot
• Sieve
• smaller sub problems
• Selection

23: For the sieve technique we solve the problem,

• recursively
• mathematically
• precisely
• accurately

24: we do sorting to,

• keep elements in random positions


• keep the algorithm run in linear order
• keep the algorithm run in (log n) order
• keep elements in increasing or decreasing order

25: The reason for introducing Sieve Technique algorithm is that it illustrates a very
important special case of,

• divide-and-conquer
• decrease and conquer
• greedy nature
• 2-dimension Maxima

26: In Sieve Technique we do


not know which item is of interest

• true
• 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)
• log n
• n/2+n/4
28: Divide-and-conquer as breaking the problem into a small number of

• pivot
• Sieve
• smaller sub problems
• Selection

29: A heap is a left-complete binary tree that conforms to the ___________

• increasing order only


• decreasing order only
• heap order
• (log n) order

30: Slow sorting algorithms run in,

• T(n^2)
• 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
• constants
• variables
• functions

32: Sorting is one of the few problems where provable ________ bonds exits on how fast
we can sort,

• upper
• lower
• average
• log n

33: For the sieve technique we solve the problem,

• mathematically
• precisely
• accurately
• recursively
34: Sieve Technique can be applied to selection problem?

• True
• False

35: How much time merge sort takes for an array of numbers?

• (n^2)
• T(n)
• T( log n)
• T(n log n)

36; : For the Sieve Technique we take time

• T(nk)
• T(n / 3)
• n^2
• n/3

37: Heaps can be stored in arrays without using any pointers; this is due to the
____________ nature of the binary tree,
• left-complete
• 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 / 2) + n elements
• n / 4 elements
• 2 n elements

39: We do sorting to,

• keep elements in random positions


• keep the algorithm run in linear order
• keep the algorithm run in (log n) order
• keep elements in increasing or decreasing order

40: In which order we can sort?

• increasing order only


• decreasing order only
• increasing order or decreasing order
• both at the same time

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)
• log n
• n/2+n/4

42: The sieve technique is a special case, where the number of sub problems is
just

• 5
• Many
• 1
• few

Question No: 1 ( Marks: 1 ) - Please choose one


Random access machine or RAM is a/an
► Machine build by Al-Khwarizmi
► Mechanical machine
► Electronics machine
► Mathematical model

Question No: 2 ( Marks: 1 ) - Please choose one


_______________ is a graphical representation of an algorithm
► Σ notation
► Θ notation
► Flowchart
► Asymptotic notation

Question No: 3 ( Marks: 1 ) - Please choose one


A RAM is an idealized machine with ______________ random-access memory.
► 256MB
► 512MB
► an infinitely large
► 100GB

Question No: 4 ( Marks: 1 ) - Please choose one


What type of instructions Random Access Machine (RAM) can execute? Choose best
answer
► Algebraic and logic
► Geometric and arithmetic
► Arithmetic and logic
► Parallel and recursive

Question No: 5 ( Marks: 1 ) - Please choose one


What will be the total number of max comparisons if we run brute-force maxima
algorithm with n elements?
► n2
n
► n2
►n
► n8

Question No: 6 ( Marks: 1 ) - Please choose one


What is the solution to the recurrence T(n) = T(n/2)+n .

► O(logn)
► O(n)
► O(nlogn)
► O(n2)

Question No: 7 ( Marks: 1 ) - Please choose one


Consider the following code:
For(j=1; j<n;j++)
For(k=1; k<15;k++)
For(l=5; l<n; l++)
{
Do_something_constant();
}
What is the order of execution for this code.
► O(n)
► O(n3)
► O(n2 log n)
► O(n2)

Question No: 8 ( Marks: 1 ) - Please choose one


Consider the following Algorithm:
Factorial (n){
if (n=1)
return 1
else
return (n * Factorial(n-1))

}
Recurrence for the following algorithm is:
► T(n) = T(n-1) +1
► T(n) = nT(n-1) +1
► T(n)= T(n-1) +n
► T(n)=T(n(n-1)) +1

Question No: 9 ( Marks: 1 ) - Please choose one


What is the total time to heapify?
► Ο(log n)
► Ο(n log n)
► Ο(n2 log n)
► Ο(log2 n)

Question No: 10 ( Marks: 1 ) - Please choose one


When we call heapify then at each level the comparison performed takes time
► It will take Θ (1)
► Time will vary according to the nature of input data
► It can not be predicted
► It will take Θ (log n)

Question No: 11 ( Marks: 1 ) - Please choose one


In Quick sort, we don’t have the control over the sizes of recursive calls
► True
► False
► Less information to decide
► Either true or false

Question No: 12 ( Marks: 1 ) - Please choose one


Is it possible to sort without making comparisons?
► Yes
► No

Question No: 13 ( Marks: 1 ) - Please choose one


If there are Θ (n2) entries in edit distance matrix then the total running time is
► Θ (1)
► Θ (n2)
► Θ (n)
► Θ (n log n)

Question No: 14 ( Marks: 1 ) - Please choose one


For Chain Matrix Multiplication we can not use divide and conquer approach
because,
► We do not know the optimum k
► We use divide and conquer for sorting only
► We can easily perform it in linear time
► Size of data is not given

Question No: 15 ( Marks: 1 ) - Please choose one


The Knapsack problem belongs to the domain of _______________ problems.
► Optimization
► NP Complete
► Linear Solution
► Sorting

Question No: 16 ( Marks: 1 ) - Please choose one


Suppose we have three items as shown in the following table, and suppose the
capacity of the knapsack is 50 i.e. W = 50.
Item Value Weight
1 60 10
2 100 20
3 120 30
The optimal solution is to pick
► Items 1 and 2
► Items 1 and 3
► Items 2 and 3
► None of these

3. ______________ graphical representation of algorithm.

> asymptotic

>. flowchart

4. who invented the quick sort

C.A.R. Hoare

5. function is given like 4n^4+ 5n^3+n what is the run time of this

• Θ (n^4)
• Θ (n^3)
• Θ (4n^4+ 5n^3)
• Θ (4n^4+ 5n^3)

6. main elements to a divide-and-conquer

Divide---->conquer---------->combine

7. T(n)={4 if n=1, otherwise T(n/5)+3n^2


what is the answer if n=5

answer is 79

8. Merge sort is a stable algorithm but not an in-place algorithm.

>True

>false

_______________ is a graphical representation of an algorithm


• notation
• Flowchart
• Asymptotic notation

• ∑ notation
Question No: 2 ( Marks: 1 ) - Please choose one

Which of the following is calculated with Big o notation?


• Lower bounds
• Upper bounds
• Both upper and lower bound
• Medium bounds

Question No: 3 ( Marks: 1 ) - Please choose one


Merge sort makes two recursive calls. Which statement is true after these recursive calls
finish, but before the merge step?
• The array elements form a heap
• Elements in each half of the array are sorted amongst themselves
• Elements in the first half of the array are less than or equal to elements in the
second half of the array
• None of the above

Question No: 4 ( Marks: 1 ) - Please choose one


Who invented Quick sort procedure?
• Hoare
• Sedgewick
• Mellroy
• Coreman

Question No: 5 ( Marks: 1 ) - Please choose one


What is the solution to the recurrence T(n) = T(n/2)+n, T(1) = 1
• O(logn)
• O(n)
• O(nlogn)
• O(2n)

FINALTERM EXAMINATION
Fall 2008
CS502- Fundamentals of Algorithms (Session - 1)
Marks: 75
Question No: 1 ( Marks: 1 ) - Please choose one
_______________ is a graphical representation of an algorithm
notation
Flowchart
Asymptotic notation
notation

Question No: 2 ( Marks: 1 ) - Please choose one


Which of the following is calculated with Bigo notation?
Lower bounds
Upper bounds
Both upper and lower bound
Medium bounds

Question No: 3 ( Marks: 1 ) - Please choose one


Merge sort makes two recursive calls. Which statement is true after these recursive calls
finish, but before the merge step?
The array elements form a heap
Elements in each half of the array are sorted amongst themselves
Elements in the first half of the array are less than or equal to elements in the
second half of the array
None of the above

Question No: 4 ( Marks: 1 ) - Please choose one


Who invented Quick sort procedure?
Hoare
Sedgewick
Mellroy
Coreman

Question No: 5 ( Marks: 1 ) - Please choose one


What is the solution to the recurrence T(n) = T(n/2)+n, T(1) = 1
O(logn)
O(n)
O(nlogn)
O(2n)
Question No: 6 ( Marks: 1 ) - Please choose one(Huffman tree is missing)
Consider the following Huffman Tree
The binary code for the string TEA is
10 00 010
011 00 010
10 00 110
11 10 110

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

Question No: 8 ( Marks: 1 ) - Please choose one


Can an adjacency matrix for a directed graph ever not be square in shape?
Yes
No

Question No: 9 ( Marks: 1 ) - Please choose one


One of the clever aspects of heaps is that they can be stored in arrays without using any
_______________.
Pointers
constants
variables
functions

Question No: 10 ( Marks: 1 ) - Please choose one


Merge sort requires extra array storage,
True
False

Question No: 11 ( Marks: 1 ) - Please choose one


Non-optimal or greedy algorithm for money change takes____________
O(k)
O(kN)
O(2k)
O(N)

Question No: 12 ( Marks: 1 ) - Please choose one


The Huffman codes provide a method of encoding data inefficiently when coded using
ASCII standard.
True
False

Question No: 13 ( Marks: 1 ) - Please choose one


Using ASCII standard the string abacdaacac will be encoded with __________ bits.
80
160
320
100

Question No: 14 ( Marks: 1 ) - Please choose one


Using ASCII standard the string abacdaacac will be encoded with 160 bits.
True
False

Question No: 15 ( Marks: 1 ) - Please choose one


Using ASCII standard the string abacdaacac will be encoded with 320 bits.
True
False

Question No: 16 ( Marks: 1 ) - Please choose one


Using ASCII standard the string abacdaacac will be encoded with 100 bits.
True
False

Question No: 17 ( Marks: 1 ) - Please choose one


Using ASCII standard the string abacdaacac will be encoded with 32 bytes
True
False

Question No: 18 ( Marks: 1 ) - Please choose one


The greedy part of the Huffman encoding algorithm is to first find two nodes with
smallest frequency.
True
False

Question No: 19 ( Marks: 1 ) - Please choose one

The greedy part of the Huffman encoding algorithm is to first find two nodes with
character frequency
True
False

Question No: 20 ( Marks: 1 ) - Please choose one


Huffman algorithm uses a greedy approach to generate an antefix code T that minimizes
the expected length B (T) of the encoded string.
True
False

Question No: 21 ( Marks: 1 ) - Please choose one


Depth first search is shortest path algorithm that works on un-weighted graphs.
True
False

Question No: 22 ( Marks: 1 ) - Please choose one


Dijkestra s single source shortest path algorithm works if all edges weights are
nonnegative
and there are no negative cost cycles.
True
False

Question No: 23 ( Marks: 1 ) - Please choose one


Dijkestra s single source shortest path algorithm works if all edges weights are negative
and there are no negative cost cycles.

True
False
hb

Question No: 24 ( Marks: 1 ) - Please choose one


Floyd-Warshall algorithm is a dynamic programming algorithm; the genius of the
algorithm is in the clever recursive formulation of the shortest path problem.
True
Flase
Question No: 25 ( Marks: 1 ) - Please choose one
Floyd-Warshall algorithm, as in the case with DP algorithms, we avoid recursive
evaluation by generating a table for
k
ij d
True
Flase

Question No: 26 ( Marks: 1 ) - Please choose one


The term coloring came form the original application which was in map drawing.
True
False

Question No: 27 ( Marks: 1 ) - Please choose one


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
Adjacent to

Question No: 28 ( Marks: 1 ) - Please choose one


In the clique cover problem, for two vertices to be in the same group, they must be apart
from each other.
True
False

Question No: 29 ( Marks: 1 ) - Please choose one


The difference between Prim s algorithm and Dijkstra s algorithm is that Dijkstra s
algorithm uses a different key.
True
False

Question No: 30 ( Marks: 1 ) - Please choose one


The difference between Prim s algorithm and Dijkstra s algorithm is that Dijkstra s
algorithm uses a same key.
True
False

Question # 1 of 10 ( Start time: 06:18:58 PM ) Total Marks: 1


We do sorting to,
Select correct option:

keep elements in random positions


keep the algorithm run in linear order
keep the algorithm run in (log n) order
keep elements in increasing or decreasing order

Question # 2 of 10 ( Start time: 06:19:38 PM ) Total Marks: 1


Heaps can be stored in arrays without using any pointers; this is due to the ____________
nature of the binary tree,
Select correct option:

left-complete
right-complete
tree nodes
tree leaves
Sieve Technique can be applied to selection problem?
Select correct option:

True
False

Question # 4 of 10 ( Start time: 06:21:10 PM ) Total Marks: 1


A heap is a left-complete binary tree that conforms to the ___________
Select correct option:

increasing order only


decreasing order only
heap order
(log n) order
Question # 5 of 10 ( Start time: 06:21:39 PM ) Total Marks: 1
A (an) _________ is a left-complete binary tree that conforms to the heap order
Select correct option:

heap
binary tree
binary search tree
array

Question # 6 of 10 ( Start time: 06:22:04 PM ) Total Marks: 1


Divide-and-conquer as breaking the problem into a small number of
Select correct option:

pivot
Sieve
smaller sub problems
Selection
Question # 7 of 10 ( Start time: 06:22:40 PM ) Total Marks: 1
In Sieve Technique we do not know which item is of interest
Select correct option:

True
False

Question # 8 of 10 ( Start time: 06:23:26 PM ) Total Marks: 1


The recurrence relation of Tower of Hanoi is given below T(n)={1 if n=1 and 2T(n-1) if
n >1 In order to move a tower of 5 rings from one peg to another, how many ring moves
are required?
Select correct option:

16
10
32
31 (yeh just tukkahai)

Question # 9 of 10 ( Start time: 06:24:44 PM ) Total Marks: 1


In the analysis of Selection algorithm, we eliminate a constant fraction of the array with
each phase; we get the convergent _______________ series in the analysis,
Select correct option:

linear
arithmetic
geometric (yeh b gup hi lugtihai)
exponent

Question # 10 of 10 ( Start time: 06:25:43 PM ) Total Marks: 1


For the heap sort, access to nodes involves simple _______________ operations.
Select correct option:

arithmetic
binary
algebraic
logarithmic (bongihai...)

Question No: 31 ( Marks: 1 )


Do you think greedy algorithm gives an optimal solution to the activity scheduling
problem?
yes, greedy algorithm gives an optimal solution to the activity scheduling
problem. as we have the data as a whole ,and activity a1 must be started at a given
start time and ends at a given finish time. all the intermediate activities who overlap
will be excluded automatically as no new activity will be selected as our data till the
finish of last activity. so this greediness of algorithm gives us the optimal solution.

Question No: 32 ( Marks: 1 )


Define Forward edge

A forward edge is a non-tree edge that connects a vertex to a descendent in a DFS-


tree.

Question No: 33 ( Marks: 2 )


Is there any relationship between number of back edges and number of cycles in DFS?

A back edge connects a vertex to an ancestor in a DFS-tree. No back edges means no


cycles. But there is some simple relationship Between the number of back edges and
the number of cycles. For example, a DFS tree may only have a single back edge,
and there may anywhere from one up to an exponential number of simple cycles in
the graph.

Question No: 34 ( Marks: 2 )


What is the common problem in communications networks and circuit designing?

Common problem in communications networks and circuit design is that of


connecting together a set of nodes by a network of total minimum length. The length
is the sum of lengths of connecting wires.

Question No: 35 ( Marks: 3 )


Let the adjacency list representation of an undirected graph is given below.
Explain what general property of the list indicates that the graph has an isolated
vertex.
abce
bad
cadef
dbcf
eacf
fcde
g

Ans:
A graph is connected if every vertex can reach
Every other vertex. and is isolated if any node has not connected to other vertex
,here’s “g” is the node that is not connected with any other vertex. This general
property of the list indicates that the graph has an isolated vertex.
Algorithm-CS502
QUIZ # 1
Mc090400760
03-11-2010

MC090400760 : Imran Shahzad 35


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 1 of 10 ( Start time: 11:20:20 PM ) Total Marks: 1
The number of nodes in a complete binary tree of height h is

Select correct option:

2^(h+1) – 1

2 * (h+1) – 1

2 * (h+1)

((h+1) ^ 2) – 1

Click here to Save Answer & Move to Next Question

MC090400760 : Imran Shahzad 81


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 2 of 10 ( Start time: 11:21:44 PM ) Total Marks: 1
A heap is a left-complete binary tree that conforms to the ___________
Select correct option:

increasing order only

decreasing order only

heap order

(log n) order

Click here to Save Answer & Move to Next Question

MC090400760 : Imran Shahzad 79


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 3 of 10 ( Start time: 11:22:29 PM ) Total Marks: 1
In which order we can sort?

Select correct option:

increasing order only

decreasing order only

increasing order or decreasing order

both at the same time


Click here to Save Answer & Move to Next Question

MC090400760 : Imran Shahzad 8


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 4 of 10 ( Start time: 11:22:57 PM ) Total Marks: 1
Consider the following Algorithm: Fun(n){ if (n=1) return 1 else return (n * Fun(n-1)) }
Recurrence for the above algorithm is:

Select correct option:

nT(n-1)+1

2T(n-1)+1

T(n-1)+cn

T(n-1)+1

Click here to Save Answer & Move to Next Question

MC090400760 : Imran Shahzad 7


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 5 of 10 ( Start time: 11:24:25 PM ) Total Marks: 1
How much time merge sort takes for an array of numbers?

Select correct option:

T(n^2)
T(n)

T( log n)

T(n log n)

Click here to Save Answer & Move to Next Question

MC090400760 : Imran Shahzad 17


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 6 of 10 ( Start time: 11:25:57 PM ) Total Marks: 1
Sieve Technique can be applied to selection problem?

Select correct option:

True

False

Click here to Save Answer & Move to Next Question

MC090400760 : Imran Shahzad 72


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 7 of 10 ( Start time: 11:27:23 PM ) Total Marks: 1
The reason for introducing Sieve Technique algorithm is that it illustrates a very important
special case of,

Select correct option:

divide-and-conquer
decrease and conquer

greedy nature

2-dimension Maxima

Click here to Save Answer & Move to Next Question

MC090400760 : Imran Shahzad 20


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 8 of 10 ( Start time: 11:27:57 PM ) Total Marks: 1
The analysis of Selection algorithm shows the total running time is indeed ________in n,

Select correct option:

arithmetic

geometric

linear

orthogonal

Click here to Save Answer & Move to Next Question


MC090400760 : Imran Shahzad 42
Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 9 of 10 ( Start time: 11:29:27 PM ) Total Marks: 1
For the Sieve Technique we take time

Select correct option:

T(nk)

T(n / 3)

n^2

n/3

Click here to Save Answer & Move to Next Question

MC090400760 : Imran Shahzad 23


Time
Left sec(
s)
Quiz Start Time: 11:20 PM
Question # 10 of 10 ( Start time: 11:30:44 PM ) Total Marks: 1
How many elements do we eliminate in each time for the Analysis of Selection algorithm?

Select correct option:

n / 2 elements

(n / 2) + n elements
n / 4 elements

2 n elements

Click here to Save Answer & Move to Next Question

Quiz Start Time: 06:18 PM Time Left 55


sec(s)

Question # 1 of 10 ( Start time: 06:18:58 PM ) Total


Marks: 1
We do sorting to,
Select correct option:

keep elements in random positions


keep the algorithm run in linear order
keep the algorithm run in (log n) order
keep elements in increasing or decreasing order

MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 62


sec(s)

Question # 2 of 10 ( Start time: 06:19:38 PM ) Total


Marks: 1
Heaps can be stored in arrays without using any pointers;
this is due to the ____________ nature of the binary tree,
Select correct option:

left-complete
right-complete
tree nodes
tree leaves

MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 77


sec(s)

Question # 3 of 10 ( Start time: 06:20:18 PM ) Total


Marks: 1
Sieve Technique can be applied to selection problem?
Select correct option:

True
False

MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 74


sec(s)

Question # 4 of 10 ( Start time: 06:21:10 PM ) Total


Marks: 1
A heap is a left-complete binary tree that conforms to the
___________
Select correct option:

increasing order only


decreasing order only
heap order
(log n) order
MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 77


sec(s)

Question # 5 of 10 ( Start time: 06:21:39 PM ) Total


Marks: 1
A (an) _________ is a left-complete binary tree that
conforms to the heap order
Select correct option:

heap
binary tree
binary search tree
array

MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 72


sec(s)

Question # 6 of 10 ( Start time: 06:22:04 PM ) Total


Marks: 1
Divide-and-conquer as breaking the problem into a small
number of
Select correct option:

pivot
Sieve
smaller sub problems
Selection
MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 48


sec(s)

Question # 7 of 10 ( Start time: 06:22:40 PM ) Total


Marks: 1
In Sieve Technique we do not know which item is of interest
Select correct option:

True
False

MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 34


sec(s)

Question # 8 of 10 ( Start time: 06:23:26 PM ) Total


Marks: 1
The recurrence relation of Tower of Hanoi is given below
T(n)={1 if n=1 and 2T(n-1) if n >1 In order to move a tower
of 5 rings from one peg to another, how many ring moves are
required?
Select correct option:

16
10
32
31 (yeh just tukka hai)
MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 36


sec(s)

Question # 9 of 10 ( Start time: 06:24:44 PM ) Total


Marks: 1
In the analysis of Selection algorithm, we eliminate a
constant fraction of the array with each phase; we get the
convergent _______________ series in the analysis,
Select correct option:

linear
arithmetic
geometric (yeh b gup hi lugti hai)
exponent

MC090406557 : Nadia Parveen

Quiz Start Time: 06:18 PM Time Left 76


sec(s)

Question # 10 of 10 ( Start time: 06:25:43 PM ) Total


Marks: 1
For the heap sort, access to nodes involves simple
_______________ operations.
Select correct option:

arithmetic
binary
algebraic
logarithmic (bongi hai...)

Question # 1 of 10 ( Start time: 10:02:41 PM ) Total Marks: 1


For the sieve technique we solve the problem,
Select correct option:
recursively
mathematically
precisely
accurately
The sieve technique works in ___________ as follows
Select correct option:
phases
numbers
integers
routines
Slow sorting algorithms run in,
Select correct option:
T(n^2)
T(n)
T( log n)
A (an) _________ is a left-complete binary tree that conforms to the heap order
Select correct option:
heap
binary tree
binary search tree
array

In the analysis of Selection algorithm, we eliminate a constant fraction of the array with
each phase; we get the convergent _______________ series in the analysis,
Select correct option:
linear
arithmetic
geometric
exponent

In the analysis of Selection algorithm, we make a number of passes, in fact it could be as


many as,
Select correct option:
T(n)
T(n / 2)
log n
n/2+n/4

The sieve technique is a special case, where the number of sub problems is just
Select correct option:
5
many
1
few

In which order we can sort?


Select correct option:
increasing order only
decreasing order only
increasing order or decreasing order
both at the same time

The recurrence relation of Tower of Hanoi is given below T(n)={1 if n=1 and 2T(n-1) if
n >1 In order to move a tower of 5 rings from one peg to another, how many ring moves
are required?
Select correct option:
16
10
32
31

Analysis of Selection algorithm ends up with,


Select correct option:
T(n)
T(1 / 1 + n)
T(n / 2)
T((n / 2) + n)

Last message received on 10/13 at 12:43 AM


Khanjee: We do sorting to,
Select correct option:

keep elements in random positions


keep the algorithm run in linear order
keep the algorithm run in (log n) order
keep elements in increasing or decreasing order

Khanjee: Divide-and-conquer as breaking the problem into a small number of


Select correct option:

pivot
Sieve
smaller sub problems
Selection

The analysis of Selection algorithm shows the total running time is indeed ________in n,
Select correct option:
arithmetic
geometric
linear
orthogonal

How many elements do we eliminate in each time for the Analysis of Selection
algorithm?
Select correct option:

n / 2 elements
(n / 2) + n elements
n / 4 elements
2 n elements

Sieve Technique can be applied to selection problem?


Select correct option:

True

For the heap sort we store the tree nodes in


Select correct option:

level-order traversal
in-order traversal
pre-order traversal
post-order traversal

1-One of the clever aspects of heaps is that they can be stored in arrays without
using any _______________.

pointers **

constants
variables

functions

2- For the heap sort we store the tree nodes in

level-order traversal**

in-order traversal

pre-order traversal

post-order traversal

3- The sieve technique works in ___________ as follows

phases

numbers

integers ** not confrm

routines

4- In the analysis of Selection algorithm, we eliminate a constant fraction of the


array with each phase; we get the convergent _______________ series in the
analysis,

linear

arithmetic

geometric **

exponent
5- We do sorting to,

keep elements in random positions

keep the algorithm run in linear order

keep the algorithm run in (log n) order

keep elements in increasing or decreasing order ***

6- 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)***

log n

n/2+n/4

7- In which order we can sort?

increasing order only

decreasing order only

increasing order or decreasing order ***

both at the same time

8- In Sieve Technique we do not know which item is of interest


True**

False

9- For the sieve technique we solve the problem,

recursively**

mathematically

precisely

10- Divide-and-conquer as breaking the problem into a small number of

pivot

Sieve

smaller sub problems **

Selection

Question # 1 of 10 Total Marks: 1


Divide-and-Conquer is as breaking the problem into a small number of
· Smaller Sub Problems
· Pivot
· Sieve
· Solutions
Question # 2 of 10 Total Marks: 1
Analysis of Selection Sort ends up with
· T(n)
· T(1/1+n)
· T(n/2)
· T((n/2) +n)
Question # 3 of 10 Total Marks: 1
How many elements do we eliminate each time for the Analysis of Selection
Algorithm?
· (n / 2)+n Elements
· n / 2 Elements
· n / 4 Elements
· 2 n Elements
Question # 4 of 10 Total Marks: 1
A heap is a left-complete binary tree that conforms to the ?
· Increasing Order
· Decreasing order
· Heap Order
· (nlog n) order
Question # 5 of 10 Total Marks: 1
The Sieve Sequence is a special case where the number of smaller sub
problems is
just_ .
·4
· Many
·1
· Few
Imrangee
Question # 6 of 10 Total Marks: 1
Heaps can be stored in arrays without using any pointers this is due to the of the binary
tree?
· Tree Nodes
· Right-Complete Nature
· Left-Complete Nature
· Tree Leaves
Question # 7 of 10 Total Marks: 1
For the Heap Sort access to nodes involves simple _ operations:
· Geometric
· Linear
· Arithmetic
· Algebraic
Question # 8 of 10 Total Marks: 1
The Analysis of Selection Sort shows that the total running time is indeed in n?
· Geometric
· Linear
· Arithmetic
· Algebraic
Question # 9 of 10 Total Marks: 1
For the sieve technique we solve the problem
· Recursively
· Randomly
· Mathematically
· Precisely
Question # 10 of 10 Total Marks: 1
How much time merger sort takes for an array of numbers?
· T(n^2)
· T(n)
· T(log n)
· T(n log n)
MC090406505 : 86
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 1 of 10 ( Start time: 06:48:26 PM ) Total Marks: 1
How many elements do we eliminate in each time for the Analysis of Selection
algorithm?
Select correct option:

n / 2 elements

(n / 2) + n elements

n / 4 elements

2 n elements

Click here to Save Answ er & Move to Next Question


MC090406505 : 83
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 2 of 10 ( Start time: 06:49:01 PM ) Total Marks: 1
The recurrence relation of Tower of Hanoi is given below T(n)={1 if n=1 and 2T(n-1) if
n >1 In order to move a tower of 5 rings from one peg to another, how many ring moves
are required?
Select correct option:

16

10

32

31

Click here to Save Answ er & Move to Next Question

MC090406505 : 85
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 3 of 10 ( Start time: 06:49:38 PM ) Total Marks: 1
The number of nodes in a complete binary tree of height h is
Select correct option:

2^(h+1) – 1
2 * (h+1) – 1

2 * (h+1)

((h+1) ^ 2) – 1

Click here to Save Answ er & Move to Next Question

MC090406505 87
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 4 of 10 ( Start time: 06:50:58 PM ) Total Marks: 1
One of the clever aspects of heaps is that they can be stored in arrays without using any
_______________.
Select correct option:

pointers

constants

variables

functions

Click here to Save Answ er & Move to Next Question


MC090406505 : 83
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 5 of 10 ( Start time: 06:51:24 PM ) Total Marks: 1
We do sorting to,
Select correct option:

keep elements in random positions

keep the algorithm run in linear order

keep the algorithm run in (log n) order

keep elements in increasing or decreasing order

Click here to Save Answ er & Move to Next Question

MC090406505 : 87
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 6 of 10 ( Start time: 06:52:04 PM ) Total Marks: 1
In Sieve Technique we do not know which item is of interest
Select correct option:

True

False
Click here to Save Answ er & Move to Next Question

MC090406505 : 83
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 7 of 10 ( Start time: 06:52:27 PM ) Total Marks: 1
Consider the following Algorithm: Fun(n){ if (n=1) return 1 else return (n * Fun(n-1)) }
Recurrence for the above algorithm is:
Select correct option:

nT(n-1)+1

2T(n-1)+1

T(n-1)+cn

T(n-1)+1

Click here to Save Answ er & Move to Next Question

MC090406505 : 85
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 8 of 10 ( Start time: 06:53:56 PM ) Total Marks: 1
In the analysis of Selection algorithm, we make a number of passes, in fact it could be as
many as,
Select correct option:

T(n)
T(n / 2)

log n

n/2+n/ 4

Click here to Save Answ er & Move to Next Question

MC090406505 : 84
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 9 of 10 ( Start time: 06:54:25 PM ) Total Marks: 1
The reason for introducing Sieve Technique algorithm is that it illustrates a very
important special case of,
Select correct option:

divide-and-conquer

decrease and conquer

greedy nature

2-dimension Maxima

Click here to Save Answ er & Move to Next Question


MC090406505 : 84
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 9 of 10 ( Start time: 06:54:25 PM ) Total Marks: 1
The reason for introducing Sieve Technique algorithm is that it illustrates a very
important special case of,
Select correct option:

divide-and-conquer

decrease and conquer

greedy nature

2-dimension Maxima

Click here to Save Answ er & Move to Next Question

MC090406505 : 80
Time Left
sec(s)

Quiz Start Time: 06:48 PM


Question # 10 of 10 ( Start time: 06:54:55 PM ) Total Marks: 1
In which order we can sort?
Select correct option:

increasing order only


1 - What type 3.
{ intofSum Correct
n^2= 0; intChoice
instructions
decreasing order only: 1
j;Random 4Access
From Lectuer
Machine#(RAM) 6
10 can execute? Choose best
www.vugujranwala.com
answer 4. n/3
13 - Iffor
26 - Sieve
(j = 0; j Sum++;
algorithm
Technique Aapplies
has running time 7n^2
to problems where + 2nwe + 3 andinterested
algorithm in B has running time item
2n^2,
cout Correct Choice : 1 From Lectuerare # 10 finding a single
then a larger set of _____________
from www.vugujranwala.com
1. Algebraic and logic
2. Geometric and arithmetic increasing order or decreasing order
1. n
Both
itemshave same asymptotic time complexity www.vugujranwala.com www.vugujranwala.com
3. Arithmetic
20 - Sieve and Technique
logic applies to problems where we are interested in finding a single item
2. phases
A is8asymptotically
- Let us say we greater
have an algorithm that carries out N2 operations for an input of size N. Let
4. Parallel
from and recursive
a larger set of _____________
3. pointers
B isus asymptotically
say that a computergreater takes 1 microsecond (1/1000000 second) to carry out one operation.
Correct Choice : 3 From Lectuer # 1
4. constant
None How of long
others does the algorithm run www.vugujranwala.com
for an input of size 3000?
1. n both
itemsat the same time
2 - Random Correct Correct
accessChoice
machine Choice
: 1orFrom : 1is a/an Lectuer
RAMLectuerFrom # 10 #6
2. phases www.vugujranwala.com
www.vugujranwala.com
1. 90 seconds
14 - Sieve
27 What is the 3.solution
Technique cantobe
pointers theapplied
recurrence T(n) = T(n/2)+n
to selection problem?.
1. Machine 2. build
9 seconds
by Al-Khwarizmi
4. constant
2. Mechanical 3. 0.9
machine
seconds Click here to Save Answ er & Move to Next Question
1. TRUE
O(logn) Correct Choice : 1 From Lectuer # 10
3. Electronics 4. 0.09
machineseconds www.vugujranwala.com
2. FALSE
O(n)
4. MathematicalCorrect model Choice : 2 From Lectuer # 4
3. O(nlogn) www.vugujranwala.com
Correct Choice : 4 From Lectuer # 1
4. O(n^2)
9 - -The
22 In Sieve
appropriate
Technique big thita
we do classification
not know which of theitem
www.vugujranwala.com given is function.
of interestf(n) = 4n2 + 97n + 1000 is
3 - _______________ Correct
Correct Choice Choice
is a :graphical : 1
1 From Lectuer From Lectuer
representation # 8
# 10 of an algorithm
www.vugujranwala.com
www.vugujranwala.com
1. FALSE
?(n)
15 - The
28 Howanalysis
much time merge sort
of Selection takes forshows
algorithm an array theof numbers?
total running time is indeed ________in n,
1. Segma Notation
2. TRUE
O(2^n)
2. Thita Notation
3. O(n^2)
1. (n^2)
3. Flowchart 4. O(n^2logn)
2. arithmetic
1. T(n)
4. Asymptotic notationCorrect Choice : 3 2 From Lectuer # 4 10
3. geometric
2. T( log n) www.vugujranwala.com
Correct Choice : 3 From Lectuer # 2
4. linear
3. T(n23 log- n)
10 The the
For appropriate
sieve technique
big ? classification
we solve the ofproblem,
the given function. f(n) = 4n2 + 97n + 1000 is
www.vugujranwala.com

will be the total number of max comparisons if 8


4. orthogonal
4 - What Correct Choice : 2 From Lectuer # we run brute-force maxima
www.vugujranwala.com
1. ?(n)
recursively
algorithm with n elements?
2. mathematically
O(2^n) www.vugujranwala.com

1. n^2 the3.following
17 - Consider O(n^2) Algorithm:
accurately
2. n^n/2
Factorial 4. precisely
(n){ if (n=1) O(n^2logn)
3. n Correct Choice : 1 3 From Lectuer # 10 4
www.vugujranwala.com
4.1n^8
return else return (n *
11 - For
24 Whichthesorting
Sieve Technique
algorithm iswe faster
take time
Correct Choice : 1 From Lectuer # 3
Factorial(n-1))
www.vugujranwala.com

5 - function is given 1. T(nk)


Olike
(n log n) 5n^3+n what is the run time of this
4n^4+
} Recurrence for2. the following
O n^2
T(n / 3) algorithm is:
1. theata(n^4) 3. n^2
O (n+k)
2. theata(n^3) 4. n/3
O n^3
1. T(n) = T(n-1) +1
3. theata(4n^4+Correct 5n^3) Choice : 1 3 From Lectuer # 10 5
2. T(n) = nT(n-1) +1 www.vugujranwala.com
4. theata(4n^4+ 5n^3)
3. T(n)=
12 T(n-1)
25 -- IfHow +n
algorithm
many Aelements
has running
do wetimeeliminate
7n^2 + 2n in +each
3 and timealgorithm
for theBAnalysis
has running
of Selection
time 2n^2,
Correct Choice : 1 From Lectuer # 4
4. T(n)=T(n(n-1))
then
algorithm? +1 www.vugujranwala.com

6 - Consider the followingCorrect Choice : 4 From Lectuer # 9


www.vugujranwala.com
code: For(j=1; j 1. Both
n / 2 elements
have same asymptotic time complexity
18 - For the Sieve Technique we take time www.vugujranwala.com
2. (n
A is/ 2)
asymptotically
+ n elementsgreater
7 - Execution of the following code fragment
3. n
B /is4asymptotically
elements greater
int i =1.N;T(nk)
while. (i > 0)
4. n
None
elements
of others
2. T(n / 3)
56 - In4.Quick
SomeSort 2.Constants
time Correct
numbers
O(n)
stable hidden
& someChoice in: T(n
times 4inFrom
log n)
www.vugujr
place Lectuer
are # 15
44 - In the analysisCorrect of Selection algorithm, we
anwala.commake a number of passes, in fact it could be as
3. O( log n)Choice : 2 From
integers Lectuer # 15 www.vugujranwala.com

many as, 62 - In stable sorting algorithm. www.vugujranwala.com


1. Large 4. O(n routineslog n)
68 - Which may be a stable sort?
2. Medium Correct Choice : 1 From Lectuer # 11 10
1. T(n) 1. If duplicate elements remain in the same relative position after sorting
www.vugujranwala.com
3. Small
T(n50
2. Merger
1. 32
/ 2)- What
A2.(an)
One is_________
the total
array time
is used is atoleft-complete
heapify? binary tree that conforms to the heap order
4. Not Known
3. Insertion
2. log n 3. More than one arrays are required
Correct Choice : 3 From Lectuer # 14
4. Both
3. n / 2 +above
n 4.
1.
/ 4Duplicating
heap n)
?(log elements not www.vugujranwala.com
handled
57 - Is4.itNone
possible
of the
Correct to sort
Correct
2. Choice
binary
?(n
above without
logtree
n) Choicemaking :
: 3 From Lectuer # 111comparisons?
From Lectuer # 15
www.vugujranwala.com
www.vugujranwala.com
3. ?(n^2
binary log search
n) tree
63 - Oneof
45 - In the analysis example
Selection of in place butwe
algorithm, notmake
stable a algorithm
number ofispasses, in fact it could be as
1. Yes 4. ?(log^2n)
array
many as, Correct Choice : 1 From Lectuer # 12 11
2. No
1. Merger Sort www.vugujranwala.com
3.
1. T(n)-When 2. we
Quick callSort
heapify then at each level the comparison performed takes time It will take
4. www.vugujranwala.com
2. T(nO/ 2) 3. Continuation Sort
34(1)
Correct
- ForChoice
the heap : 1sort,
From access
Lectuer to nodes
# 15 involves simple _______________ operations.
3. log n 4. Bubble Sort www.vugujranwala.com

58 - Merge
4. n / 2sort
+ nis/ 4stable
1. TimeCorrectsort,vary
will Choice
but according
not an: 2 in-place
Fromto theLectuer
algorithm
nature#of15input data
1. arithmetic www.vugujranwala.com
Correct 2. It can
Choice not be
: 3 ofFrompredicted
Lectuer # 11
64 - One example
2. binary in place butwww.vugujranwala.com
not stable algorithm is
1. TRUE 3. It will take O (log n)
46 - In which order 3. algebraic
we can sort?
2. FALSE 4. None of the Given
4. Merger
1. logarithmic Sort
3. Correct Choice : 3 From Lectuer #
1. increasing 2. orderCorrect
Quickonly Sort Choice : 1 From Lectuerwww.vugujranwala.com # 1211
4. www.vugujranwala.com
2. decreasing 3. Continuation
order only Sort
Correct Choice : 1 From Lectuer # 15 www.vugujranwala.com
3. increasing 4. order
Bubble orSort
decreasing orderwww.vugujranwala.com www.vugujranwala.com
53 - After Correct
partitioning Choice array in Quick sort, pivot # is15placed in a position such that
59 - In4. both at thesort,
counting same oncetimewe know :the 2 From
ranks, Lectuer
we simply _________ numbers to their final
www.vugujranwala.com
positions in Correct
an-output
37 We65Choice
do array.
- One : 3the
sorting
of From
to,clever Lectuer # 11
1. Values smaller than aspects areofonheaps
pivotwww.vugujranwala.com
left andis that
larger theythancanpivot
be stored
are oninright
arrays without using
Correct Choice : 3 From Lectuer # 10
47 - One ofany the _______________.
2. Values
clever larger
aspects of than
heaps pivot are
is that on left
they canand
www.vugujranwala.com besmaller
stored in than pivotwithout
arrays are on using
right any
1. Delete
29 - The reason3.
_______________. 1.for
keep
Pivot elements
is the firstSieve
introducing in
element
random ofpositions
Technique array algorithm is that it illustrates a very
2. copy
important special1. 2.case
4. keepof,
Pivot
pointers the
is thealgorithm
last elementrun inoflinear
arrayorder
3. Mark
1. pointers 2. 3. constants
keep the algorithm run
Correct Choice : 2 From Lectuer in (log n) order# 13
4. arrange www.vugujranwala.com
1. constants
2. divide-and-conquer
4. variables
3. keep elements in increasing or decreasing order
Correct
54 - TheChoicerunning
Correct : 2
time
From of quick
Lectuersort # depends
15
Lectuer # 11 on the selection of
heavily
2. variables
3. decrease4.and conquerChoice : 1 From
functions www.vugujranwala.com

60 - An3. functions
4. greedy
in placenature
sorting Correct
algorithmChoice is one: 1that uses ___ From arraysLectuer
www.vugujranwala.com
for storage # 15
1. No of inputs www.vugujranwala.com
4. 2-dimension
Correct Maxima
Choice : 1 From Lectuer # 11
66 - Quick sort is
2. Arrangement in array www.vugujranwala.com
of elementswww.vugujranwala.com
1. Two dimensional
Correct Choicearrays : 1 From Lectuer # 10
48 - One of the clever 3. Sizeaspects
o elements of heaps is that they canwww.vugujranwala.com
www.vugujranwala.com be stored in arrays without using any
2. More than one array
4. Stable
1.
30 - The sieve technique
_______________. Pivot element
& in place
works in ___________ as follows
3. No Additional Array www.vugujranwala.com
2. Not stable Choice
Correct but in place : 4 From Lectuer # 13
4. None of the above www.vugujranwala.com
1. pointers
phases 3. Stable but not in place www.vugujranwala.com
Correct
55 - In Quick
Choice
42 - For the4.heap Sort
: 3 Constants
From
sort Lectuer
westable hidden
store the # 15
in T(n
tree nodes log n) are
in place
2. constants
numbers Some time &www.vugujranwala.com
some times in
3. variables
integers
61 - Continuation/counting Correct sortChoice
is suitable: 3 From
to sortLectuer
the elements # 15 in range 1 to k
1. Large www.vugujranwala.com
4. functions
routines 1. level-order traversal
67 - Quick
2. Medium sort is
1. K Correct
is Large 2. Choice
in-order:traversal
1 From Lectuer # 11 10
3. Small www.vugujranwala.com
2. K is not known
3. pre-order traversal
31 - Slow
49 The sievesorting 4.algorithms
1. Not Known
Stable
technique & in
worksrunplace
in
in,___________ as follows
3. K may be4.small post-order
or large traversal
2. Not stable but in place
Correct
4. K is small Correct ChoiceChoice :: 3 1 From
From Lectuer #
# 14
Lectuerwww.vugujranwala.com
11
1. O(n^2)
phases 3. Stable but not in place
www.vugujr
anwala.com
79 - A p x q matrix callsA Correct
can
andbe multiplied
looking
Choicethem: with a q xLectuer
3upFrom
again ifr matrix
we need #B. The result
21them later will be a p x r matrix
www.vugujranwala.com
C. There are (p .3.r) To totalmake
entries
the inprocess
C and accurate
each takes _________ to compute.
85 - Huffman algorithm uses a greedy approach to generate a postfix code T that
4. None of the above
minimizesCorrect the expected
Choice length B (T) Lectuer
: 2 From of the encoded
# 16 string.
1. O (q)
www.vugujranwala.com
2. O (1)
1. TRUE
73 - Dynamic programming algorithms need to store the results of intermediate
3. O (n^2)
2. FALSE
sub-problems.
4. O (n^3)
3.
Correct Choice : 1 From Lectuer # 19
1. TRUE
4. www.vugujranwala.com

80 - For Chain Matrix 2. Correct


Multiplication
FALSE Choice :we
Correct Choice : 1 From 3 From
can not
Lectuer
use
Lectuerdivide
# 15# and
22 conquer approach because,
www.vugujranwala.com www.vugujranwala.com
3.
69 - Which 86 of the
- The following
codeword sorting algorithms
assigned is stable?by the Huffman algorithm have the property that no
to characters
1. We do not 4. know the optimum k
(i) Merge sort,codeword is the postfix of any other.
2. We use divideCorrect and conquer
Choice for: sorting
1 Fromonly Lectuer # 17
(ii) Quick sort, www.vugujranwala.com
3. We can easily perform it in linear time
(iii) Heap sort, 1. TRUEprogramming uses a top-down approach.
74 - Dynamic
4. Size of data is not given
(iv) Counting Sort. 2. FALSE
Correct Choice : 1 From Lectuer # 19
1. TRUE
3. www.vugujranwala.com

1. Only i 4. 2. FALSE
www.vugujranwala.com
2. Only ii 3.
82 - A p x q matrix A Correct Choice : with
can be multiplied 2 Froma q xLectuer
r matrix #B.22The result will be a p x r matrix
www.vugujranwala.com
3. Both i and 4. ii
C. There are 87(p- .Ther) total entries
greedy partin of
C and each takes
the Huffman _________
encoding to compute.
algorithm is to first find two nodes with
4. Both iii and ivCorrect Choice : 2 From Lectuer # 17
larger frequency.
Correct Choice : 1 From Lectuer # 15
www.vugujranwala.com

1. O (q)75 - The edit distance between FOOD and MONEY is


www.vugujranwala.com

70 - Which
2. O (1) of the1.following
TRUE sorting algorithms is stable?
(i) Merge
3. O sort,
(n^2) 2. 1. FALSE
At most four
(ii) Quick
4. Osort,
(n^3) 3. 2. At least four
Correct
(iii) Heap sort, 3. Choice
4. Exact four: 1 From Lectuer # 19
www.vugujranwala.com
(iv) Counting Sort. 4. Wrong
Correctbelongs
Choiceto: 2the From Lectuer # 22
83 - The Knapsack problem domain of _______________
www.vugujranwala.com problems.
Correct Choice : 1 From Lectuer # 17
88 - An optimization problem is one in which you want to find,
www.vugujranwala.com
1. Only i
1. Optimization
76 - The edit distance between FOOD and MONEY is
2. Only ii
2. NP Complete 1. Not a solution
3. Both i and ii
3. Linear Solution
1. An
2. At most
algorithm
four
4. Both iii and iv
4. Sorting 3. 2. Good
At leastsolution
four
Correct Choice : 1 From Lectuer # 15
Correct 3. Choice
4. Exactbest
The : 1solution
four From Lectuer # 21
www.vugujranwala.com

71 - Mergesort is4.aWrong stable algorithm but not an in-place algorithm.


www.vugujranwala.com

84 - Suppose we have three items as shown in the following table, and suppose the
Correct Choice : 1 From Lectuer # 17
capacity of
1. TRUE the knapsack is 50 i.e. W = 50. Item Value Weight 1 60 10 2 100
www.vugujranwala.com

20 3 120 3077The
2. FALSE
- If optimal
there are O (n^2)
solution is entries
to pick in edit distance matrix then the total running time is
3.
1. O (1)
4.
2. O (n^2)
Correct Choice : 1 From Lectuer # 16
3. O (n) www.vugujranwala.com

72 - Memorization
1. Items 1 and 4. is?
O2(n log n)
2. Items 1 and 3Correct Choice : 2 From Lectuer # 18
www.vugujranwala.com
1. Items
3. To store 2 andprevious
3 results for future use
2. None
4. To avoid of these
this unnecessary repetitions by writing down the results of recursive
www.vugujranwala.com
Correct Choice : 4 From Lectuer # 22

También podría gustarte