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

Post on 16-Dec-2015

253 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Exchange Sorts

Lesson Plan - 2: Bubble Sort, Quick Sort

Contents

EvocationObjectiveIntroductionBubble SortBubble Sort AlgorithmQuick SortQuick Sort AlgorithmMind MapSummary

Evocation

Objective

To study the basic knowledge of bubble sort algorithm

To learn about the basic concept of quick sort algorithm

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

Bubble Sort Examples

Bubble Sort Algorithm

Evocation

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

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

Quick Sort Partitions

Quick Sort Algorithm

Hidden picture puzzle Easter

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

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

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

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

top related