Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

ALGORITHMS

(Practice Session – 3)
SATYA NARAYANA KAITEPALLI (SNK)

❖ B.Tech, M.Tech, (Ph.D.)


❖ 13+ Years of Experience
❖ CS Senior Faculty
❖ Mentored 20000+ Students
❖ GATE Qualified
❖ SET Qualified
❖ CISCO Certified
❖ Areas Of Expertise : COA, CN, OS, DS, ALGORITHMS
Practice Session 3 – ALGORITHMS
Surveying

For parameters a and b, both of which are ω(1), T(n)=T(n1/a)+1, and


Question No. 41 T(b)=1. Then T(n) is

(A) Θ(logalogbn)
(B) Θ(logabn)
(C) Θ(logblogan)
(D) Θ(log2log2n)
Practice Session 3 – ALGORITHMS
Surveying
Practice Session 3 – ALGORITHMS
Surveying

Which one of the following is the tightest upper bound that


Question No. 42 represents the number of swaps required to sort n numbers
using selection sort?

(A) O(log n)
(B) O(n)
(C) O(nlogn)
(D) O(n2)
Practice Session 3 – ALGORITHMS
Surveying

Which one of the following is the tightest upper bound that


Question No. 43
represents the time complexity of inserting an object into a binary
search tree of n nodes?
(A) O(1)
(B) O(logn)
(C) O(n)
(D) O(nlogn)
Practice Session 3 – ALGORITHMS
Surveying

What is the time complexity of Bellman-Ford single-source


Question No. 44
shortest path algorithm on a complete graph of n vertices?

(A) O(n2)
(B) O(n3)
(C) O(n2logn)
(D) O(n3logn)
Practice Session 3 – ALGORITHMS
Surveying

The worst case running time to search for an element in a


