COP 3503 FALL 2012 Shayan Javed Lecture 16

Slides:



Advertisements
Similar presentations
Garfield AP Computer Science
Advertisements

Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Lecture 25 Selection sort, reviewed Insertion sort, reviewed Merge sort Running time of merge sort, 2 ways to look at it Quicksort Course evaluations.
Simple Sorting Algorithms
1 TCSS 342, Winter 2005 Lecture Notes Sorting Weiss Ch. 8, pp
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
Simple Sort Algorithms Selection Sort Bubble Sort Insertion Sort.
Simple Sorting Algorithms. 2 Outline We are going to look at three simple sorting techniques: Bubble Sort, Selection Sort, and Insertion Sort We are going.
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
Computer Science Searching & Sorting.
Searching. The process used to find the location of a target among a list of objects Searching an array finds the index of first element in an array containing.
CSE 373 Data Structures and Algorithms
Lecture 6 Sorting Algorithms: Bubble, Selection, and Insertion.
CSE 373: Data Structures and Algorithms Lecture 6: Sorting 1.
CSE 341 Lecture 4 merge sort; basic efficiency issues Ullman slides created by Marty Stepp
1 CSE 373 Sorting 3: Merge Sort, Quick Sort reading: Weiss Ch. 7 slides created by Marty Stepp
CS 162 Intro to Programming II Bubble Sort 1. Compare adjacent elements. If the first is greater than the second, swap them. Do this for each pair of.
Lecture #9: Sorting Algorithms خوارزميات الترتيب Dr. Hmood Al-Dossari King Saud University Department of Computer Science 22 April 2012.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
Intro To Algorithms Searching and Sorting. Searching A common task for a computer is to find a block of data A common task for a computer is to find a.
M180: Data Structures & Algorithms in Java Sorting Algorithms Arab Open University 1.
Bubble Sort Example
CSE 143 Lecture 16 Sorting reading: 13.1, slides created by Marty Stepp
Building Java Programs Chapter 13 Sorting reading: 13.3, 13.4.
Searching and Sorting Searching algorithms with simple arrays
Sort Algorithm.
Lecture 25: Searching and Sorting
CS212: Data Structures and Algorithms
Sorting Mr. Jacobs.
COP 3503 FALL 2012 Shayan Javed Lecture 15
Simple Sorting Algorithms
slides created by Marty Stepp and Hélène Martin
Adapted from slides by Marty Stepp and Stuart Reges
Bubble Sort Bubble sort is one way to sort an array of numbers. Adjacent values are swapped until the array is completely sorted. This algorithm gets its.
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Linear and Binary Search
Selection Sort Sorted Unsorted Swap
Building Java Programs
slides adapted from Marty Stepp and Hélène Martin
Building Java Programs
Quicksort analysis Bubble sort
Selection sort Given an array of length n,
CSC215 Lecture Algorithms.
Sorting.
CSE 154 Sorting reading: 13.3, 13.4
Adapted from slides by Marty Stepp and Stuart Reges
Sorting.
slides created by Marty Stepp
Sub-Quadratic Sorting Algorithms
slides adapted from Marty Stepp
slides created by Marty Stepp and Ethan Apter
slides created by Marty Stepp
Topic 17 Faster Sorting "The bubble sort seems to have nothing to recommend it, except a catchy name and the fact that it leads to some interesting theoretical.
slides created by Marty Stepp
CSE 143 Sorting reading: 13.3, 13.4.
Simple Sorting Algorithms
CSE 373 Data Structures and Algorithms
slides created by Marty Stepp and Hélène Martin
Building Java Programs
slides adapted from Marty Stepp
CSE 373 Sorting 1: Bogo Sort, Stooge Sort, Bubble Sort
Simple Sorting Algorithms
Simple Sorting Algorithms
Insertion Sort and Shell Sort
CSE 373 Sorting 2: Selection, Insertion, Shell Sort
CS 165: Project in Algorithms and Data Structures Michael T. Goodrich
Stacks, Queues, ListNodes
Sorting Popular algorithms:
Presentation transcript:

