Saturday, October 27, 2007

Insertion Sort Interview Question Part 3


25. What is the output of insertion sort after the 4th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5
a. 3 4 6 8 10 9 7 2 1 5
b. 3 4 6 10 8 9 7 2 1 5
c. 3 4 10 6 8 9 7 2 1 5
d. 3 4 6 8 9 10 7 2 1 5
Ans:a

26. What is the output of insertion sort after the 5th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5
a. 3 4 6 8 10 9 7 2 1 5
b. 3 4 6 10 8 9 7 2 1 5
c. 3 4 6 7 8 9 10 2 1 5
d. 3 4 6 8 9 10 7 2 1 5
Ans:d

27. What is the output of insertion sort after the 6th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5
a. 3 4 6 8 10 9 7 2 1 5
b. 3 4 6 7 8 9 10 2 1 5
c. 3 4 10 6 8 9 7 2 1 5
d. 3 4 6 8 9 10 7 2 1 5
Ans:b

28. What is the output of insertion sort after the 7th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5
A.1 2 3 4 6 7 8 9 10 5
b. 2 3 4 6 7 8 9 10 1 5
c. 3 4 10 6 8 9 7 2 1 5
d. 3 4 6 8 9 10 7 2 1 5
Ans:b

29. What is the output of insertion sort after the 8th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5
A.1 2 3 4 6 7 8 9 10 5
b. 2 3 4 6 7 8 9 10 1 5
c. 1 2 3 4 5 6 7 8 9 10
d. 3 4 6 8 9 10 7 2 1 5
Ans:a

30. Consider the following insertion sort algorithm and the Data set of integers given thereafter:

Setp 1 : initialise marker1 to 1 ( the location of the second element in the list)
Step 2 : while marker1 < L
Setp 3 : if Element[marker1] < Element[marker1- 1 ] , store Element [marker1] in a temporary location temp. Initialise marker2 to marker1 – 1 ( the location just before the marker1)
Step 4 : while Element[marker2] > temp and marker2 >= 0. Shift Element[marker2] to location marker2+1.( this slides the element over to make room to its left). Decrease marker2 by 1
Step 5 : insert temp into the location last vacated by a shift
Setp 6 : increase marker1 by 1.

Data set: 3 9 1 7 2
Note: There are L elements numbered from 0 to L-1 stored in the array.

Which of the following values are not the temp values during the process of sorting?
(a) 1 (b)3 (c)7 (d)2
Ans: b

31. The output of 1st iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is
a. 5 7 0 3 4 2 6 1
b. 0 5 7 3 4 2 6 1

c. 0 3 5 7 4 2 6 1

d. 0 3 4 5 7 2 6 1
Ans:a

32. The output of 2nd iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is
a.5 7 0 3 4 2 6 1
b. 0 5 7 3 4 2 6 1

c. 0 3 5 7 4 2 6 1

d. 0 3 4 5 7 2 6 1
Ans:a

33. The output of 3rd iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is
a.5 7 0 3 4 2 6 1
b. 0 5 7 3 4 2 6 1

c. 0 3 5 7 4 2 6 1

d. 0 3 4 5 7 2 6 1
Ans:b

34. The output of 4th iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is
a.5 7 0 3 4 2 6 1
b. 0 5 7 3 4 2 6 1

c. 0 3 5 7 4 2 6 1

d. 0 3 4 5 7 2 6 1
Ans:c

35. The output of 5th iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is
a.5 7 0 3 4 2 6 1
b. 0 5 7 3 4 2 6 1

c. 0 3 5 7 4 2 6 1

d. 0 3 4 5 7 2 6 1
Ans:d

36. The output of 6th iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is
a.0 2 3 4 5 7 6 1
b. 0 5 7 3 4 2 6 1

c. 0 3 5 7 4 2 6 1

d. 0 3 4 5 7 2 6 1
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