Вы находитесь на странице: 1из 2

Principles of Computer Science

Sorting and Searching Algorithms


Lab 9
Sort # 1
Fill an array with data
For N times
For all N items in the array
Compare two adjacent elements
If the two are out of sequence, SWAP
1. This is a Bubble sort.
2. Using Big O notation, what is the Big O for this sort?
O(n2)
3. Suppose your data arrived in sorted order. How could you modify the above
pseudocode to make it more efficient? Hint: Lay out playing cards and run
through this sort and you should see the answer!
Dont raise to 2
Sort # 2
Fill an array with data
Find the smallest item in the array
SWAP element [0] and the smallest item found
Find the 2nd smallest item in the array
SWAP element [1] and the 2nd smallest item found
Find the 3rd smallest item in the array
SWAP element [2] and the 3rd smallest item found
Continue for all items in the array...
4. This is a Merge sort.
5. Using Big O notation, what is the Big O for this sort?
O(n log n)
6. Would a binary search work with unsorted data? Briefly explain your answer.
7. Using a Bubble Sort, show the result of the first pass using the data below. Be sure
you clearly show your swaps, and show only the first pass.
7

8. Using a binary search, how many probes into the data would be necessary to search
2048 items?
9. T F An Insertion Sort is more efficient than a Merge Sort.
10. Show the merge of the data sets A and B below:
Set A:

11 16

Set B: 0

Merged Set Contains: ______________________________

Вам также может понравиться