Exchange Sorts Lesson Plan 2 Bubble Sort Quick

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

Contents v Evocation v Objective v Introduction v Bubble Sort Algorithm v Quick Sort Algorithm v Mind Map v Summary

Evocation

Objective Ø To study the basic knowledge of bubble sort algorithm Ø To learn about the basic concept of quick sort algorithm

Introduction-Exchange Sort Ø Exchange the elements that are out of order until the entire list is sorted Bubble Sort Ø List at any movement is divided into two sublists: Sorted and Unsorted Ø Smallest 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 Sort Ø Quick 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 pivot Ø Divide the lists into three groups �Partition of elements whose keys are less than pivots key �Pivot element is placed in correct location in list �Partition of elements greater than or equal to pivots key �Quick sorting left partition followed by sorting right partition

Quick Sort Hoare’s Algorithm �Select pivot key as first element in list Singleton Algorithm �Select 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 element �Start from two ends of array towards middle �Use median value of three elements Ø Before 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 Algorith m Example s Quick Sort Partitions Straight Insertion Module Quick Sort Algorithms Determin e median of three Quick Sort Algorithm

Summary �Exchange 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 key �Pivot element is placed in correct location in list �Partition of elements greater than or equal to pivots key �Quick 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
- Slides: 24