DS Data Structures PPT-module-6
DS Data Structures PPT-module-6
DS Data Structures PPT-module-6
SUBJECT CODE-ACIC10
(III SEM)
(IARE- UG20)
By
Ms. N.Venkata Sireesha
MODULE –I
INTRODUCTION TO DATA STRUCTURES, SEARCHING AND
SORTING (09) Basic concepts: Introduction to data structures,
classification of data structures, operations on data structures; Algorithm
Specification, Recursive algorithms, Data Abstraction, Performance
analysis- time complexity and space complexity, Asymptotic Notation-Big
O, Omega, and Theta notations. Introduction to Linear and Non Linear data
structures, Searching techniques: Linear and Binary search; Sorting
techniques: Bubble, Selection, Insertion, Quick and Merge Sort and
comparison of sorting algorithms.
3
Quick Sort
Quick sort is a divide and conquer algorithm. Quick sort first divides a
large list into two smaller sub- lists: the low elements and the high
elements. Quick sort can then recursively sort the sub-lists.
The steps are:
1. Pick an element, called a pivot, from the list.
2. Reorder the list so that all elements with values less than the pivot
come before the pivot, while all elements with values greater than
the pivot come after it (equal values can go either way). After this
partitioning, the pivot is in its final position. This is called the
partition operation.
3. Recursively apply the above steps to the sub-list of elements with
smaller values and separately the sub-list of elements with greater
values.
The base case of the recursion is lists of size zero or one, which never
need to be sorted. 4
Quick Sort
5
Quick Sort
6
Quick Sort
7
Quick Sort
8
Quick Sort
Complexity of the Quick Sort Algorithm
To sort an unsorted list with 'n' number of elements, we need to make ((n-1)+(n-2)+(n-3)+......
+1) = (n (n-1))/2 number of comparisions in the worst case. If the list is already sorted, then it
requires 'n' number of comparisions.
Worst Case : O(n2)
Best Case : O (n log n)
Average Case : O (n log n)
9
Quick Sort Program
Function to find the partition position
def partition(array, low, high):
11
Quick Sort
# Recursive call on the left of pivot
quickSort(array, low, pi - 1)
size = len(data)
quickSort(data, 0, size - 1)
12
Quick Sort
13