lesson plan - 2: bubble sort, quick sort. contents evocation objective introduction bubble sort ...

24
Exchange Sorts Lesson Plan - 2: Bubble Sort, Quick Sort

Upload: annice-burke

Post on 16-Dec-2015

266 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Exchange Sorts

Lesson Plan - 2: Bubble Sort, Quick Sort

Page 2: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Contents

EvocationObjectiveIntroductionBubble SortBubble Sort AlgorithmQuick SortQuick Sort AlgorithmMind MapSummary

Page 3: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Evocation

Page 4: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Objective

To study the basic knowledge of bubble sort algorithm

To learn about the basic concept of quick sort algorithm

Page 5: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Introduction-Exchange SortExchange the elements that are out of order until the entire list

is sorted

Bubble SortList at any movement is divided into two sublists: Sorted and

UnsortedSmallest element is bubbled from unsorted sublist and moved

to sorted sublist

Given a list of n elements, bubble sort requires n-1 passes to sort data

Page 6: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Bubble Sort Examples

Page 7: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Bubble Sort Algorithm

Page 8: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Evocation

Page 9: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Quick SortQuick sort is an exchange sort in which a pivot key is placed in

its correct position in the array while rearranging other elements widely discussed across the list

Each iteration of quick sort selects an element known as pivotDivide the lists into three groups Partition of elements whose keys are less than pivots keyPivot element is placed in correct location in listPartition of elements greater than or equal to pivots keyQuick sorting left partition followed by sorting right partition

Page 10: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Quick SortHoare’s AlgorithmSelect pivot key as first element in list

Singleton AlgorithmSelect pivot key as median value of three elements left, right

and element in middle of list

Once median value is determined it is exchanged with left element

Page 11: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Quick Sort Partitions

Page 12: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Quick Sort Algorithm

Page 13: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort
Page 14: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort
Page 15: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort
Page 16: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort
Page 17: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort
Page 18: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort
Page 19: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort
Page 20: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Hidden picture puzzle Easter

Page 21: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Quick Sort Algorithm

To determine correct position of pivot elementStart from two ends of array towards middleUse median value of three elementsBefore exchange starts, median element in middle position and

smallest of three element used to determine median in right location

After median left algorithm, median is in left position and smallest in middle location

Pivot key is moved to hold area to facilitate processing

Page 22: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Mind Map

Exchange Sort

Bubble Sort

Quick Sort

Algorithm

Examples

Quick SortPartitions

Quick SortAlgorithms

Straight Insertio

n Module

Determine

median of three

Quick Sort

Algorithm

Page 23: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

SummaryExchange sort systematically exchange elements that are out of

order until list is sorted

Two methods of exchange sorts are bubble sort and quick sort

In bubble sort, list at any movement is divided into two sublists: Sorted and Unsorted

In each pass the smallest element is bubbled from unsorted sublist and moved to sorted sublist

In quick sort, list is continuously divided into smaller sublists and exchanging takes place between elements that are out of order

Page 24: Lesson Plan - 2: Bubble Sort, Quick Sort. Contents  Evocation  Objective  Introduction  Bubble Sort  Bubble Sort Algorithm  Quick Sort  Quick Sort

Summary

Each pass of quick sort selects a pivot and divides the list into three groups

Partition of elements whose key is less than pivots keyPivot element is placed in correct location in listPartition of elements greater than or equal to pivots keyQuick sorting left partition followed by sorting right partition Quick sort algorithm is mainly based on three steps straight

insertion module, determine median of three and quick sort