Sorting: part 1 Barak Obama on sorting, bubble sort, insertion sort,

Slides:



Advertisements
Similar presentations
Garfield AP Computer Science
Advertisements

A simple example finding the maximum of a set S of n numbers.
CSCE 3110 Data Structures & Algorithm Analysis
CS 171: Introduction to Computer Science II Mergesort.
Efficient Sorts. Divide and Conquer Divide and Conquer : chop a problem into smaller problems, solve those – Ex: binary search.
CHAPTER 11 Sorting.
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
HKOI 2006 Intermediate Training Searching and Sorting 1/4/2006.
Lecture 2 Sorting. Sorting Problem Insertion Sort, Merge Sort e.g.,
1 Week 9 A little more GUI, and threads. Objectives: Discuss the Swing set of classes. Incorporate animation into applets. Define the term thread. Explain.
Teacher Talk There has never been a better time to teach Computer Science 2.We can learn from Chemistry, Physics, Biology, …
Sorting and Searching by Dr P.Padmanabham Professor (CSE)&Director
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
Reflections of ADS “There has never been a better time to teach Computer Science” Patrick Prosser 2011.
Quick sort, lower bound on sorting, bucket sort, radix sort, comparison of algorithms, code, … Sorting: part 2.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
Insertion Sorting example { 48}
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Merge Sort.
Advanced Sorting.
Advanced Sorting 7 2  9 4   2   4   7
CMPT 438 Algorithms.
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Sorting.
Lecture 2 Sorting.
Design and Analysis of Algorithms
Introduction to Algorithms: Asymptotic Notation
CSCI 104 Sorting Algorithms
Recitation 13 Searching and Sorting.
CS 3343: Analysis of Algorithms
COMP 53 – Week Seven Big O Sorting.
Chapter 2 (16M) Sorting and Searching
Lecture 4 Divide-and-Conquer
Searching & Sorting "There's nothing hidden in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting.
Quick-Sort 9/12/2018 3:26 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Divide-And-Conquer-And-Combine
Chapter 7 Sorting Spring 14
Teach A level Computing: Algorithms and Data Structures
Divide and Conquer.
CS 3343: Analysis of Algorithms
Adapted from slides by Marty Stepp and Stuart Reges
Quick-Sort 11/14/2018 2:17 PM Chapter 4: Sorting    7 9
Sorting Chapter 13 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
CS 3343: Analysis of Algorithms
Chapter 4: Divide and Conquer
Data Structures and Algorithms
Quick-Sort 11/19/ :46 AM Chapter 4: Sorting    7 9
Quick Sort (11.2) CSE 2011 Winter November 2018.
CS 3343: Analysis of Algorithms
كلية المجتمع الخرج البرمجة - المستوى الثاني
Divide-And-Conquer-And-Combine
CS200: Algorithms Analysis
Sub-Quadratic Sorting Algorithms
CSE373: Data Structure & Algorithms Lecture 21: Comparison Sorting
Quick-Sort 2/23/2019 1:48 AM Chapter 4: Sorting    7 9
CSE 332: Data Abstractions Sorting I
Quick-Sort 2/25/2019 2:22 AM Quick-Sort     2
Sorting.
Divide & Conquer Algorithms
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
Searching/Sorting/Searching
Algorithms Sorting.
CSCE 3110 Data Structures & Algorithm Analysis
CSCE 3110 Data Structures & Algorithm Analysis
Lecture 15: Sorting Algorithms
CSCE 3110 Data Structures & Algorithm Analysis
Lecture 19: Sorting Algorithms
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Sorting Popular algorithms:
Presentation transcript:

Sorting: part 1 Barak Obama on sorting, bubble sort, insertion sort, selection sort, merge, merge sort, ... demos, demos, demos …

Sorting, what’s that then? Given a collection of data, get it into order …

Given a collection of data, get it into order … 9 2 6 0 4 3 2 7 5 This is NOT in order

Given a collection of data, get it into order … 0 2 3 4 5 6 7 9 This is IS in order

Given a collection of data, get it into order … 0 2 3 4 5 6 7 9 This is IS in order It’s in ascending order

Sorting is the process of going from this 9 2 6 0 4 3 2 7 5 to that 0 2 3 4 5 6 7 9

Who cares? Sorting, why bother? 9 2 6 0 4 3 2 7 5 You can find things quicker!

9 2 6 0 4 3 2 7 5 You can find things quicker! 0 2 3 4 5 6 7 9 Use “binary search” (or even linear search and stop early)

