Algorithm - Mergesort & Quicksort
-
Upload
varendra-university-rajshahi-bangladesh -
Category
Education
-
view
45 -
download
2
Transcript of Algorithm - Mergesort & Quicksort
WELCOME TO MY
PRESENTATION
Course title : Algorithm - Mergesort & Quicksort CSE-225
• Submitted By: • Submitted ToName: Istiaque Ahmed
ShuvoId:141311057
5th batch ,5th semesterSec-BDept. Of CseVarendra University,rajshahi
Name: Atiquer Rahman Sarkar, CSE, Varendra University
Quick sort Algorithm
Merge sort Algorithm
Merge Sort
Merge sort is based on Divide and conquer method. It takes the list to be sorted and divide it in half to create two unsorted lists. The two unsorted lists are then sorted and merged to get a sorted list. The two unsorted lists are sorted by continually calling the merge-sort algorithm; we eventually get a list of size 1 which is already sorted. The two lists of size 1 are then merged.
Example sort Example
The most well known algorithm design strategy:
1.Divide instance of problem into two or more smaller instances
2.Solve smaller instances recursively
3.Obtain solution to original (larger) instance by combining these solutions
Divide-and-conquer Technique
subproblem 2 of size n/2
subproblem 1 of size n/2
a solution to subproblem 1
a solution tothe original problem
a solution to subproblem 2
a problem of size n
Divide and Conquer Examples
• Sorting: mergesort and quicksort
• Tree traversals
• Matrix multiplication-Strassen’s algorithm
• Closest pair problem
Merge Sort Algorithm
MergeSort (Example) - 1
MergeSort (Example) - 2
MergeSort (Example) - 3
MergeSort (Example) - 4
MergeSort (Example) - 5
MergeSort (Example) - 6
MergeSort (Example) - 7
MergeSort (Example) - 8
MergeSort (Example) - 9
MergeSort (Example) - 10
MergeSort (Example) - 11
MergeSort (Example) - 12
MergeSort (Example) - 13
MergeSort (Example) - 14
MergeSort (Example) - 15
MergeSort (Example) - 16
MergeSort (Example) - 17
MergeSort (Example) - 18
MergeSort (Example) - 19
MergeSort (Example) - 20
MergeSort (Example) - 21
MergeSort (Example) - 22
14 23 45 98 6 33 42 67
Merge
23 45 98 33 42 6714 6
Merge
23 45 98 6 42 67
6
14 33
Merge
14 45 98 6 42 67
6 14
23 33
Merge
14 23 98 6 42 67
6 14 23
45 33
Merge
14 23 98 6 33 67
6 14 23 33
45 42
Merge
14 23 98 6 33 42
6 14 23 33 42
45 67
Merge
14 23 45 6 33 42
6 14 23 33 42 45
98 67
Merge
14 23 45 98 6 33 42 67
6 14 23 33 42 45 67
Merge
14 23 45 98 6 33 42 67
6 14 23 33 42 45 67 98
Quick sort Algorithm
QUICKSORT (A, p, r)
1. if p < r2. q = PARTITION (A, p, r)3. QUICKSORT (A, p, q-1)4. QUICKSORT (A, q -1, r)
Partitioning the array
PARTITION (A, p, r)
1. X=A[r]2. i =p -13. for j = p to r -14. if A[j] X5. i = i + 16. exchange A[i] with A[j]7. exchange A[i+1] with A[r]8. return i+1