Insertion sort

Post on 17-Dec-2014

725 Views

Category:

Entertainment & Humor

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

Transcript

Insertion sort!!!

Sorting:Question: How do you sort out data?

a-z

a-ZA-Z0,1,2,3…..

Looking For Patterns

Question: Why do we sort out data?

Answer: For effective analysis of data?

Common Sorting:

Insertion Sort

Insertion sort is a simple sorting algorithm

that builds the final sorted array (or list)

one item at a time

It is much less efficient on large lists than more advanced algorithms

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list

Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list

Select Link here

Advantages / Disadvantages

Advantages Disadvantages

• Simple It is much less efficient on large lists

• Efficient in practice than most other simple quadratic

• Does not change the relative order of elements with equal key

• Only requires a constant amount O(1) of additional memory space

• Can sort a list as it receives it

Least Advanced to other Algoritms

Best/Worst Array

Best Array:

The best case input is an array that is already sorted.

In this case insertion sort has a linear running time

(i.e., Θ(n)). During each iteration

The first remaining element of the input is only compared with the right-most element of the sorted subsection of the array.

Worst Array:

The simplest worst case input is an array sorted in reverse order

The set of all worst case inputs consists of all arrays where each

element is the smallest or second-smallest of the elements before it.

In these cases every iteration of the inner loop will scan and shift

the entire sorted subsection of the array before inserting the next element.

Now for a Quiz!!!!!!

Please read the set of questions and select the correct answers

Question 1

Complete the following sentence “Insertion Sort is...?

a) “….a complex sorting algorithm”

b) “… a simple sorting algorithm”

c) “…the most efficient sorting algoritm”

Oh No Try Again!

Or select to quit

Correct Answer!!!!!

Well Done go to the next question

Question 2

How does Insertion operate?

a) Builds the final sorted array (or list) one item at a time

b) Builds the final sorted array (or list) in data batches

c) Builds the final sorted array (or list) in reverse order

Correct Answer!!!!!

Well Done go to the next question

Oh No Try Again!

Or select to quit

Question 3

True or False

“One of the advantages of Insertion is that it only requires a constant amount an additional memory space”

True False

Correct Answer!!!!!

Well Done go to the next question

Oh No Try Again!

Or select to quit

Question 4

True of False, Insertion is most efficient on large lists?

True False

Correct Answer!!!!!

Well Done go to the next question

Oh No Try Again!

Or select to quit

Question 5

The Best Array is…

a) Data grouped in alphabetical order

b) Data grouped in reverse order

c) Data already sorted

Correct Answer!!!!!

Well Done go to the next question

Oh No Try Again!

Or select to quit

top related