sorting Some algorithms for sorting bubble sort insertion sort selection sort shell sort gnome sort merge sort quick sort heap sort radix sort bead sort

sorting Some algorithms for sorting bubble sort insertion sort selection sort shell sort gnome sort merge sort quick sort heap sort radix sort bead sort quadratic

sorting Some algorithms for sorting bubble sort insertion sort selection sort shell sort gnome sort merge sort quick sort heap sort radix sort bead sort logarithmic

sorting Some algorithms for sorting bubble sort insertion sort selection sort shell sort gnome sort merge sort quick sort heap sort radix sort bead sort linear

sorting Some algorithms for sorting bubble sort insertion sort selection sort shell sort gnome sort merge sort quick sort heap sort radix sort bead sort Our example

Example sorting 9 2 6 4 3 2 7 5 Bubble Sort

Example sorting 9 2 6 4 3 2 7 5 compare Bubble Sort

Example sorting 2 9 6 4 3 2 7 5 swap Bubble Sort

Example sorting 2 9 6 4 3 2 7 5 compare Bubble Sort

Example sorting 2 6 9 4 3 2 7 5 swap Bubble Sort

Example sorting 2 6 9 4 3 2 7 5 compare Bubble Sort

Example sorting 2 6 9 4 3 2 7 5 swap Bubble Sort

Example sorting 2 6 9 4 3 2 7 5 compare Bubble Sort

Example sorting 2 6 4 9 3 2 7 5 swap Bubble Sort

Example sorting 2 6 4 9 3 2 7 5 compare Bubble Sort

Example sorting 2 6 4 3 9 2 7 5 swap Bubble Sort

Example sorting 2 6 4 3 9 2 7 5 compare Bubble Sort

Example sorting 2 6 4 3 2 9 7 5 swap Bubble Sort

Example sorting 2 6 4 3 2 9 7 5 compare Bubble Sort

Example sorting 2 6 4 3 2 7 9 5 swap Bubble Sort

Example sorting 2 6 4 3 2 7 9 5 compare Bubble Sort

Example sorting 2 6 4 3 2 7 5 9 swap Bubble Sort

Example sorting 2 6 4 3 2 7 5 9 Bubble Sort

Example sorting 2 6 4 3 2 7 5 9 compare Bubble Sort

Example sorting 2 6 4 3 2 7 5 9 compare Bubble Sort

Example sorting 2 6 4 3 2 7 5 9 swap Bubble Sort

Example sorting 2 6 4 3 2 7 5 9 compare Bubble Sort

Example sorting 2 4 6 3 2 7 5 9 swap Bubble Sort

Example sorting 2 4 6 3 2 7 5 9 compare Bubble Sort

Example sorting 2 4 3 6 2 7 5 9 swap Bubble Sort

Example sorting 2 4 3 6 2 7 5 9 compare Bubble Sort

Example sorting 2 4 3 2 6 7 5 9 swap Bubble Sort

Example sorting 2 4 3 2 6 7 5 9 compare Bubble Sort

Example sorting 2 4 3 2 6 7 5 9 compare Bubble Sort

Example sorting 2 4 3 2 6 5 7 9 swap Bubble Sort

Example sorting 2 4 3 2 6 5 7 9 Bubble Sort

Example sorting 2 4 3 2 6 5 7 9 Are you tired yet? Bored? Bubble Sort

Example sorting 2 4 3 2 6 5 7 9 compare Bubble Sort

Example sorting 2 4 3 2 6 5 7 9 swap Bubble Sort

Example sorting 2 4 3 2 6 5 7 9 compare Bubble Sort

Example sorting 2 4 3 2 6 5 7 9 compare Bubble Sort

Example sorting 2 3 4 2 6 5 7 9 swap Bubble Sort

Example sorting 2 3 4 2 6 5 7 9 compare Bubble Sort

Example sorting 2 3 2 4 6 5 7 9 swap Bubble Sort

Example sorting 2 3 2 4 6 5 7 9 compare Bubble Sort

Example sorting 2 3 2 4 6 5 7 9 compare Bubble Sort

Example sorting 2 3 2 4 5 6 7 9 swap Bubble Sort

Example sorting 2 3 2 4 5 6 7 9 Bubble Sort

Example sorting 2 3 2 4 5 6 7 9 compare Bubble Sort

Example sorting 2 3 2 4 5 6 7 9 compare Bubble Sort

Example sorting 2 3 2 4 5 6 7 9 compare Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 swap Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 compare Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 compare Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 compare Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 compare Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 compare Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 compare Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 Phew! Bubble Sort

