UNITIII SORTING Lesson Plan1 Insertion Sort Selection Sort

  • Slides: 24
Download presentation
UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Contents v Evocation v Objective v Introduction-Sorting v Sort Classifications v Sort v Insertion

Contents v Evocation v Objective v Introduction-Sorting v Sort Classifications v Sort v Insertion Sort v Selection Sort v Mind map v Summary

ANNEXURE-I Evocation

ANNEXURE-I Evocation

Objective ØTo study the basic concept of sorting techniques ØTo discuss about the insertion

Objective ØTo study the basic concept of sorting techniques ØTo discuss about the insertion sort and selection sort algorithm with examples

ANNEXURE-II Introduction-Sorting Ø A sorting algorithm is an algorithm that puts elements of a

ANNEXURE-II Introduction-Sorting Ø A sorting algorithm is an algorithm that puts elements of a list in a certain order Ø Consider list x 1, x 2, x 3, … xn Ø We seek to arrange the elements of the list in order • Ascending or descending • For example, to arrange the elements in ascending order Start 1 23 2 56 9 8 100 End 1 2 8 9 10 23 56 100 Ø Some O(n 2) schemes • Easy to understand implement • Inefficient for large data sets

Sort Classifications Sort External Internal Selection Exchange Insertion Selection Bubble Shell Heap Quick Insertion

Sort Classifications Sort External Internal Selection Exchange Insertion Selection Bubble Shell Heap Quick Insertion Natural Balanced Polyphase

Sort Internal Sort • Data are held in primary memory during sorting process External

Sort Internal Sort • Data are held in primary memory during sorting process External Sort • Use primary memory for data currently being sorted Sort Order • Data sorted in ascending or descending sequence • Identifies sequence of sorted data, ascending or descending Example • Ascending sequence - Dictionary, telephone book • Descending sequence - Percentage of games won in sporting event such as base ball

Sort Stability • Attribute of sort indicating data with equal keys maintain relative input

Sort Stability • Attribute of sort indicating data with equal keys maintain relative input order in output Unsorted data Stable sort Unstable sort 365 blue 212 green 876 white 212 yellow 119 purple 737 green 212 blue 443 red 567 yellow 119 purple 212 green 212 yellow 212 blue 365 blue 443 red 567 yellow 737 green 876 white 119 purple 212 blue 212 green 212 yellow 365 blue 443 red 567 yellow 737 green 876 white

Sort Efficiency • Measure of relative efficiency of sort • Estimate of number of

Sort Efficiency • Measure of relative efficiency of sort • Estimate of number of comparisons and moves required to order unordered list Passes • During sorting, data traversed many times • Each traversal of data is referred to as sort pass • Sort pass traverse whole list or section of list

Evocation

Evocation

Insertion Sort Ø In each pass of insertion sort, one or more pieces of

Insertion Sort Ø In each pass of insertion sort, one or more pieces of data are inserted into correct location in ordered list Ø Most common sort technique used by card players Ø Pick up each card, then insert into proper sequence in hand Ø Repeatedly insert a new element into an already sorted list

Ø List is divided into two parts: Sorted and Unsorted Ø In each pass

Ø List is divided into two parts: Sorted and Unsorted Ø In each pass the first element of unsorted sublist is transferred to sorted sublist by inserting at appropriate place Ø If list contains n elements, it will take n-1 passes to sort data

Insertion Sort Example

Insertion Sort Example

Contd. ,

Contd. ,

ANNEXURE-III Progressive Muscular Relaxation Forehead • Wrinkle your forehead and arch your eyebrows •

ANNEXURE-III Progressive Muscular Relaxation Forehead • Wrinkle your forehead and arch your eyebrows • Hold; then relax Eyes • Close your eyes tightly. • Hold; then relax Nose • Wrinkle your nose and flare your nostrils. • Hold; then relax Tongue • Push your tongue firmly against the roof of your mouth • Hold; then relax

Optical Illusion What do you see in the image below?

Optical Illusion What do you see in the image below?

Logo Identification

Logo Identification

Abbreviation • AIAA • BAE • BNSC • A&A

Abbreviation • AIAA • BAE • BNSC • A&A

Evocation

Evocation

Selection Sort Ø List is divided into two sublists, sorted and unsorted which are

Selection Sort Ø List is divided into two sublists, sorted and unsorted which are divided by imaginary wall Ø In each pass, the smallest element is selected from unsorted sublist and exchanged with element at beginning of unsorted sublist ØMake passes through a list ØOn each pass reposition correctly some element

Selection Sort Example

Selection Sort Example

ANNEXURE-IV Mind Map Sorting Classification Algorithm Example Insertion Sort Program Selection Sort Algorithm Example

ANNEXURE-IV Mind Map Sorting Classification Algorithm Example Insertion Sort Program Selection Sort Algorithm Example Program

ANNEXURE-V Summary • Sorting is one of the most common data processing applications •

ANNEXURE-V Summary • Sorting is one of the most common data processing applications • Sorting algorithms are classified as either internal or external • Data may be sorted in ascending or descending order • Sort stability is an attribute of sort indicating data with equal keys maintain relative input order in output • Sort efficiency is a measure of relative efficiency of sort • Each traversal of data during sorting process is referred to as pass

Summary • In Straight insertion sort, list is divided into two sublists: Sorted and

Summary • In Straight insertion sort, list is divided into two sublists: Sorted and Unsorted • In each pass the first element of unsorted sublist is transferred to sorted sublist by inserting at appropriate place • In Straight selection sort the list is divided into two sublists, sorted and unsorted • In each pass, the process selects the smallest element from unsorted sublist and exchanged with element at beginning of unsorted sublist