UE CS 215 - Lecture 37 (18 pages)

Previewing pages 1, 2, 3, 4, 5, 6 of 18 page document View the full content.
View Full Document

Lecture 37



Previewing pages 1, 2, 3, 4, 5, 6 of actual document.

View the full content.
View Full Document
View Full Document

Lecture 37

84 views


Pages:
18
School:
University of Evansville
Course:
Cs 215 - Fundamentals of Programming II
Fundamentals of Programming II Documents

Unformatted text preview:

Lecture 37 Log into Linux We will be adding code to files sort h and sort examples cpp from last class Reminder Homework 13 due today Reminder Project 7 due on Friday No class on Friday CS Senior Project presentations 1 00 2 30 or so in KC 267 Office hours 3 4 30 Project 8 posted includes material to be covered next week due last day of class Questions Wednesday April 13 CS 215 Fundamentals of Programming II Lecture 37 1 Outline More Sorting Quicksort 2nd half of Section 13 2 More algorithm analysis O nlog2n running time Worst case average case Wednesday April 13 CS 215 Fundamentals of Programming II Lecture 37 2 Sorting Recall Applications often require data to be sorted For a vector v with n elements this means the elements are arranged such that v 0 v 1 v n 2 v n 1 There are lots of different algorithms Last time we look at a couple of slow O n 2 algorithms Today we will look at a fast algorithm Wednesday April 13 CS 215 Fundamentals of Programming II Lecture 37 3 Divide and Conquer One class of recursive algorithms is called divide and conquer The basic idea is to divide the problem in two or more approximately equal sized subproblems solve them directly or recursively then combine the subproblem results into the result for the original problem Section 13 2 covers two sorting algorithms mergesort and quicksort that use this method We will cover only quicksort Wednesday April 13 CS 215 Fundamentals of Programming II Lecture 37 4 Quicksort Note the textbook presents a method for sorting arrays that uses pointer arithmetic We will be sorting vectors so we will be using indexes first last to indicate the range to be sorted One of the reasons that sorting algorithms like selection and insertion sort are so slow is that the exchanges do not move the elements very far Quicksort attempts to speed this up by making the exchanges more effective Wednesday April 13 CS 215 Fundamentals of Programming II Lecture 37 5 Quicksort The basic idea of quicksort is to arrange the



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Lecture 37 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 37 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?