unit-iii sorting lesson plan-1 insertion sort, selection sort

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

Upload: abraham-porter

Post on 17-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

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

UNIT-IIISORTING

Lesson Plan-1

Insertion Sort, Selection Sort

Page 2: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Contents

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

Page 3: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

ANNEXURE-IEvocation

Page 4: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Objective

To study the basic concept of sorting techniques

To discuss about the insertion sort and selection sort algorithm with examples

Page 5: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

ANNEXURE-IIIntroduction-Sorting

A sorting algorithm is an algorithm that puts elements of a list in a certain order

Consider listx1, x2, x3, … xn

We seek to arrange the elements of the list in order• Ascending or descending• For example, to arrange the elements in ascending orderStart 1 23 2 56 9 8 10 100End 1 2 8 9 10 23 56 100

Some O(n2) schemes• Easy to understand and implement• Inefficient for large data sets

Page 6: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Sort Classifications

Sort

Internal External

Insertion Selection Exchange

Insertion Selection

Shell Heap

Bubble

Quick

Natural Balanced

Polyphase

Page 7: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

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

Page 8: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Sort

Sort Stability

• Attribute of sort indicating data with equal keys maintain relative input order in output

Unsorted data Stable sort Unstable sort

365 blue212 green876 white212 yellow119 purple737 green212 blue443 red567 yellow

119 purple212 green212 yellow212 blue365 blue443 red567 yellow737 green876 white

119 purple212 blue212 green212 yellow365 blue443 red567 yellow737 green876 white

Page 9: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Sort

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

Page 10: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Evocation

Page 11: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

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

Page 12: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

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

Page 13: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Insertion Sort Example

Page 14: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Contd.,

Page 15: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

ANNEXURE-IIIProgressive 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

Page 16: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Optical Illusion

What do you see in the image below?

Page 17: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Logo Identification

Page 18: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Abbreviation

• AIAA

• BAE

• BNSC

• A&A

Page 19: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Evocation

Page 20: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

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 listOn each pass reposition correctly some element

Page 21: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

Selection Sort Example

Page 22: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

ANNEXURE-IVMind Map

Sorting

Classification

Insertion Sort Selection SortAlgorithm

ExampleProgram

Algorithm

Example Program

Page 23: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

ANNEXURE-VSummary

• 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

Page 24: UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort

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