Transcript PPT

CS 112 - Fall 2012, Lab 02

Haohan Zhu

CS 112 - Fall 2012, Lab 02

Sorting Algorithm Boston University

Slideshow Title Goes Here     Selection Sort Insertion Sort Merge Sort Quick Sort  Sorting algorithm from the lectures 5/2/2020

2

CS 112 - Fall 2012, Lab 02

Sorting Algorithm Boston University

Slideshow Title Goes Here

Best Average Selection sort Insertion sort Merge sort Quick sort

n^2 n nlogn nlogn n^2 n^2 nlogn nlogn

Worst

n^2 n^2 nlogn n^2

Memory

1 1 n logn 5/2/2020

3

CS 112 - Fall 2012, Lab 02

Sorting Algorithm Boston University

Slideshow Title Goes Here   Shell sort Heapsort  Sorting algorithm from the textbook 5/2/2020

4

CS 112 - Fall 2012, Lab 02

Sorting Algorithm Boston University

Slideshow Title Goes Here     Bubble sort Cocktail sort Timsort (Java) …  Other sorting algorithms 5/2/2020

5

CS 112 - Fall 2012, Lab 02

Sorting Algorithm Boston University

Slideshow Title Goes Here   Sorting algorithms on Wikipedia Popular algorithms but not a full list 5/2/2020

6

CS 112 - Fall 2012, Lab 02

Sorting Algorithm in Java Boston University

Slideshow Title Goes Here  Class Collections   sort(List list) sort(List list, Comparator c)  Class Arrays  sort() for Primitive Types and Objects  PriorityQueue 5/2/2020

7

CS 112 - Fall 2012, Lab 02

Practice Boston University

Slideshow Title Goes Here  Implementing Bubble Sort  Compare two adjacent elements and sort them 7 1 1 1 7 5 5 5 7 3 3 3 8 8 8 4 4 4 6 6 6 2 2 2 5/2/2020

8

CS 112 - Fall 2012, Lab 02

Practice Boston University

Slideshow Title Goes Here  Bubble Sort or Cocktail Sort  Different directions 7 1 1 1 7 5 5 5 7 3 3 3 8 8 8 4 4 4 6 6 6 2 2 2 5/2/2020

9