On an Array sorting Bubble Sort

Example sorting i=8 9 2 6 4 3 2 7 5 Bubble Sort

Example sorting i=8 j=0 9 2 6 4 3 2 7 5 compare Bubble Sort

Example Example sorting i=8 j=0 2 9 6 4 3 2 7 5 swap Bubble Sort

Example Example Example sorting i=8 j=1 2 9 6 4 3 2 7 5 compare Bubble Sort

Example Example Example Example sorting i=8 j=1 2 6 9 4 3 2 7 5 swap Bubble Sort

Example Example Example Example Example sorting i=8 j=2 2 6 9 4 3 2 7 5 compare Bubble Sort

Example Example Example Example Example Example sorting i=8 j=2 2 6 9 4 3 2 7 5 swap Bubble Sort

Example Example Example Example Example Example Example sorting i=8 j=3 2 6 9 4 3 2 7 5 compare Bubble Sort

Example Example Example Example Example Example Example Example sorting i=8 j=3 2 6 4 9 3 2 7 5 swap Bubble Sort

Example Example Example Example Example Example Example Example Example sorting i=8 j=4 2 6 4 9 3 2 7 5 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example sorting i=8 j=4 2 6 4 3 9 2 7 5 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example sorting i=8 j=5 2 6 4 3 9 2 7 5 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example sorting i=8 j=5 2 6 4 3 2 9 7 5 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=6 i=8 2 6 4 3 2 9 7 5 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=6 i=8 2 6 4 3 2 7 9 5 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=7 i=8 2 6 4 3 2 7 9 5 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=7 i=8 2 6 4 3 2 7 5 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting 2 6 4 3 2 7 5 9 Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting i=7 j=0 2 6 4 3 2 7 5 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting i=7 j=1 2 6 4 3 2 7 5 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting i=7 j=1 2 6 4 3 2 7 5 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting i=7 j=2 2 6 4 3 2 7 5 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting i=7 j=2 2 4 6 3 2 7 5 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting i=7 j=3 2 4 6 3 2 7 5 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting i=7 j=3 2 4 3 6 2 7 5 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting i=7 j=4 2 4 3 6 2 7 5 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting i=7 j=4 2 4 3 2 6 7 5 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting j=5 i=7 2 4 3 2 6 7 5 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting j=6 i=7 2 4 3 2 6 7 5 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting j=6 i=7 2 4 3 2 6 5 7 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting 2 4 3 2 6 5 7 9 Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting sorting j=0 i=6 2 4 3 2 6 5 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=0 i=6 2 4 3 2 6 5 7 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=1 i=6 2 4 3 2 6 5 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=2 i=6 2 4 3 2 6 5 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=2 i=6 2 3 4 2 6 5 7 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=3 i=6 2 3 4 2 6 5 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=3 i=6 2 3 2 4 6 5 7 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=4 i=6 2 3 2 4 6 5 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=5 i=6 2 3 2 4 6 5 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=5 i=6 2 3 2 4 5 6 7 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting 2 3 2 4 5 6 7 9 Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=0 i=5 2 3 2 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=1 i=5 2 3 2 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=2 i=5 2 3 2 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=2 i=5 2 2 3 4 5 6 7 9 swap Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=3 i=5 2 2 3 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=4 i=5 2 2 3 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting 2 2 3 4 5 6 7 9 Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=0 i=4 2 2 3 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=1 i=4 2 2 3 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=2 i=4 2 2 3 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting j=3 i=4 2 2 3 4 5 6 7 9 compare Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting 2 2 3 4 5 6 7 9 Bubble Sort

Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example sorting 2 2 3 4 5 6 7 9 Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 Bubble Sort

Example sorting 2 2 3 4 5 6 7 9 Phew! Bubble Sort

On an Array sorting Can we visualize this? Bubble Sort

On an Array sorting Can we visualize this? Assume we have a random list of numbers from 0 to n-1, put in an array A Such that A[0] is the 1st number and A[n-1] is the last Bubble Sort

On an Array sorting Can we visualize this? Assume we have a random list of numbers from 0 to n-1, put in an array A Such that A[0] is the 1st number and A[n-1] is the last 9 2 6 4 3 2 7 5 Bubble Sort

On an Array sorting Can we visualize this? Assume we have a random list of numbers from 0 to n-1, put in an array A Such that A[0] is the 1st number and A[n-1] is the last 9 2 6 4 3 5 7 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] Bubble Sort

