1 / 10

Array Sorting Algorithms

Array Sorting Algorithms. for(int I = 0; I < 10; i++) { System.out.println( “ I = “ +I); } No difference in for loop but there is a difference when using in an expression i++ - Use the current value of I in the expression then increment by 1. for(int I = 0; I < 10; ++i) {

kalyca
Télécharger la présentation

Array Sorting Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Array Sorting Algorithms

  2. for(int I = 0; I < 10; i++) { System.out.println(“I = “ +I); } No difference in for loop but there is a difference when using in an expression i++ - Use the current value of I in the expression then increment by 1 for(int I = 0; I < 10; ++i) { System.out.println(“I = “ +I); } No difference in for loop ++I – increment by 1, the nuse the new value in the expression Comparing I++ and ++I

  3. Sorting an Array • One of the most important computing applications • Sorting data is computer intensive -- much research has gone into finding good algorithms • Choice of algorithm affects • Run time • Memory usage

  4. Sorting Algorithms • Selection Sort • Insertion Sort • Merge Sort

  5. Big-O • Describes and algorithms efficiency in terms of the work required to solve a problem

  6. Selection Sort Select sort runs in O(n2) time The outer loops runs n-1 times The inner loop runs n -1 times, then n- 2 times, then n-3 times…. 1 Inner loops runs a total of n(n-1)/2 times In Big-O notation, the smaller term drops out so it is O(n2)

  7. Insertion Sort • Runs in O(n2) • Outer loop runs n-1 times • Worst case, while loop runs n-1 times

  8. Next Time • Merge sort • Bubble sort

  9. Conway’s Game of Life • Partner Problem • Solution is on the web • You will need to explain HOW you and your partner created a solution to the Game of Life in detail. • There will be a Game of Life “Quiz” on the due date where you will answer these questions

More Related