Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 18: Selection Sort, Quicksort & Merge Sort Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

Similar presentations


Presentation on theme: "1 Lecture 18: Selection Sort, Quicksort & Merge Sort Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science."— Presentation transcript:

1 1 Lecture 18: Selection Sort, Quicksort & Merge Sort Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science

2 2 Revision: Comparing Growth Rates O(n)O(n) Faster Code O(n2)O(n2) O(n3)O(n3) O(n log n) O(log n) O(1) O(2n)O(2n) Textbook, p. 378 Binary Search Sequential Search

3 3 Selection Sort MOCP 0123 ETUR 4567 Textbook, p. 385-6  How does this algorithm execute the instructions? Show the steps on the next page.  What is it’s Big O notation?

4 4 MOCP 0123 ETUR 4567 Java Code, Textbook, p. 386-7

5 5 Selection Sort MOCP 0123 ETUR 4567 Selection Sort Analysis, Textbook, p. 387-388  What is Bubble Sort?  Is there a more efficient way than using Selection Sort or Bubble Sort?

6 6 Algorithm Efficiency Analysing Search Algorithms Limits of Big O Analysis Sorting Selection Sort Merge Sort Algorithm Analysis Quick Sort Algorithm Analysis

7 7 Merging Sorted Lists (L11.4) OMCP 0123 TREU 0123

8 8 Merge Sort MOCP 0123 ETUR 4567 Analysis, Textbook, p. 393-398

9 9 Merge Sort Analysis, Textbook, p. 393-398 COMP UT ER

10 10 Merge Sort Analysis, Textbook, p. 393-398 11 2 11 2 4 11 2 11 2 4 8 items

11 11 Algorithm Efficiency Analysing Search Algorithms Limits of Big O Analysis Sorting Selection Sort Merge Sort Algorithm Analysis Quick Sort Algorithm Analysis

12 12 Partitioning (as seen in L8) <p p ≥p≥p 93871 01234 71398 Textbook, p. 399

13 13 Assignment 3 private BinaryTreeNode parseTree(){ /*This is the method that helps you to create a binary tree (BinaryTreeNode) data structure. Return null if the TextField where the users put in the expression is empty. Otherwise store the expression into the binary tree data structure. If there are an invalid input i.e. input other than (x,y,z,1,2,3,+,-,*,/) then an error message should be displayed on the command window. */ return null; }

14 14 private BinaryTreeNode parseTree(){//recursive method to construct a BinaryTreeNode tree from // textString that was input, e.g. +12. if (textString.length() > 0) { BinaryTreeNode result, left, right; char c = textString.charAt(0); textString = textString.substring(1, textString.length()); //when do we create the children of the tree: if(…) { result = new BinaryTreeNode(“” + c); result.setLeft(…) //recursion… result.setRight(…) //recursion… return result; } //when do we create the leaves of the tree: else if(...) { return new BinaryTreeNode("" + c); } else { // error System.out.println("Parse error: invalid character: " + c); return …; // return null } else // return null }


Download ppt "1 Lecture 18: Selection Sort, Quicksort & Merge Sort Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science."

Similar presentations


Ads by Google