On an Array sorting Can we visualize this? Assume we have a random list of numbers from 0 to n-1, put in an array A Such that A[0] is the 1st number and A[n-1] is the last 9 2 6 4 3 5 7 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] We could plot A[i] on a graph as a point with x/y coordinates i/A[i] Bubble Sort

On an Array sorting Can we visualize this? Assume we have a random list of numbers from 0 to n-1, put in an array A Such that A[0] is the 1st number and A[n-1] is the last 9 2 6 4 3 5 7 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] We could plot A[i] on a graph as a point with x/y coordinates i/A[i] Do this as the algorithm progress to see how it progresses. Bubble Sort

Ready? On an Array sorting Can we visualize this? Assume we have a random list of numbers from 0 to n-1, put in an array A Such that A[0] is the 1st number and A[n-1] is the last 9 2 6 4 3 5 7 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] We could plot A[i] on a graph as a point with x/y coordinates i/A[i] Do this as the algorithm progress to see how it progresses. Bubble Sort

On an Array sorting Bubble Sort

sorting Show me more! Bubble Sort

sorting Show me more! different sorting algorithms and relative performance a beauty contest what is the “sound” of sorting? can you show me it by mime? Expressive dance? Bubble Sort

sorting NOTE to self: Bubble sort is a quadratic time algorithm. If I have to sort a data set of N objects the run time will be proportional to N2 To sort 10 numbers will take 100 units of time To sort 100 numbers will take 10,000 units of time Bubble Sort

Barak on Sorting

Links sorting algorithm animation sound of sorting (part 1) sound of sorting (part 2) bubble sort by folk dancing

sorting O(n^2) algorithms bubble sort insertion sort selection sort

On an Array sorting Bubble Sort O(n^2) algorithms bubble sort insertion sort selection sort On an Array sorting Bubble Sort

On an Array sorting Selection Sort O(n^2) algorithms bubble sort insertion sort selection sort On an Array sorting Selection Sort

On a linked list sorting insertion sort O(n^2) algorithms bubble sort selection sort On a linked list sorting insertion sort

merge

merge sorting You have already done this! (QueueSort) Demo with cards?

merge sorting On linked lists

where l1 is of size n1 and l2 is of size n2 merge sorting On linked lists O(n1 + n2) where l1 is of size n1 and l2 is of size n2

sorting merge sort

merge sort sorting msort(L) if (size(L) <= 1) return L return merge(msort(leftHalf(L)),msort(rightHalf(L)))

merge sort sorting msort(L) if (size(L) <= 1) return L return merge(msort(leftHalf(L)),msort(rightHalf(L))) Divide and Conquer divide: divide input data into smaller parts recur: solve the small parts conquer: combine the subproblems once solved (merge)

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting Stopping condition

merge sort sorting Divide list into Left and Right parts

merge sort sorting recurse & merge

a way of “thinking” about merge sort sorting merge sort tree a way of “thinking” about merge sort

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting abbreviated

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting

merge sort sorting n

merge sort sorting n n/2 n/2

merge sort sorting n 2.T(n/2) n/2 n/2

merge sort sorting n 2.T(n/2) n/2 n/2 T(n) is time to cut the data into 2 parts make 2 recursive calls to msort merge the 2 msorted parts and this is linear in n

merge sort sorting n n/2 n/2 n/4 n/4 n/4 n/4

merge sort sorting n n/2 n/2 4.T(n/4) n/4 n/4 n/4 n/4

merge sort sorting n n/2 n/2 n/4 n/4 n/4 n/4 n/8 n/8 n/8 n/8 n/8 n/8 n/8 n/8

merge sort sorting n n/2 n/2 n/4 n/4 n/4 n/4 8.T(n/8) n/8 n/8 n/8 n/8 n/8 n/8 n/8 n/8

merge sort sorting n n/2 n/2 n/4 n/4 n/4 n/4 8.T(n/8) n/8 n/8 n/8 n/8 n/8 n/8 n/8 n/8 This goes on h times where h = log(n) … base 2

merge sort sorting n n/2 n/2 n/4 n/4 n/4 n/4 8.T(n/8) n/8 n/8 n/8 n/8 n/8 n/8 n/8 n/8 This goes on h times where h = log(n) … base 2 Therefore O(n) at each level

merge sort sorting n n/2 n/2 n/4 n/4 n/4 n/4 8.T(n/8) n/8 n/8 n/8 n/8 n/8 n/8 n/8 n/8 This goes on h times where h = log(n) … base 2 Therefore O(n) at each level Therefore O(n.log(n))

fin