DAA Unit 1 Notes
DAA Unit 1 Notes
Case Time
Complexity
Best Case O(n*logn)
Average Case O(n*logn)
Worst Case O(n*logn)
QUICK SORT ALGORITHM
QuickSort is a sorting algorithm based on the Divide and
Conquer algorithm that picks an element as a pivot and
partitions the given array around the picked pivot by
placing the pivot in its correct position in the sorted array.
QUICK SORT ALGORITHM
.
QUICK SORT ALGORITHM
.
TIME COMPLEXITY QUICK SORT ALGORITHM
• Best Case: Ω (N log (N))
• Average Case: θ ( N log (N))
• Worst Case: O(N2)
Heap Sort
• A Heap is a special Tree-based data structure in which the tree is a
complete binary tree.
.
Heap Sort
.
Heap Sort
.
Heap Sort
.
Heap Sort
Shell Sort
• Shell sort is mainly a variation of Insertion Sort. In insertion sort, we
move elements only one position ahead.
• When an element has to be moved far ahead, many movements are
involved. The idea of ShellSort is to allow the exchange of far items.
• In Shell sort, we make the array h-sorted for a large value of h. We
keep reducing the value of h until it becomes 1.
• An array is said to be h-sorted if all sublists of every h’th element are
sorted.
Shell Sort
ShellSort(a, n) // 'a' is the given array, 'n' is the size of
array
1. for (interval = n/2; interval > 0; interval /= 2)
2. for ( i = interval; i < n; i += 1)
3. temp = a[i];
4.
for (j = i; j >= interval && a[j - interval] > temp; j -
= interval)
5. a[j] = a[j - interval];
6. a[j] = temp;
Shell Sort
•.
Shell Sort
•.
Shell Sort Time Complexity
Case Time Complexity
Count array
COUNTING SORT Time Complexity
• Best Case O(n + k)
• Average Case O(n + k)
• Worst Case O(n + k)