COMP 2011 - Data Structures & Algorithms

A. Sorting

SortingRunning TIme (Worst)Running TIme (Best)StableMajor IterationscomparisonsSwappingExample (Unstable)Example (best case)
Bubble Sortθ( n^2 )θ( n )Tn − 1 (1 in 1,2,3,4,5)n − in − i  
Insertion Sortθ( n^2 )θ( n )Tn − 1    
Selection Sortθ( n^2 )θ( n^2 )Fn − 1n - i, (i in 5,4,3,2,1)   
Merge Sortθ( n log n )θ( n log n )T     
Quick Sortθ( n^2 )θ( n log n )F    [1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8]
Heap Sortθ( n log n )θ( n log n )F   [9, 9, 6], [9, 9], [2, 0, 2, 1], [6, 6, 9], but ([2, 0, 1, 1] & [9, 6, 6] are Stable) 

(a) Bubble or Insertion Sorting uses the least steps when the array is sorted.

(b) Merge Sorting uses the least steps when the array is reversely sorted.

(c) Insertion Sorting uses the least steps when the array is sorted except one element.

(d) Merge Sorting uses the least steps in the worst case.

(e) Selection or Quick Sorting is not stable.

1. Bubble Sorting --- ( o(n^2) )

1, 2, 3, 4, 5, .... --> no swapping, only one major iteration.

2. Selection Sorting --- ( o(n^2) )

Always n−1 major iterations, n−i comparisons in the ith major iteration

3. Insertion Sorting --- ( o(n^2) )

1, 2, 3, 4, 5, ... --> one comparison and two movements in each major iteration.

Always n−1 major iterations.

4. Merge Sorting (Recursive) --- ( o(n log n) )

levels --> Θ(logn)

5. Quick Sorting (Recursive)

levels --> logn ∼ n−1

6. Heap Sorting

--> to I. Heap [3. Heap Sorting]

 

B. Searching

1. Linear Searching

2. Binary Searching (Iterative) --- ( o(log n) )

3. Binary Search (Recursive) --- ( o(log n) )

4. Find Max & Min

major: (2n - 2)

 

C. Stack

1. Stack

2. Brackets Check (Stack Application)

3. Postfix (Stack Application)

 

D. Queue

1. Circular Queue

2. Queue on Linked List

 

E. Array

1. Array List

 

F. Linked List

TypeNumbe of Null Reference
Linked List1
Doubly Linked List2

1. Linked List

2. Reverse Linked List

3. Doubly Linked List

4. Reverse Doubly Linked List

5. Circular Doubly Linked List

6. Queue on Linked List

--> to D. Queue [2. Queue on Linked List]

7. Merge Two Linked List

 

G. Divide & Conquer

1. Find Peak (Recursive)

2. Find Max & Min

--> to B. Searching [4. Find Max & Min]

3. Merge Sorting

--> to A. Sorting [4. Merge Sorting]

4. Quick Sorting

--> to A. Sorting [4. Quick Sorting]

5. Towers of Hanoi Problem (Divide & Conquer Application)

6. Stable Merger

 

H. Tree

TypeNumbe of Null Reference
Binary Treen + 1
FunctionRunning TimeBest Caseworst Case
Finding a min elementO( n )  
InsertO( h ) / O( n ) / O( d )  
DeletionO( h ) / O( n ) / O( d )  
SearchingO( h ) / O( n ) / O( d )d = [ log n ] (Tree is Balanced)d = n - 1
Traversals   
DFSO( n ) / O( h )  
BFS / Level OrderO( w )  

1. Binary Search Tree

2. Merge Binary Trees

 

 

I. Heap

 FunctionBig O
HeapInsertO( log n )
 UpO( log n )
 DownO( log n )
 removeMaxO( log n )
Heap SortheapsortO( n log n )
 UpO( log n ) OR O( log size )
 DownO( log n ) OR O( log size )

A Max Heap on n nodes has n / 2 leaves.

1. Implantation of a Heap (Max Heap)

heap

2. Priority Queues (Heap Application)

3. Heap Sorting (Heap Application)

heap_time

Heapify (turn something into a heap): O(n log n) (can be down in O(n))

RemoveMax: O(n log n)

(1)Heapify: i=1n1log(i+1)<i=1n(logn+1)=O(nlogn)RemoveMax: i=1n1log(n+1i)<i=1n(logn+1)=O(nlogn)

Heap Sorting is unstable.

 

 

J. Hashing

1. Linear Probing Hash

 

2. Separate Chainning

 

3. Duplicate Character

 

4. Other Hashing

4.1 Quadratic Probing Hash

Quadratic_probing

4.2 Double Hashing

Double_hashing

Overall

Hash Function - Probing