© 2004 Pearson Addison-Wesley. All rights reserved March 10, 2006 Sorting ComS 207: Programming I (in Java) Iowa State University, SPRING 2006 Instructor:

Slides:



Advertisements
Similar presentations
Garfield AP Computer Science
Advertisements

CompSci Searching & Sorting. CompSci Searching & Sorting The Plan  Searching  Sorting  Java Context.
Chapter 6: Arrays Java Software Solutions for AP* Computer Science
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 24 Sorting.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L17 (Chapter 23) Algorithm.
Midterm Exam Two Tuesday, November 25 st In class cumulative.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L18 (Chapter 23) Algorithm.
1 © 2006 Pearson Addison-Wesley. All rights reserved Searching and Sorting Linear Search Binary Search -Reading p
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Sorting and Searching Arrays CSC 1401: Introduction to Programming with Java Week 12 – Lectures 1 & 2 Wanda M. Kunkle.
Sorting in Linear Time Lower bound for comparison-based sorting
Upcoming schedule F 11/12 hw#4 due F 11/19 hw#5 due F 11/25 midterm #2.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Computer Science: A Structured Programming Approach Using C1 8-5 Sorting One of the most common applications in computer science is sorting—the process.
Searching and Sorting Topics Sequential Search on an Unordered File
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Chapter 10 B Algorithm Efficiency and Sorting. © 2004 Pearson Addison-Wesley. All rights reserved 9 A-2 Sorting Algorithms and Their Efficiency Sorting.
Chapter 2 Array Data Structure Winter Array The Array is the most commonly used Data Storage Structure. It’s built into most Programming languages.
 2005 Pearson Education, Inc. All rights reserved Searching and Sorting.
© 2004 Pearson Addison-Wesley. All rights reserved October 17, 2007 Searching (part 2) ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Objectives - 11  We will work with processing Arrays.  Objectives:  Describe the concept of an array and its benefits.  Define the terms index, traverse,
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
© 2004 Pearson Addison-Wesley. All rights reserved October 13, D Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor:
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
© 2004 Pearson Addison-Wesley. All rights reserved October 19, 2007 Sorting ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 26 Sorting.
© 2006 Pearson Addison-Wesley. All rights reserved10 B-1 Chapter 10 (continued) Algorithm Efficiency and Sorting.
Introduction to C++ Programming Language Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University,
© 2004 Pearson Addison-Wesley. All rights reserved October 15, 2007 Searching ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Selection Sort Sorts an array by repeatedly finding the smallest.
Final Exam Tuesday, December 22nd 2:00 - 3:50pm room 102 Warren Weaver Hall.
Quick sort, lower bound on sorting, bucket sort, radix sort, comparison of algorithms, code, … Sorting: part 2.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 25 Sorting.
Chapter 8 Searching and Sorting © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
PREVIOUS SORTING ALGORITHMS  BUBBLE SORT –Time Complexity: O(n 2 ) For each item, make (n –1) comparisons Gives: Comparisons = (n –1) + (n – 2)
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
19 March More on Sorting CSE 2011 Winter 2011.
Searching and Sorting Arrays Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 15-16, 2013.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 26 Sorting.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 23 Sorting.
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review Prof. Katherine Gibson.
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review Prof. Katherine Gibson Prof. Jeremy Dixon.
Sorting Lower Bound 4/25/2018 8:49 PM
CMSC201 Computer Science I for Majors Lecture 27 – Final Exam Review
Topics discussed in this section:
Sorting Data are arranged according to their values.
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Searching and Sorting Topics Sequential Search on an Unordered File
Sorting October 20, 2006 ComS 207: Programming I (in Java)
كلية المجتمع الخرج البرمجة - المستوى الثاني
CprE 185: Intro to Problem Solving (using C)
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
Sorting Data are arranged according to their values.
Searching and Sorting Topics Sequential Search on an Unordered File
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review
Algorithmic Complexity
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
Presentation transcript:

© 2004 Pearson Addison-Wesley. All rights reserved March 10, 2006 Sorting ComS 207: Programming I (in Java) Iowa State University, SPRING 2006 Instructor: Alexander Stoytchev

