/*
To print binary search's average case and the worst complexity
for various value of N (array size).
The average case complexity is obtained by simulation (and counting
number of comparisons.
The wo
Insertion Sort - Average Case Analysis
Claim 1:
Let CS (i ) denote the average number of comparisons made to insert the i th element
into a sorted segment of length i 1 to form a sorted segment of len
Example to introduce the idea of Shell sort
We want to sort the array
0
9
1
3
2
2
3
6
4
0
5
8
6
7
7
1
8
4
9
5
7
1
8
4
9
5
Suppose we choose to do this in 3 steps
Sort elements at distance 4 a part
Sor
Bubble Sort Tracing
The tracing below allows us to easily count the swaps. Note that each times we swap a
pair (indicated by underlining the pair), we move down a line.
Example:
0
1
2
3
4
6
4
10
2
8
6
Lecture 4
Covers:
Shell sort
Reading: Lafore chapter 7
1
> The Basic Idea
2
Shell sort uses insertion sort and improve on it
For insertion sort, we can observe that
Fact 1: On lists that are mostly so
/* LECTURE 4 - SUPPLEMENTARY
Contains:
1) The shell sort method that can be called with a user-defined sequence of
diminishing gaps.
2) Methods to generate Shell's, Knuth's and Flamig's sequences
*/
A
Welcome to
Algorithms and Data Structures
CSE2ALG / CSE5ALG
1
Lecture 1
Covers:
Overview of the Subject
Linear Search
Binary Search
Complexity Analysis
Complexity of Linear Search
Complexity of
Selection Sort Tracing
In the tracing below, underlined are the actions we know in advance that we have to
perform for each pass
Example:
0
1
2
3
4
6
4
10
2
8
Pass 1
max index (how it change as we mov
Lecture 3
Covers:
Insertion Sort
Reading: Lafore chapter 3
1
> Insertion Sort
The idea
2
The idea
Insertion sort is similar to what card players often
use to sort a hand of cards when they pick up the
Binary Search - A program to calculate for the number of
comparisons for the average case and to compare it with
that of the worst case
/*
To print binary search's average case and the worst complexit
Tracing the Execution of the Insertion Sort
Java Code (Algorithm)
The Java code for this sorting algorithm (which is just as readable as the pseudo code) is as
follows:
public static void insertionSor