Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Q.1) What is the number of swaps required to sort n elements using selection sort, in
the worst case?
e.
co
m
A. Θ(n)
B. Θ(n log n)
C. Θ(n2)
D. Θ(n2 log n)
ANSWER : Θ(n)
SOLUTION :
Note that we are concerned about the swaps, not the comparisons. In the best case,
there is no need for any swap. The best case scenario is when the given list of elements
is already in sorted order. In the worst case, we need (n-1) swaps. For example,
consider the list 10, 5, 6, 7, 8, 9. We need 5 swaps. To conclude, 0 <= (the number of
required swaps) < n
in
Q.2) A machine took 200 sec to sort 200 names, using bubble sort. In 800 sec, it can
approximately sort?
tio
nl
A. 400 names
B. 800 names
C. 750 names
D. 800 names
w
.a
p
A. 50.2 sec
B. 6.7 sec
C. 72.7 sec
D. 11.2 sec
Page 1
e.
co
m
nl
in
ANSWER : Place them in a linked list and sort the linked list
SOLUTION :
Dynamic structure (Memory Allocated at run-time).
We can have more than one datatype.
Re-arrange of linked list is easy (Insertion-Deletion).
It doesn^aEURTMt waste memory.
w
.a
p
A. mnp
B. mp
C. mn
D. np
tio
Q.7) The complexity of multiplying two matrices of order m*n and n*p is
ANSWER : mnp
SOLUTION :
The complexity of multiplying two matrices of order m*n and n*p is mnp
Q.8) Which of the following is not a limitation of binary search algorithm?
Page 2
e.
co
m
nl
in
tio
w
.a
p
Q.12) If a node having two children is deleted from a binary tree, it is replaced by its
A. Inorder predecessor
B. Inorder successor
C. Preorder predecessor
D. None of the above
Page 3
e.
co
m
nl
in
w
.a
p
A. O(1)
B. O(log n)
C. O(n log n)
D. O(n).
tio
ANSWER : O(n).
SOLUTION :
As there it sorts the entries in one loop. Because in nondeterministic sorting algorithms
the abstractions are used which can^aEURTMt be programmed.
A. O (n log n)
B. O (n2/2)
C. O (log n)
D. O (n2/4)
ANSWER : O (n2/2)
SOLUTION :
Each partition gives unbalanced
split. We get T(n) = T(n ¡ 1) + (n) = Θ(n2).
In worst case, Quick Sort as bad as BubbleSort.
The worst-case occurs when the list is already
sorted, and the last element chosen as pivot.
Page 4