© 2004 Pearson Addison-Wesley. All rights reserved Midterm 2: Kildee Hall, room 125

© 2004 Pearson Addison-Wesley. All rights reserved Tuesday Mar 6:30 pm

© 2004 Pearson Addison-Wesley. All rights reserved Midterm Format Covers Sections 1-5 & 7 Also, Searching and Sorting Format same as Midterm 1

© 2004 Pearson Addison-Wesley. All rights reserved Midterm Format True/False(10 x 1p each = 10p) Short answer( 5 x 2p each = 10p) Code Snippets( 5 x 3p each = 15p) Other Stuff( 3 x 5p each = 15p) Program 1(15p) Program 2(15p) Program 3(15p) Program 4(20p) TOTAL (130p)

© 2004 Pearson Addison-Wesley. All rights reserved Midterm Format You don’t need to get all 130 points to get an A 100 is a 100 You must get at least 65 points in order to pass this exam

© 2004 Pearson Addison-Wesley. All rights reserved Quick review of last lecture

© 2004 Pearson Addison-Wesley. All rights reserved Arrays in Java Java represents 2D arrays as an array of arrays! In other words, a 2D integer array is really a 1D array of references to 1D integer arrays. The concept generalizes to N-dimensions

© 2004 Pearson Addison-Wesley. All rights reserved Anatomy of a 2D Array [

© 2004 Pearson Addison-Wesley. All rights reserved Example of a regular 2D array [ Note: In Java the first index should be 0 not 1!

© 2004 Pearson Addison-Wesley. All rights reserved Example of a Ragged Array [ Note: In Java the first index should be 0 not 1!

© 2004 Pearson Addison-Wesley. All rights reserved Example: Ragged2Darray.java

© 2004 Pearson Addison-Wesley. All rights reserved Binary Search At each step it splits the remaining array elements into two groups Therefore, it is faster than the linear search Works only on an already SORTED array Thus, there is a performance penalty for sorting the array [

© 2004 Pearson Addison-Wesley. All rights reserved [ Example: Successful Binary Search

© 2004 Pearson Addison-Wesley. All rights reserved Example: BinarySearch.java

© 2004 Pearson Addison-Wesley. All rights reserved

Analysis of Searching Methods For an array of size n Sequential Search (Average-Case) n/2 Sequential Search (Worst-Case) n Binary Search (Average-Case) log(n)/2 Binary Search (Worst-Case) log(n)

Sorting Not in the Textbook

© 2004 Pearson Addison-Wesley. All rights reserved Insertion Sort [ 0

© 2004 Pearson Addison-Wesley. All rights reserved [ Example: Insertion Sort

© 2004 Pearson Addison-Wesley. All rights reserved Animations of Sorting Algoritms

© 2004 Pearson Addison-Wesley. All rights reserved Animations for Insertion Sort [

© 2004 Pearson Addison-Wesley. All rights reserved Example: InsertionSort.java

© 2004 Pearson Addison-Wesley. All rights reserved Selection Sort [

© 2004 Pearson Addison-Wesley. All rights reserved Example: Selection Sort [

© 2004 Pearson Addison-Wesley. All rights reserved Example: SelectionSort.java

© 2004 Pearson Addison-Wesley. All rights reserved Bubble Sort [ 0

© 2004 Pearson Addison-Wesley. All rights reserved [ Example: Bubble Sort

© 2004 Pearson Addison-Wesley. All rights reserved Example: BubbleSort.java

© 2004 Pearson Addison-Wesley. All rights reserved Analysis: all three run in O(n 2 ) time [

© 2004 Pearson Addison-Wesley. All rights reserved Analysis There are faster sorting algorithms  Heap sort  Quick sort  Merge Sort We will not cover those but feel free to study them on your own. They run in O(n log n) time.

© 2004 Pearson Addison-Wesley. All rights reserved O(n log n) sorting algorithms [

© 2004 Pearson Addison-Wesley. All rights reserved THE END