CrashCourse · @crashcourse

Intro to Algorithms: Crash Course Computer Science #13

Uploaded June 8, 2017 · Length 11:44

Intro to Algorithms: Crash Course Computer Science #13

Summary

Learn about algorithms, how they work, and compare selection sort and merge sort's efficiency using Big O notation.

  • introduction to algorithms
  • selection sort explained
  • merge sort explained
  • algorithm complexity
  • big O notation

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:03

    Hi, I’m Carrie Anne, and welcome to CrashCourse Computer Science!

  2. 0:05

    Over the past two episodes, we got our first taste of programming in a high-level language,

  3. 0:10

    like Python or Java.

  4. 0:11

    We talked about different types of programming language statements – like assignments,

  5. 0:14

    ifs, and loops – as well as putting statements into functions that perform a computation,

  6. 0:18

    like calculating an exponent.

  7. 0:20

    Importantly, the function we wrote to calculate exponents is only one possible solution.

  8. 0:24

    There are other ways to write this function – using different statements in different

  9. 0:27

    orders – that achieve exactly the same numerical result.

  10. 0:30

    The difference between them is the algorithm, that is the specific steps used to complete

  11. 0:34

    the computation.

  12. 0:35

    Some algorithms are better than others even if they produce equal results.

  13. 0:38

    Generally, the fewer steps it takes to compute, the better it is, though sometimes we care

  14. 0:42

    about other factors, like how much memory it uses.

  15. 0:45

    The term algorithm comes from Persian polymath Muḥammad ibn Mūsā al-Khwārizmī who was

  16. 0:49

    one of the fathers of algebra more than a millennium ago.

  17. 0:52

    The crafting of efficient algorithms – a problem that existed long before modern computers

  18. 0:56

    – led to a whole science surrounding computation, which evolved into the modern discipline of…

  19. 1:00

    you guessed it!

  20. 1:01

    Computer Science!

  21. 1:02

    INTRO

  22. 1:11

    One of the most storied algorithmic problems in all of computer science is sorting… as

  23. 1:15

    in sorting names or sorting numbers.

  24. 1:18

    Computers sort all the time.

  25. 1:19

    Looking for the cheapest airfare, arranging your email by most recently sent, or scrolling

  26. 1:23

    your contacts by last name -- those all require sorting.

  27. 1:27

    You might think “sorting isn’t so tough… how many algorithms can there possibly be?”

  28. 1:30

    The answer is: a lot.

  29. 1:32

    Computer Scientists have spent decades inventing algorithms for sorting, with cool names like

  30. 1:36

    Bubble Sort and Spaghetti Sort.

  31. 1:38

    Let’s try sorting!

  32. 1:39

    Imagine we have a set of airfare prices to Indianapolis.

  33. 1:42

    We’ll talk about how data like this is represented in memory next week, but for now, a series

  34. 1:47

    of items like this is called an array.

  35. 1:49

    Let’s take a look at these numbers to help see how we might sort this programmatically.

  36. 1:52

    We’ll start with a simple algorithm.

  37. 1:55

    First, let’s scan down the array to find the smallest number.

  38. 1:58

    Starting at the top with 307.

  39. 1:59

    It’s the only number we’ve seen, so it’s also the smallest.