Here are some great Sorting questions which will help u in your interviews

1 .In a selectionsort of n elements, how many times is the swap function called in the complete execution of the algorithm?

A. 1

B. n - 1

C. n log n

D. n^2.

Solution: B. n-1

2 .Selectionsort and quicksort both fall into the same category of sorting algorithms. What is this category?

* A. O(n log n) sorts

* B. Divide-and-conquer sorts

* C. Interchange sorts

* D. Average time is quadratic.

Solution: C.Interchange sorts reason:Selection sort is not O(n log n) and not a Divide-conquer sort too and Average time of quicksort is not quadratic.

3 . Suppose that a selectionsort of 100 items has completed 42 iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved again)?

* A. 21

* B. 41

* C. 42

* D. 43

Solution: C. 42

4 .Suppose we are sorting an array of ten integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here:

1 2 3 4 5 0 6 7 8 9

Which statement is correct? (Note: Our selection sort picks largest items first.)

* A. The algorithm might be either selection sort or insertion sort.

* B. The algorithm might be selectionsort, but could not be insertionsort.

* C. The algorithm might be insertionsort, but could not be selectionsort.

* D. The algorithm is neither selectionsort nor insertionsort.

Solution: C. The algorithm might be insertion sort, but could not be selection sort.

5 .Suppose we are sorting an array of eight integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here:

2 4 5 7 8 1 3 6

Which statement is correct? (Note: Our selectionsort picks largest items first.)

* A. The algorithm might be either selectionsort or insertionsort.

* B. The algorithm might be selectionsort, but it is not insertionsort.

* C. The algorithm is not selectionsort, but it might be insertionsort.

* D. The algorithm is neither selectionsort nor insertionsort.

Solution: C. The algorithm is not selectionsort, but it might be insertionsort.

6 .When is insertionsort a good choice for sorting an array?

* A. Each component of the array requires a large amount of memory.

* B. Each component of the array requires a small amount of memory.

* C. The array has only a few items out of place.

* D. The processor speed is fast.

Solution: C. The array has only a few items out of place.

7 What is the worst-case time for mergesort to sort an array of n elements?

* A. O(log n)

* B. O(n)

* C. O(n log n)

* D. O(n^2)

Solution : C. O(n log n)

8 What is the worst-case time for quicksort to sort an array of n elements?

* A. O(log n)

* B. O(n)

* C. O(n log n)

* D. O(n^2)

Solution: D. O(n^2)

9 .Mergesort makes two recursive calls. Which statement is true after these recursive calls finish, but before the merge step?

* A. The array elements form a heap.

* B. Elements in each half of the array are sorted amongst themselves.

* C. Elements in the first half of the array are less than or equal to elements in the second half of the array.

* D. None of the above.

Solution: B. Elements in each half of the array are sorted amongst themselves.

10 .Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the array looking like this:

2 5 1 7 9 12 11 10

Which statement is correct?

* A. The pivot could be either the 7 or the 9.

* B. The pivot could be the 7, but it is not the 9.

* C. The pivot is not the 7, but it could be the 9.

* D. Neither the 7 nor the 9 is the pivot.

Solution: A. The pivot could be either the 7 or the 9.

For More Such Sorting aptitude Questions see this WEBSITE

1 .In a selectionsort of n elements, how many times is the swap function called in the complete execution of the algorithm?

A. 1

B. n - 1

C. n log n

D. n^2.

Solution: B. n-1

2 .Selectionsort and quicksort both fall into the same category of sorting algorithms. What is this category?

* A. O(n log n) sorts

* B. Divide-and-conquer sorts

* C. Interchange sorts

* D. Average time is quadratic.

Solution: C.Interchange sorts reason:Selection sort is not O(n log n) and not a Divide-conquer sort too and Average time of quicksort is not quadratic.

3 . Suppose that a selectionsort of 100 items has completed 42 iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved again)?

* A. 21

* B. 41

* C. 42

* D. 43

Solution: C. 42

4 .Suppose we are sorting an array of ten integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here:

1 2 3 4 5 0 6 7 8 9

Which statement is correct? (Note: Our selection sort picks largest items first.)

* A. The algorithm might be either selection sort or insertion sort.

* B. The algorithm might be selectionsort, but could not be insertionsort.

* C. The algorithm might be insertionsort, but could not be selectionsort.

* D. The algorithm is neither selectionsort nor insertionsort.

Solution: C. The algorithm might be insertion sort, but could not be selection sort.

5 .Suppose we are sorting an array of eight integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here:

2 4 5 7 8 1 3 6

Which statement is correct? (Note: Our selectionsort picks largest items first.)

* A. The algorithm might be either selectionsort or insertionsort.

* B. The algorithm might be selectionsort, but it is not insertionsort.

* C. The algorithm is not selectionsort, but it might be insertionsort.

* D. The algorithm is neither selectionsort nor insertionsort.

Solution: C. The algorithm is not selectionsort, but it might be insertionsort.

6 .When is insertionsort a good choice for sorting an array?

* A. Each component of the array requires a large amount of memory.

* B. Each component of the array requires a small amount of memory.

* C. The array has only a few items out of place.

* D. The processor speed is fast.

Solution: C. The array has only a few items out of place.

7 What is the worst-case time for mergesort to sort an array of n elements?

* A. O(log n)

* B. O(n)

* C. O(n log n)

* D. O(n^2)

Solution : C. O(n log n)

8 What is the worst-case time for quicksort to sort an array of n elements?

* A. O(log n)

* B. O(n)

* C. O(n log n)

* D. O(n^2)

Solution: D. O(n^2)

9 .Mergesort makes two recursive calls. Which statement is true after these recursive calls finish, but before the merge step?

* A. The array elements form a heap.

* B. Elements in each half of the array are sorted amongst themselves.

* C. Elements in the first half of the array are less than or equal to elements in the second half of the array.

* D. None of the above.

Solution: B. Elements in each half of the array are sorted amongst themselves.

10 .Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the array looking like this:

2 5 1 7 9 12 11 10

Which statement is correct?

* A. The pivot could be either the 7 or the 9.

* B. The pivot could be the 7, but it is not the 9.

* C. The pivot is not the 7, but it could be the 9.

* D. Neither the 7 nor the 9 is the pivot.

Solution: A. The pivot could be either the 7 or the 9.

For More Such Sorting aptitude Questions see this WEBSITE

Remember a lotta these questions with detailed explanation can be foundAt this Website

## No comments:

Post a Comment