Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Naive Sorting Algorithms: Bubble Sort, Insertion Sort, Selection Sort, and Comparison, Slides of Data Structures and Algorithms

An overview of naive sorting algorithms, including bubble sort, insertion sort, selection sort, and a comparison of their pros and cons. The document also includes exercises for counting operations in bubble sort and finding the runtime complexity of selection sort. Additionally, it introduces advanced sorting techniques like bucket sort and radix sort.

Typology: Slides

2012/2013

Uploaded on 04/23/2013

saratey
saratey 🇮🇳

4.3

(10)

87 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Survey of Sorting
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Naive Sorting Algorithms: Bubble Sort, Insertion Sort, Selection Sort, and Comparison and more Slides Data Structures and Algorithms in PDF only on Docsity!

Survey of Sorting

Naïve sorting algorithms

Bubble sort:

scan for flips, until all are fixed

Etc...

Insertion sort

Sorted subarray

Insertion sort

Algorithm

for

i =

to

n-

do

insert a[i] in the proper place

in

a[0:i-1]

Correctness

•Note: after i steps, the sub-array A[0:i] issorted

Selection sort

Algorithm

for

i =

n-

to

do

Find the

largest entry

in the

in

the subarray A[0:i]

Swap

with A[i]

What is the runtime complexity ofselection sort?

Sorting Comparison

• Discuss the pros and cons of each of the

naïve sorting algorithms

Bucket sort

• In addition to comparing pairs of elements,

we require these additional restrictions:

  • all elements are non-negative integers– all elements are less than a predetermined

maximum value

• Elements are usually keys paired with

other data

Bucket sort

Radix Sort

Radix sort

• If your integers are in a larger range then

do bucket sort on

each digit

• Start by sorting with the

low-order digit

using a

STABLE

bucket sort.

• Then, do the next-lowest,and so on

Radix sort characteristics

• Each sorting step can be performed via

bucket sort, and is thus

O

(N).

• If the numbers are all

b bits

long, then

there are b sorting steps.

• Hence, radix sort is

O

(bN).

What about non-binary?

• Radix sort can be used for decimal

numbers and alphanumeric strings.