Question No. 45
balanced binary search tree with n2n elements is
(A)θ(n log n)
(B) θ(n2n)
(C θ(n)
(D θ(log n)
Practice Session 3 – ALGORITHMS
Surveying

Let W(n) and A(n) denote respectively, the worst case and
Question No. 46
average case running time of an algorithm executed on an input
of size n. which of the following is ALWAYS TRUE?

(A) A(n) = Ω(W(n))


(B) A(n) =θ(W(n))
(C) A(n) = O(W(n))
(D) A(n) = o(W(n))
Practice Session 3 – ALGORITHMS
Surveying

Two alternative packages A and B are available for processing a


Question No. 47
database having 10k records. Package A requires 0.0001n2 time
units and package B requires 10nlog10n time units to process n
records. What is the smallest value of k for which package B will
be preferred over A?
(A) 12
(B) 10
(C) 6
(D) 5
Practice Session 3 – ALGORITHMS
Surveying
Practice Session 3 – ALGORITHMS
Surveying

Consider the following segment of C-code:


Question No. 48
int j, n;
j = 1;
while (j <= n)
j = j * 2;
The number of comparisons made in the execution of the loop
for any n>0 is:

A. log2n-1
B. n
C. log2n
D. log2n+1
Practice Session 3 – ALGORITHMS
Surveying

Question No. 49 Consider the following C-program fragment in which i, j and n


are integer variables.
for (i = n, j = 0; i >0; i /= 2, j += i);
Let val(j) denote the value stored in the variable j after
termination of the for loop. Which one of the following is true?

(A) val(j) = θ(logn)


(B) vaI(j) = θ(√n)
(C) val(j) = θ(n)
(D) val(j) = θ nlogn)
Practice Session 3 – ALGORITHMS
Surveying

The number of possible min-heaps containing each value from


Question No. 50
{1,2,3,4,5,6,7} exactly once is _______

A. 72 B. 35 C. 70 D. 80
Practice Session 3 – ALGORITHMS
Surveying

Assume that a merge sort algorithm in the worst case takes 30


Question No. 51 seconds for an input of size 64. Which of the following most
closely approximates the maximum input size of a problem that
can be solved in 6 minutes?

(A) 256
(B) 512
(C) 1024
(D) 2048
Practice Session 3 – ALGORITHMS
Surveying

Match the following


Question No. 52

List-I
A. Prim’s algorithm for minimum spanning tree
B. Floyd-Warshall algorithm for all pairs shortest paths
C. Merge sort
Codes:
D. Hamiltonian circuit
ABCD
List-II
(a) 3 2 4 1
1. Backtracking
(b) 1 2 4 3
2. Greed method
(c) 2 3 4 1
3. Dynamic programming
(d) 2 1 3 4
4. Divide and conquer
Practice Session 3 – ALGORITHMS
Surveying

Let G be a weighted connected undirected graph with distinct positive edge

Question No. 53 weights. If every edge weight is increased by the same value, then which of
the following statements is/are TRUE?

P: Minimum spanning tree of G does not change


Q: Shortest path between any pair of vertices does not change

(A) P only
(B) Q only
(C) Neither P nor Q
(D) Both P and Q
Practice Session 3 – ALGORITHMS
Surveying

Consider the following statements:


Question No. 54 I. The smallest element in a max-heap is always at a leaf node.
II. The second largest element in a max-heap is always a child of
the root node.
III. A max-heap can be constructed from a binary search tree in
Θ(n) time.
IV. A binary search tree can be constructed from a max-heap in
Θ(n) time.
Which of the above statements is/are TRUE?
(A) II, III and IV
(B) I, II and III
(C) I, III and IV
(D) I, II and IV
Practice Session 3 – ALGORITHMS
Surveying

The running time of an algorithm is represented by the following


Question No. 55 recurrence relation:

if n <= 3 then T(n) = n


else T(n) = T(n/3) + cn

Which one of the following represents the time complexity of the


algorithm?

A. Θ(n)
B. Θ(nlogn)
C. Θ(n2)
D. Θ(n2logn)
Practice Session 3 – ALGORITHMS
Surveying

Which of the given options provides the increasing order of


asymptotic complexity of functions f1, f2, f3 and f4?
Question No. 56
f1(n) = 2n
f2(n) = n3/2
f3(n) = nlogn
f4(n) = nlogn

(A) f3, f2, f4, f1


(B) f3, f2, f1, f4
(C) f2, f3, f1, f4
(D) f2, f3, f4, f1
Practice Session 3 – ALGORITHMS
Surveying

Consider the following functions:


Question No. 57
f(n) = 2n
g(n) = n!
h(n) = nlogn

Which of the following statements about the asymptotic behaviour


of f(n), g(n), and h(n) is true?

(A) f(n) = O(g(n)); g(n) = O(h(n))


(B) f(n) = Ω(g(n)); g(n) = O(h(n))
(C) g(n) = O(f(n)); h(n) = O(f(n))
(D) h(n) = O(f(n)); g(n) = Ω(f(n))
Practice Session 3 – ALGORITHMS
Surveying

Assume that the algorithms considered here sort the input


Question No. 58 sequences in ascending order. If the input is already in ascending
order, which of the following are TRUE ?

I. Quicksort runs in Θ(n2) time


II. Bubble sort runs in Θ(n2) time
III. Merge sort runs in Θ(n) time
IV. Insertion sort runs in Θ(n) time

(A) I and II only


(B) I and III only
(C) II and IV only
(D) I and IV only
Practice Session 3 – ALGORITHMS
Surveying

The worst case running times of Insertion sort, Merge sort and
Question No. 59 Quick sort, respectively, are:

(A) Θ(n log n), Θ(n log n) and Θ(n2)

(B) Θ(n2), Θ(n2) and Θ(n Log n)

(C) Θ(n2), Θ(n log n) and Θ(n log n)

(D) Θ(n2), Θ(n log n) and Θ(n2)


Practice Session 3 – ALGORITHMS
Surveying

An unordered list contains n distinct elements. The number of


Question No. 60 comparisons to find an element in this list that is neither
maximum nor minimum is

(A) Θ(nlogn)
(B) Θ(n)
(C) Θ(logn)
(D) Θ(1)
Practice Session
Quick3Sort
– ALGORITHMS
Surveying

Next Class
COMPUTER NETWORKS
(Practice Session - 1)

You might also like