1 / 19

Science Fellows, Computer Science Lesson 1

Science Fellows, Computer Science Lesson 1. Fall 2010. Algorithm . Way to solve a problem (Write a program.) But, as computer SCIENTISTS we care about more than getting *a* solution. We want to know – how good a solution is it?. Example.

thuy
Download Presentation

Science Fellows, Computer Science Lesson 1

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. Science Fellows, Computer Science Lesson 1 Fall 2010

  2. Algorithm • Way to solve a problem (Write a program.) • But, as computer SCIENTISTS we care about more than getting *a* solution. We want to know – how good a solution is it?

  3. Example • Packs of word cards. Try to find the alphabetically first card in the pack. Count how many times you turn over a card. • Can’t memorize cards. • Usually keep the cards in numbered slots, but can switch them around or keep out a few “special” cards. • Only one card not in special slot can be turned over at a time. • With each step, the cards that aren’t in special slots have to get turned back over. • Can remember counts if you need to.

  4. Find alphabetically first card 1 5 2 6 3 • 7 8 4 Turn over count: 0

  5. Find alphabetically first card 1 Lane 5 2 6 3 • 7 8 4 Turn over count: 1

  6. Find alphabetically first card 1 5 Lane 2 6 3 • 7 8 4 Turn over count: 1

  7. Find alphabetically first card 1 5 Lane 2 6 Boy 3 • 7 8 4 Turn over count: 2

  8. Find alphabetically first card 1 5 Boy 2 6 3 • 7 8 4 Turn over count: 2

  9. Find alphabetically first card 1 5 Boy 2 6 3 • 7 Violin 8 4 Turn over count: 3

  10. Find alphabetically first card 1 5 Boy 2 6 3 • 7 8 4 Apple Turn over count: 4

  11. Find alphabetically first card 1 5 Apple 2 6 3 • 7 8 4 Turn over count: 4

  12. Examine Algorithm • How many times do I turn over a card? • What if I double the number of cards? • If there are n cards, how many times do I turn over a card?

  13. Your turn • Sort your cards alphabetically • We’ll see what algorithms we come up with and whose is best

  14. What if there are N cards? Some math you may want to know: 1+2+3+…+n = n(n-1)/2 Number of times I can cut the number n in half until I hit 1 = lg n

  15. Why do we care? exponential quadratic Num card turns (Time) linear logarithmic constant Number of cards ->

  16. 106 instructions/sec, runtimes

  17. So… • If my function is time = 2(n-1) all I really care about is that it is a LINEAR function. • What’s the best I can do for sorting, if I know NOTHING about my data? • What’s the best I can do for sorting if I do know something about my data?

  18. Searching • New problem: Find the card that has a given word on it. How long will it take? What could we do to make it fast?

  19. Back to the real world • Are these “real” problems? • Oh, yes! How does Google do such a good job? • They SORT (PageRank algorithm) better than the rest • They SEARCH quickly

More Related