COP 3503 FALL 2012 Shayan Javed Lecture 16 Programming Fundamentals using Java

Sorting Another crucial problem. Used everywhere: Sorting numbers (prices/grades/ratings/etc..) Names Dates Rating

Sorting When shopping online (Amazon for ex.):

Sorting We designed a RedBox system where you can sort by different criteria

Sorting We designed a RedBox system where you can sort by different criteria How can you sort in Java?

Sorting We designed a RedBox system where you can sort by different criteria How can you sort in Java? Arrays.sort(..) – but how does it work?

Sorting We designed a RedBox system where you can sort by different criteria How can you sort in Java? Arrays.sort(..) – but how does it work? Going to look at a few different algorithms.

Sorting Let’s see if we can come up with one on our own...

Sorting Let’s see if we can come up with one on our own... array A (N = A.length): sorted array A: i 1 2 3 4 5 A 55 19 100 45 87 33 i 1 2 3 4 5 A 19 33 45 55 87 100

Sorting Compare values at indices 0 and 1 first. i 1 2 3 4 5 A 55 19 1 2 3 4 5 A 55 19 100 45 87 33

Sorting Compare values at indices 0 and 1 first. i 1 2 3 4 5 A 55 19 1 2 3 4 5 A 55 19 100 45 87 33

Sorting Compare values at indices 0 and 1 first. Swap if A[1] < A[0]: i 1 2 3 4 5 A 55 19 100 45 87 33 i 1 2 3 4 5 A 19 55 100 45 87 33

Sorting Compare values at indices 1 and 2. i 1 2 3 4 5 A 19 55 100 45 1 2 3 4 5 A 19 55 100 45 87 33

Sorting Compare values at indices 1 and 2. Is A[2] < A[1]? No: i 1 1 2 3 4 5 A 19 55 100 45 87 33 i 1 2 3 4 5 A 19 55 100 45 87 33

Sorting Compare values at indices 2 and 3. i 1 2 3 4 5 A 19 55 100 45 1 2 3 4 5 A 19 55 100 45 87 33

Sorting Compare values at indices 2 and 3. Is A[3] < A[2]? Yes! Swap. i 1 2 3 4 5 A 19 55 100 45 87 33 i 1 2 3 4 5 A 19 55 45 100 87 33

Sorting Keep repeating this process until you reach the end of the array.

Sorting Keep repeating this process until you reach the end of the array. Result: i 1 2 3 4 5 A 19 55 45 87 33 100

Sorting Largest value in the array is now at the end of the array. Result: i 1 2 3 4 5 A 19 55 45 87 33 100

Sorting What do we do next? i 1 2 3 4 5 A 19 55 45 87 33 100

Sorting What do we do next? Repeat the process. i 1 2 3 4 5 A 19 55 45 1 2 3 4 5 A 19 55 45 87 33 100

Sorting What do we do next? Repeat the process. Result: i 1 2 3 4 5 A 1 2 3 4 5 A 19 45 55 33 87 100

Sorting Have the second largest value at index N - 2 Result: i 1 2 3 4 1 2 3 4 5 A 19 45 55 33 87 100

Sorting Have the second largest value at index N - 2 How many more times to sort? Result: i 1 2 3 4 5 A 19 45 55 33 87 100

Sorting Have the second largest value at index N - 2 How many more times to sort? Total of N times Result: i 1 2 3 4 5 A 19 45 55 33 87 100

Sorting Have the second largest value at index N - 2 How many more times to sort? Total of N times Result: i 1 2 3 4 5 A 19 33 45 55 87 100 i 1 2 3 4 5 A 19 55 45 33 87 100

Bubble Sort This algorithm is known as “Bubble Sort”

Bubble Sort This algorithm is known as “Bubble Sort” The max value “bubbles” to the end of the list at each pass.

Bubble Sort This algorithm is known as “Bubble Sort” The max value “bubbles” to the end of the list at each pass. Simplest sorting algorithm.

Bubble Sort Let’s write the code for it:

