Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Merge-Sort and Quick-Sort Algorithms Analysis, Slides of Design and Analysis of Algorithms

An analysis of merge-sort and quick-sort algorithms, including their approach, time complexity, space complexity, and comparison with each other. It also includes example implementations and visualizations.

Typology: Slides

2011/2012

Uploaded on 07/11/2012

dharmadaas
dharmadaas 🇮🇳

4.3

(54)

266 documents

1 / 25

Toggle sidebar

Related documents


Partial preview of the text

Download Merge-Sort and Quick-Sort Algorithms Analysis and more Slides Design and Analysis of Algorithms in PDF only on Docsity! 26 3 7 5 1 8 4 6 2 Merge-Sort(A, 1, 1) , base case A: Merge-Sort(A, 0, 7) Docsity.com 27 3 7 5 1 8 4 6 2 Merge-Sort(A, 1, 1), return A: Merge-Sort(A, 0, 7) Docsity.com 30 3 7 5 1 8 4 2 6 Merge-Sort(A, 2, 3) , divide A: Merge-Sort(A, 0, 7) Docsity.com 31 3 7 5 1 4 2 6 8 Merge-Sort(A, 2, 2), base case A: Merge-Sort(A, 0, 7) Docsity.com 32 3 7 5 1 4 2 6 8 Merge-Sort(A, 2, 2), return A: Merge-Sort(A, 0, 7) Docsity.com 35 3 7 5 1 2 6 4 8 Merge(A, 2, 2, 3) A: Merge-Sort(A, 0, 7) Docsity.com 36 3 7 5 1 2 6 4 8 Merge-Sort(A, 2, 3), return A: Merge-Sort(A, 0, 7) Docsity.com 37 3 7 5 1 2 4 6 8 Merge(A, 0, 1, 3) A: Merge-Sort(A, 0, 7) Docsity.com 40 1 3 5 7 2 4 6 8 A: Merge (A, 4, 5, 7) Merge-Sort(A, 0, 7) Docsity.com 41 1 3 5 7 2 4 6 8 Merge-Sort(A, 4, 7), return A: Merge-Sort(A, 0, 7) Docsity.com 42 1 2 3 4 5 6 7 8 Merge(A, 0, 3, 7) A: Merge-Sort(A, 0, 7) Merge-Sort(A, 0, 7), done! Docsity.com 45 Overview  Divide and Conquer  Merge Sort  Quick Sort Docsity.com 46 Quick Sort  Divide:  Pick any element p as the pivot, e.g, the first element  Partition the remaining elements into FirstPart, which contains all elements < p SecondPart, which contains all elements ≥ p  Recursively sort the FirstPart and SecondPart  Combine: no work is necessary since sorting is done in place Docsity.com 47 Quick Sort x < p p p ≤ x Partition FirstPart SecondPart p pivot A: Recursive call x < p p p ≤ x Sorted FirstPart Sorted SecondPart Sorted Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved