Saturday, October 27, 2007

Bubble Sort Interview Question Part 2


14.When does the best case for Bubble sort occur?
a. When the numbers are placed in random
b. When the numbers are placed in descending order
c. When the numbers are placed in ascending order
d. When all the numbers are same
Ans:c

15.In which cases are the time complexities same in Bubble sort?
a. Worst and Best
b. Best and Average
c. Worst and Average
d. none of the above
Ans:c

16.The sort which works by iterating down an array to be sorted from the first element to the last, comparing each pair of elements and switching their positions if necessary is

a.Merge sort
b.Bubble sort
c.Selection sort
d.none of these
Ans:b

17.The most exchanges that will be necessary for bubble sort for an array of length n is
a.n
b.n+1
c.n-1
d.n*n
Ans:a

18. The best case order for modified bubble sort algorithm is
a.O(n)
b.O(n*n)
c.O(nlogn)
d.O(logn)
Ans:a
A better version of bubble sort, known as modified bubble sort, includes a flag that is set if an exchange is made after an entire pass over the array. If no exchange is made, then it should be clear that the array is already in order because no two elements need to be switched. In that case, the sort should end. The new best case order for this algorithm is O(n), as if the array is already sorted, then no exchanges are made.
19. The frequency count of bubble sort is
a.n*n
b.n(n-1)/2
c.n
d.logn
Ans:b
(n-1)+(n-2)+……+3+2+1=n(n+1)/2 – n =n(n-1)/2

20.In bubble sort,after the 1st iteration, the element which is at the bottom is
a.the smallest
b.the largest
c.the 2nd largest
d.none
Ans:b

21. In bubble sort,after the 2nd iteration, the element which is at the bottom is
a.the smallest
b.the largest
c.the 2nd largest
d.none
Ans:c

22.The number of swappings required to sort the numbers 8,22,7,9,31,19,5,13 in ascending order using bubble sort
a.11 b.12 c.13 d.14
Ans:d

23.Which of the following sort is known as sinking sort?
a.Bubble sort
b.Selection sort
c.Quick sort
d.none
Ans:a

0 comments:

Advertisement

 

Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com