Saturday, October 27, 2007

Bubble Sort Interview Question Part 1


1.What is the output of bubble sort after the 1st iteration given the following sequence of numbers: 13 2 9 4 18 45 37 63
a.2 4 9 13 18 37 45 63
b.2 9 4 13 18 37 45 63
c.13 2 4 9 18 45 37 63
d.2 4 9 13 18 45 37 63
Ans:b


2.What is the worst case complexity for bubble sort algorithm
a.O(n) b.O(n*n) c.O(nlogn) d.O(logn)
Ans:b

3.What is the average case complexity for bubble sort algorithm
a.O(n) b.O(n*n) c.O(nlogn) d.O(logn)
Ans:b

4.What is the best case complexity for bubble sort algorithm
a.O(n) b.O(n*n) c.O(nlogn) d.O(logn)
Ans:a

5.The following loop is used for
For i<- N-1 to 1
For j<- 1 to i
If(a(j)>a(j+1))
{
Temp=a(j);
A(j)=a(j+1);
A(j+1)=temp;
}
a.bubble sort b.selection sort c.insertion sort d.merge sort
Ans:a

6. What is the output of bubble sort after the 1st iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33
a. 48 25 37 12 57 86 33 92
b. 25 48 12 37 57 86 33 92
c.25 48 37 12 57 86 33 92
d. 25 48 37 12 57 33 86 92
Ans:c

7.What is the output of bubble sort after the 2nd iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33
a. 48 25 37 12 57 86 33 92
b. 25 48 12 37 57 86 33 92
c.25 48 37 12 57 86 33 92
d. 25 37 12 48 57 33 86 92
Ans:d

8.What is the output of bubble sort after the 3rd iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33
a. 48 25 37 12 57 86 33 92
b. 25 12 37 48 33 57 86 92
c.25 48 37 12 57 86 33 92
d. 25 37 12 48 57 33 86 92
Ans:b

9.What is the output of bubble sort after the 4th iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33
a. 48 25 37 12 57 86 33 92
b. 25 48 12 37 57 86 33 92
c.25 48 37 12 57 86 33 92
d. 12 25 37 33 48 57 86 92
Ans:d

10.What is the output of bubble sort after the 5th iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33
a. 12 25 33 37 48 57 86 92
b. 25 48 12 37 57 86 33 92
c.25 48 37 12 57 86 33 92
d. 25 37 12 48 57 33 86 92
Ans:a

11.What is the output of bubble sort after the 6th iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33
a. 48 25 37 12 57 86 33 92
b. 25 48 12 37 57 86 33 92
c.12 25 33 37 48 57 86 92
d. 25 37 12 48 57 33 86 92
Ans:c

12.What is the output of bubble sort after the 7th iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33
a. 48 25 37 12 57 86 33 92
b. 12 25 33 37 48 57 86 92
c.12 25 37 33 48 57 86 92
d. 25 37 12 48 57 33 86 92
Ans:b

13.When does the worst 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:b

0 comments:

Advertisement

 

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