Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

BITS F232

aft
Foundations of
Data Structures & Algorithms
Lect 3
Sameera Muhamed Salam
Dept of CSIS, BITS Pilani, Hyderabad Campus

Dr
Algorithm & Algorithm Analysis

BITS F232 Sameera M S 2


Quiz 1

Given an array A, write a pseudocode to find the smallest element in the array?

BITS F232 Sameera M S 3


Insertion Sort

I There will be two lists


I Sorted
I Unsorted list
I Intitially
I First element will be in the sorted list
I Remaining elements in the unsorted list
I Place the first element from the unsorted list to the correct position in the sorted
list

BITS F232 Sameera M S 4


Insertion Sort

Example: 4 3 2 10 12 1 5 6

BITS F232 Sameera M S 5


Insertion Sort
Example: 4 3 2 10 12 1 5 6

BITS F232 Sameera M S 6


Inserting in correct position

BITS F232 Sameera M S 7


Inserting in correct position

BITS F232 Sameera M S 8


Insertion Sort

Algorithm?

BITS F232 Sameera M S 9


Insertion Sort

Example: 7, 4, 8, 2, 5, 3, 9

BITS F232 Sameera M S 10


Selection Sort

I It Selects the smallest (or largest) element from the unsorted portion of the list
and swap it with current element.
Algorithm?

BITS F232 Sameera M S 11


Selection Sort

BITS F232 Sameera M S 12


Discussion Time!

BITS F232 Sameera M S 13


BITS F232 Sameera M S 14

You might also like