1 / 6

Series Warmup

Series Warmup. A really bad way to maintain order. Given a list L in order Suppose elements get added dynamically Problem is to keep it in order Joe has a sort function available Sort(L ) He learned in CS50 not to reinvent any wheels

diallo
Download Presentation

Series Warmup

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. Series Warmup

  2. A really bad way to maintain order Given a list L in order Suppose elements get added dynamically Problem is to keep it in order Joe has a sort function available Sort(L) He learned in CS50 not to reinvent any wheels So when a new element x arrives he appends it to the end of L: L <- append(L,x) and then calls Sort(L) Unbeknownst to Joe, Sort does a bubble sort How many item comparisons, starting from an empty list and adding n elements?

  3. Recall Bubble Sort Analysis ((n-1)∙n)/2 comparisons to sort a list of length n So But what is the sum of the first n squares?

  4. n=4, sum of first 4 squares Area = n across and tall How big is the white space? Let

  5. Of course this is Θ(n3)!

  6. FINIS

More Related