Placement Questions: Searching
Placement Questions: Searching
Searching:
Ans:c
Ans:a
3. Average case time complexity of Sequential searchis
a. O(1)
b. O(n)
c. O(n×n)
d. None ofthese.
Ans:b
4. Worst case time complexity of Sequential searchis
a. O(1)
b. O(n)
c. O(n×n)
d. None ofthese.
Ans:b
5. Best case time complexity of linear searchis
a. O(1)
b. O(n)
34
c. O(n×n)
d. None ofthese.
Ans:a
6. Average case time complexity of linear searchis
a. O(1)
b. O(n)
c. O(n×n)
d. None ofthese.
Ans:b
7. Worst case time complexity of Linear searchis
a. O(1)
b. O(n)
c. O(n×n)
d. None ofthese.
Ans:b
8. Efficiency is usually measured in terms of abstract computations,such as data moves and
the memory used. True.
9. Binary search is a more specialized algorithm than sequential search as it takes advantage
of data that hasbeen
a. Sorted
b. NotSorted
c. random
d. none of theabove
Ans:a
10. The underlying idea of binary search is to divide the sorted data into two halves and to
examine the data at the point of the split.True.
35
Ans:a
12. A search algorithm is an algorithm that accepts an argument a and tries to find a record in
the file with the primary key as a.True.
17. For finding the middle element in a binary search to avoid overflows the formula usedis
Ans. mid = low + (high-low)/2
Sorting:
1. Which of the following is not a stable sortingalgorithm?
a) Insertionsort
b) Selectionsort
c) Bubblesort
d) Mergesort
36
Ans. B
2. Which of the following is a stable sortingalgorithm?
a) Mergesort
b) Typical in-place quicksort
c) Heapsort
d) Selectionsort
Ans: A
3. Which of the following is not an in-place sortingalgorithm?
a) Selectionsort
b) Heapsort
c) Quicksort
d) Mergesort
Ans: D
4. Running merge sort on an array of size n which is already sortedis
a) O(n)
b) O(nlogn)
c) O(n2)
d) None
Ans: B
5. Thetimecomplexityofaquicksortalgorithmwhichmakesuseofmedian,foundbyan
O(n) algorithm, as pivot elementis
a) O(n2)
b) O(nlogn)
c) O(nloglogn)
d) O(n)
Ans: B
6. Which of the following is not a noncomparisonsort?
a) Countingsort
b) Bucketsort
c) Radixsort
d) Shellsort
37
Ans: D
7. The time complexity of heap sort in worst caseis
a) O(logn)
b) O(n)
c) O(nlogn)
d) O(n2)
Ans: C
8. Ifthegiveninputarrayissortedornearlysorted,whichofthefollowingalgorithmgivestheb
est performance?
a) Insertionsort
b) Selectionsort
c) Quicksort
d) Mergesort
Ans: A
9. Which of the following algorithm pays the least attention to the ordering of the elements
in theinput list?
a) Insertionsort
b) Selectionsort
c) Quicksort
d) None
Ans: B
10. Which of the following algorithms has lowest worst case timecomplexity?
a) Insertionsort
b) Selectionsort
c) Quicksort
d) Heapsort
Ans: D
38