Top Banner
Search and Sort
12

Search and Sort. Binary Search common/mod01/binarySearchAlg.html

Dec 18, 2015

Download

Documents

Duane Logan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Search and Sort

Page 2: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Binary Search

• http://video.franklin.edu/Franklin/Math/170/common/mod01/binarySearchAlg.html

Page 3: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Bubble Sort

• An example on bubble sort. Starting from the beginning of the list,compare every adjacent pair, swap their position if they are not in the right order(the latter one is smaller than the former one). After each iteration, one less element (the last one) is needed to be compared until there is no more element left to be compared.

Page 4: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Insertion Sort

• An example on insertion sort. Check each element and put them in the right order in the sorted list.

Page 5: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Quick Sort

• Divide and Conquer!!

Page 6: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Quick Sort

Page 7: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

2d Arrays78 0 0 9 98

1 2 h nips 213

5 6 4 d 13

jop 5 kol 2

moose silla gobi 45 32

Page 8: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Sort Comparisons

• http://www.sorting-algorithms.com/bubble-sort

• http://www.sorting-algorithms.com/

Page 9: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Bubble Vs Quick

• When is quick sort quicker than bubble sort

• When is bubble sort quicker than quick sort

• Which is generally quicker?

Page 10: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Describe Sort

• Describe how Bubble sort works• Describe how quick sort works as best you can

Page 11: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Question 14A procedure is required that can sort a list of randomly arranged items. This list can be of any given size. Two separate procedures are written, one using a quick sort algorithm and the other using a bubble sort algorithm. The performance of each procedure is compared by measuring the time it takes to sort an increasing number of list items. The results are shown below.

The graph line that most likely represents the performance of the bubble sort isA.  neither (1) nor (5) because a bubble sort cannot sort very large lists.B.  (2) because a bubble sort generally takes less time than a quick sort.C.  (1) because a bubble sort generally takes more time than a quick sort.D.  neither (1) nor (2) because the time taken for a bubble sort does not depend on the list size.

Page 12: Search and Sort. Binary Search  common/mod01/binarySearchAlg.html

Binary Sort

• What is one prerequisite required to use a binary sort

• What philosophy does the binary sort work on?