Uploaded by Zyad Shokry

ds quiz

advertisement
Egypt Japan University of Science and Technology
CSE 317 – Data Structures
Quiz #2
1. The top row contains an array of 10 integers to be sorted; the bottom row contains the integers
in sorted order; the other rows are the contents of the array at some intermediate step during one
of the three sorting algorithms: Selection-sort, Merge-sort and Quick-sort. Match each row with
the corresponding sorting algorithm you think applied. Use each choice once. Note that you do
not need to apply each sorting algorithm on the array’s numbers. It is sufficient to recognize certain
patterns featured by each row of numbers due to sorting method applied upon.
Original Array
Sorted Array
8
33
77
1
0
0
100
44
9
2
0
0
1
2
8
33
100
44
9
77
0
1
8
33
77
0
100
44
9
2
0
1
0
2
8
77
100
44
9
33
0
0
1
2
8
9
33
44
77
100
2. Given an unsorted array, discuss how to find the minimum difference between any pair in given
array in 𝑂(𝑛 log 𝑛).
3. Consider the queues 𝑄1 containing the elements 1, 2, 3 and 4 where 1 is the head and 𝑄2
containing no elements. The only operations allowed on these two queues are Enqueue (𝑄, element)
and Dequeue (𝑄). Say how to use only Enqueue and Dequeue operations to place the elements of
𝑄1 in 𝑄2 in reverse order (i.e., 𝑄2 contains the elements 4, 3, 2 and 1 where 4 is the head and 𝑄1 is
now empty). Use no extra storage rather than the two queues given.
1
Download