Presentation is loading. Please wait.

Presentation is loading. Please wait.

Many slides borrowed lovingly from Skiena

Similar presentations


Presentation on theme: "Many slides borrowed lovingly from Skiena"— Presentation transcript:

1 Many slides borrowed lovingly from Skiena
Divide and Conquer Anya E Vostinar Grinnell College Many slides borrowed lovingly from Skiena

2 Outline Homework reqs Divide and Conquer Find the median
Implementation on HackerRank No office hours today

3 Homework requirements
Above all, it must run without error If names are specified in assignment, you must use them (for my testing) Include instructions in a README for how to run everything, make my life easy Every function must have a header comment explaining what it does Use sensible variable and function names Make up ONLY THIS FIRST TIME due 9/11/2017 at 10:30pm

4 What is divide and conquer
Originally: military strategy Now: also an algorithm design technique Divide problem into (two?) smaller problems Solve them recursively Meld two partial solutions into one solution Which should take more time: Solving the (two?) subproblems or merging them? What are some examples?

5 Find the Median Given a set of ‘n’ unordered numbers we want to find the ”kth” smallest number (k is an integer between 1 and n) Talk to your neighbor about how to find the median in a given list of numbers

6 Sort it! Sort the list, what is the Big-Oh?
Let’s do better using divide and conquer!

7 Divide and Conquer recipe
Split the problem into smaller problems How? Solve those smaller problems Combine the solved smaller problems Big-Oh of worst case? Average case?

8 Divide and Conquer recipe
Split the problem into smaller problems Randomly! Solve those smaller problems Put everything onto proper side of pivot, recurse on correct side if needed Combine the solved smaller problems Don’t need to! Big-Oh: worst case n^2, average case n, so generally used

9 Implement it! Go to median/problem to implement it yourself


Download ppt "Many slides borrowed lovingly from Skiena"

Similar presentations


Ads by Google