The document discusses various sorting algorithms:
- Insertion sort works by dividing an array into sorted and unsorted parts, inserting unsorted elements into the sorted part one by one.
- Quicksort uses a divide and conquer approach, recursively dividing the array into sublists and selecting a pivot element.
- Merge sort divides the array into halves, recursively sorts the halves, and then merges the sorted halves.
- Heap sort uses a heap data structure that maintains the heap property as it builds the heap from an unsorted array and then extracts elements in sorted order.
3. INSERTION SORT
For Insertion sort, we need to consider an array in
two parts – Sorted part & Unsorted part !
Let us consider an unsorted array of integer with 6
elements : 7 2 4 1 5 3
This is an unsorted array
We will have to divide this array into sorted part
and unsorted part
The first element is always sorted
20. QUICK SORT
Quicksort is an algorithm of divide and conquer type . It is an
algorithm design based on multi-branched recursion . It works
by recursively breaking down a problem into two or more sub
problems of the same related type.
In quick sort we will divide the problems in two sub list.And the
algorithm will find the final position of one of the numbers.
From this position the value of the left side will be less than the
numbers and the value will be greater than the right
25. What is Merge Sort
Merge Sort is one kind of sorting
that based on Divide and
Conquer algorithm .
26. How IT WORKS
It divides input array in two halves , calls itself
(using recursive function) for the two halves
and then merges the two sorted halves .
31. Heap tree is a complete binary tree but
at lowest level of it is not necessary to
make heap tree a complete binary tree.
complete binary tree
Not necessray
Heap Sort
32. Heap Sort
•:Length: Number of elements in the
array
•Heap-size - how many elements in
the heap are stored within
array A.
36. Each node in a tree has a key which is
more extreme (greater or less) than or
equal to the key of its parent.
A complete tree with the heap property is
a heap.
37. MAX-HEAP PROPERTY
Each node in a tree has a key which is
less than or equal to the key of its parent.
A[PARENTi] >= A[i]
“While using this property it makes a list of
descending order.”
38. MIN-HEAP PROPERTY
Each node in a tree has a key which is
greater than or equal to the key of
its parent.
A[PARENTi] <= A[i]
“While using this property it makes a list of
ascending order.”
39. BUILDING THE HEAP
“ The Build heap method
shown in Program transforms an
unsorted array into a max
heap or min heap ”