Bubble Sort Let’s write the code for it: static void bubbleSort(int[] A, int N) { for(int i = 0; i < N; i++) { for (int j = 1; j < N; j++) { if (A[j] < A[j-1]) { // swap int temp = A[j]; A[j] = A[j-1]; A[j-1] = temp; }

Bubble Sort Let’s write the code for it: static void bubbleSort(int[] A, int N) { for(int i = 0; i < N; i++) { for (int j = 1; j < N; j++) { if (A[j] < A[j-1]) { // swap int temp = A[j]; A[j] = A[j-1]; A[j-1] = temp; }

Bubble Sort Let’s write the code for it: static void bubbleSort(int[] A, int N) { for(int i = 0; i < N; i++) { for (int j = 1; j < N; j++) { if (A[j] < A[j-1]) { // swap int temp = A[j]; A[j] = A[j-1]; A[j-1] = temp; }

Bubble Sort Let’s write the code for it: static void bubbleSort(int[] A, int N) { for(int i = 0; i < N; i++) { for (int j = 1; j < N; j++) { if (A[j] < A[j-1]) { // swap int temp = A[j]; A[j] = A[j-1]; A[j-1] = temp; }

Bubble Sort Let’s write the code for it: static void bubbleSort(int[] A, int N) { for(int i = 0; i < N; i++) { for (int j = 1; j < N; j++) { if (A[j] < A[j-1]) { // swap int temp = A[j]; A[j] = A[j-1]; A[j-1] = temp; }

Bubble Sort Efficiency How efficient is it?

Bubble Sort Efficiency How efficient is it? What is the O(..) of the algorithm?

Bubble Sort Efficiency Let’s look at one pass.

Bubble Sort Efficiency Let’s look at one pass. i 1 2 3 4 5 A 55 19 100 45 87 33

Bubble Sort Efficiency Let’s look at one pass. To: i 1 2 3 4 5 A 55 19 100 45 87 33 i 1 2 3 4 5 A 19 55 45 87 33 100

Bubble Sort Efficiency Let’s look at one pass. To: What’s the efficiency of this pass? i 1 2 3 4 5 A 55 19 100 45 87 33 i 1 2 3 4 5 A 19 55 45 87 33 100

Bubble Sort Efficiency Let’s look at one pass. To: What’s the efficiency of this pass? O(N) i 1 2 3 4 5 A 55 19 100 45 87 33 i 1 2 3 4 5 A 19 55 45 87 33 100

Bubble Sort Efficiency How many of these passes do we have?

Bubble Sort Efficiency How many of these passes do we have? N passes.

Bubble Sort Efficiency How many of these passes do we have? N passes. Efficiency: O(N) * N = O(N2)

Bubble Sort Efficiency How can we make the algorithm a little more efficient/faster?

Bubble Sort Efficiency static void bubbleSort(int[] A, int N) { for(int i = 0; i < N; i++) { for (int j = 1; j < (N-i); j++) { if (A[j] < A[j-1]) { // swap int temp = A[j]; A[j] = A[j-1]; A[j-1] = temp; }

Bubble Sort Efficiency static void bubbleSort(int[] A, int N) { for(int i = 0; i < N; i++) { for (int j = 1; j < (N-i); j++) { if (A[j] < A[j-1]) { // swap int temp = A[j]; A[j] = A[j-1]; A[j-1] = temp; } We know the end keeps getting sorted properly

Bubble Sort Efficiency But efficiency is still O(N2)

Bubble Sort Efficiency But efficiency is still O(N2) Thus bubble sort isn’t really a good sorting algorithm...

Bubble Sort Efficiency But efficiency is still O(N2) Thus bubble sort isn’t really a good sorting algorithm... Going to look at other alternatives.

Find the minimum in an array How will you find the minimum number in an array? i 1 2 3 4 5 A 55 19 100 45 87 33

Find the minimum in an array min = A[0] for i = 1 to A.length – 1: if A[i] < min: min = A[i]

Find the minimum in an array What can we do with the minimum value?

Find the minimum in an array What can we do with the minimum value? Swap it with the value at index 0

Find the minimum in an array What can we do with the minimum value? Swap it with the value at index 0 Repeat for the rest of the indices...

Find the minimum in an array What can we do with the minimum value? Swap it with the value at index 0 Repeat for the rest of the indices... Result: Sorted array!

Selection Sort static void selectionSort(int[] A) { for (int i = 0; i < A.length; i++) { int min = i; // index of minimum value for(int j = i; j <= A.length; j++) { if ( A[j] < A[min]) min = j; } // swap if (j != i) swap(A, i, j);

Selection Sort static void selectionSort(int[] A) { for (int i = 0; i < A.length - 1; i++) { int min = i; // index of minimum value for(int j = i; j <= A.length; j++) { if ( A[j] < A[min]) min = j; } // swap if (j != i) swap(A, i, j);

Selection Sort static void selectionSort(int[] A) { for (int i = 0; i < A.length - 1; i++) { int min = i; // index of minimum value for(int j = i; j <= A.length; j++) { if ( A[j] < A[min]) min = j; } // swap if (j != i) swap(A, i, j);

Selection Sort static void selectionSort(int[] A) { for (int i = 0; i < A.length - 1; i++) { int min = i; // index of minimum value for(int j = i + 1; j < A.length; j++) { if ( A[j] < A[min]) min = j; } // swap if (j != i) swap(A, i, j);

Selection Sort static void selectionSort(int[] A) { for (int i = 0; i < A.length - 1; i++) { int min = i; // index of minimum value for(int j = i + 1; j < A.length; j++) { if ( A[j] < A[min]) min = j; } // swap if (j != i) swap(A, i, j);

Selection Sort static void selectionSort(int[] A) { for (int i = 0; i < A.length - 1; i++) { int min = i; // index of minimum value for(int j = i + 1; j < A.length; j++) { if ( A[j] < A[min]) min = j; } // swap if (min != i) swap(A, i, min);

Selection Sort Efficiency

Selection Sort Efficiency Better than Bubble Sort

Selection Sort Efficiency Better than Bubble Sort But rarely used

Insertion Sort Concept: Go through every element, insert it in it’s correct position in the sub-array before it

Insertion Sort array A (N = A.length): i 1 2 3 4 5 A 55 19 100 45 87 1 2 3 4 5 A 55 19 100 45 87 33

Insertion Sort array A (N = A.length): Value = 55 Look at sub-array between indices 0 and 0 i 1 2 3 4 5 A 55 19 100 45 87 33

Insertion Sort array A (N = A.length): Value = 55 Look at sub-array between indices 0 and 0 Already sorted, let’s look at next index i 1 2 3 4 5 A 55 19 100 45 87 33

Insertion Sort array A (N = A.length): Value = 19 Look at sub-array between indices 0 and 1 i 1 2 3 4 5 A 55 19 100 45 87 33

Insertion Sort array A (N = A.length): Value = 19 Look at sub-array between indices 0 and 1 Is Value < A[0]? Yes! i 1 2 3 4 5 A 55 19 100 45 87 33

Insertion Sort array A (N = A.length): Value = 19 Look at sub-array between indices 0 and 1 Is Value < A[0]? Yes! Move 55 forward by 1 index. i 1 2 3 4 5 A 55 100 45 87 33

Insertion Sort array A (N = A.length): Value = 19 Look at sub-array between indices 0 and 1 Is Value < A[0]? Yes! Move 55 forward by 1 index. Put 19 at index 0 (reached the beginning) i 1 2 3 4 5 A 19 55 100 45 87 33

Insertion Sort array A (N = A.length): Value = 100 Look at sub-array between indices 0 and 2 i 1 2 3 4 5 A 19 55 100 45 87 33

Insertion Sort array A (N = A.length): Value = 100 Look at sub-array between indices 0 and 2 Is Value < A[1]? No. i 1 2 3 4 5 A 19 55 100 45 87 33

Insertion Sort array A (N = A.length): Value = 100 Look at sub-array between indices 0 and 2 Is Value < A[1]? No. Continue i 1 2 3 4 5 A 19 55 100 45 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 i 1 2 3 4 5 A 19 55 100 45 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[2]? Yes. i 1 2 3 4 5 A 19 55 100 45 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[2]? Yes. Move A[2] forward by one position i 1 2 3 4 5 A 19 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[1]? Yes. i 1 2 3 4 5 A 19 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[1]? Yes. i 1 2 3 4 5 A 19 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[1]? Yes. Move A[1] forward by one position i 1 2 3 4 5 A 19 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[0]? No. i 1 2 3 4 5 A 19 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[0]? No. i 1 2 3 4 5 A 19 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[0]? No. STOP! i 1 2 3 4 5 A 19 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Is Value < A[0]? No. STOP! Put Value at index 1 (where we stopped) i 1 2 3 4 5 A 19 45 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Note how this sub-array is sorted. i 1 2 3 4 5 A 19 45 55 100 87 33

Insertion Sort array A (N = A.length): Value = 45 Look at sub-array between indices 0 and 3 Note how this sub-array is sorted. Repeat for Value = 87 & sub-array between 0 and 4 i 1 2 3 4 5 A 19 45 55 100 87 33

Insertion Sort Exercise: Write the code by yourselves.

Insertion Sort Exercise: Write the code by yourselves. (Without looking it up online of course...) Try to challenge yourself

Insertion Sort Efficiency Also O(N2)

Insertion Sort Efficiency Also O(N2) But:

Insertion Sort Efficiency Also O(N2) But: Very fast for sorted/partially sorted arrays.

Insertion Sort Efficiency Also O(N2) But: Very fast for sorted/partially sorted arrays. Efficient for small data sets

Insertion Sort Efficiency Also O(N2) But: Very fast for sorted/partially sorted arrays. Efficient for small data sets Online: Sort a list as it receives input

Insertion Sort Efficiency Also O(N2) But: Very fast for sorted/partially sorted arrays. Efficient for small data sets Online: Sort a list as it receives input Better than Bubble and Selection Sort

Sorting None of the algorithms seen so far are “good enough”

Sorting None of the algorithms seen so far are “good enough” Especially Bubble and Selection

Sorting None of the algorithms seen so far are “good enough” Especially Bubble and Selection Merge Sort and QuickSort are the best algorithms

Sorting None of the algorithms seen so far are “good enough” Especially Bubble and Selection Merge Sort and QuickSort are the best algorithms Going to look at Merge Sort

Merge Sort Concept: Divide a list equally into two

Merge Sort Concept: Divide a list equally into two Sort the two lists

Merge Sort Concept: Divide a list equally into two Sort the two lists Merge them

Merge Sort Concept: Divide a list equally into two Sort the two lists Merge them Repeat process recursively

Merge Sort i 1 2 3 4 5 A 55 19 100 45 87 33

Merge Sort Split i 1 2 3 4 5 A 55 19 100 45 87 33 1 2 55 19 100 3 4 5 45 87 33

Merge Sort Split i 1 2 3 4 5 A 55 19 100 45 87 33 1 2 55 19 100 3 4 5 45 87 33 55 1 2 19 100

Merge Sort Split i 1 2 3 4 5 A 55 19 100 45 87 33 1 2 55 19 100 3 4 5 45 87 33 55 1 2 19 100 3 45 4 5 87 33

Merge Sort Split Now Sort and Merge i 1 2 3 4 5 A 55 19 100 45 87 33 1 1 2 3 4 5 A 55 19 100 45 87 33 1 2 55 19 100 3 4 5 45 87 33 55 1 2 19 100 3 45 4 5 87 33

Merge Sort 55 1 2 19 100

Merge Sort Already sorted Already Sorted 55 1 2 19 100

Merge Sort Already sorted Already Sorted Merge the two in the proper order: 55 1 2 19 100

Merge Sort Already sorted Already Sorted Merge the two in the proper order: s Sorted! 55 1 2 19 100 1 2 19 55 100

Merge Sort 3 45 55 4 5 87 33 1 2 19 100

Merge Sort Already sorted Sort it: 3 45 55 4 5 87 33 1 2 19 100

Merge Sort Already sorted Sort it: 3 45 55 4 5 87 33 1 2 19 100 4 5 33 55 4 5 87 33 1 2 19 100 4 5 33 87

Merge Sort Already sorted Sort it: Now Merge: 3 45 55 4 5 87 33 1 2 19 55 4 5 87 33 1 2 19 100 4 5 33 87 3 4 5 33 45 87

Merge Sort 1 2 19 55 100 3 4 5 33 45 87

Merge Sort Both already sorted. 1 2 19 55 100 3 4 5 33 45 87

Merge Sort Both already sorted. Merge: 1 2 19 55 100 3 4 5 33 45 87 i 1 2 19 55 100 3 4 5 33 45 87 i 1 2 3 4 5 A 19 33 45 55 87 100

Merge Sort mergeSort(A[]): if size(A) <= 1: return A // split into two lists middleIndex = size(A)/2 left[] = A[0…middleIndex-1] right[] = A[middleIndex…size(A)-1] left = mergeSort(left) right = mergeSort(right) result[] = merge(left, right) return result

Merge Sort mergeSort(A[]): if size(A) <= 1: return A // split into two lists middleIndex = size(A)/2 left[] = A[0…middleIndex-1] right[] = A[middleIndex…size(A)-1] left = mergeSort(left) right = mergeSort(right) result[] = merge(left, right) return result

Merge Sort mergeSort(A[]): if size(A) <= 1: return A // split into two lists middleIndex = size(A)/2 left[] = A[0…middleIndex-1] right[] = A[middleIndex…size(A)-1] left = mergeSort(left) right = mergeSort(right) result[] = merge(left, right) return result

Merge Sort mergeSort(A[]): if size(A) <= 1: return A // split into two lists middleIndex = size(A)/2 left[] = A[0…middleIndex-1] right[] = A[middleIndex…size(A)-1] left = mergeSort(left) right = mergeSort(right) result[] = merge(left, right) return result

Merge Sort mergeSort(A[]): if size(A) <= 1: return A // split into two lists middleIndex = size(A)/2 left[] = A[0…middleIndex-1] right[] = A[middleIndex…size(A)-1] left = mergeSort(left) right = mergeSort(right) result[] = merge(left, right) return result

Merge Sort mergeSort(A[]): if size(A) <= 1: return A // split into two lists middleIndex = size(A)/2 left[] = A[0…middleIndex-1] right[] = A[middleIndex…size(A)-1] left = mergeSort(left) right = mergeSort(right) result[] = merge(left, right) return result

Merge Sort mergeSort(A[]): if size(A) <= 1: return A // split into two lists middleIndex = size(A)/2 left[] = A[0…middleIndex-1] right[] = A[middleIndex…size(A)-1] left = mergeSort(left) right = mergeSort(right) result[] = merge(left, right) return result

Merge Sort mergeSort(A[]): if size(A) <= 1: return A // split into two lists middleIndex = size(A)/2 left[] = A[0…middleIndex-1] right[] = A[middleIndex…size(A)-1] left = mergeSort(left) right = mergeSort(right) result[] = merge(left, right) return result

Merge Sort How to merge two sorted lists?

Merge Sort How to merge two sorted lists? Figure that out yourself

Merge Sort How to merge two sorted lists? Figure that out yourself Try to to do it on paper first

Merge Sort How to merge two sorted lists? Figure that out yourself Try to to do it on paper first Exercise: Implement Merge Sort Can it be done iteratively?

Merge Sort Efficiency O(NlogN)

Merge Sort Efficiency O(NlogN) Much faster than the previous algorithms

Merge Sort Efficiency O(NlogN) Much faster than the previous algorithms Used in java.util.Arrays.sort(…)

Summary Sorting is a very important problem. Bubble, Selection and Insertion Sort. Insertion Sort great for small arrays. Merge Sort much faster than others