CrashCourse · @crashcourse

Data Structures: Crash Course Computer Science #14

Uploaded June 8, 2017 · Length 10:07

Data Structures: Crash Course Computer Science #14

Summary

Learn about fundamental data structures like arrays, strings, matrices, structs, and linked lists, and how they organize data in computer memory.

  • computer science basics
  • data structures explained
  • arrays and strings
  • matrices and structs
  • linked lists tutorial
  • computer memory organization

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 Crash Course Computer Science!

  2. 0:05

    Last episode, we discussed a few example classic algorithms, like sorting a list of numbers

  3. 0:09

    and finding the shortest path in a graph.

  4. 0:11

    What we didn’t talk much about, is how the data the algorithms ran on was stored in computer

  5. 0:16

    memory.

  6. 0:16

    You don’t want your data to be like John Green’s college dorm room, with food, clothing

  7. 0:19

    and papers strewn everywhere.

  8. 0:21

    Instead, we want our data to be structured, so that it’s organized, allowing things

  9. 0:25

    to be easily retrieved and read.

  10. 0:27

    For this, computer scientists use Data Structures!

  11. 0:29

    INTRO

  12. 0:39

    We already introduced one basic data structure last episode, Arrays, also called lists or

  13. 0:43

    Vectors in some languages.

  14. 0:45

    These are a series of values stored in memory.

  15. 0:47

    So instead of just a single value being saved into a variable, like ‘j equals 5’, we

  16. 0:51

    can define a whole series of numbers, and save that into an array variable.

  17. 0:55

    To be able to find a particular value in this array, we have to specify an index.

  18. 0:59

    Almost all programing languages start arrays at index 0, and use a square bracket syntax

  19. 1:04

    to denote array access.

  20. 1:05

    So, for example, if we want to add the values in the first and third spots of our array

  21. 1:10

    ‘j’, and save that into a variable ‘a’, we would write a line of code like this.

  22. 1:14

    How an array is stored in memory is pretty straightforward.

  23. 1:16

    For simplicity, let’s say that the compiler chose to store ours at memory location 1,000.

  24. 1:21

    The array contains 7 numbers, and these are stored one after another in memory, as seen here.

  25. 1:26

    So when we write “j index of 0”, the computer goes to memory location 1,000, with an offset

  26. 1:31

    of 0, and we get the value 5.

  27. 1:33

    If we wanted to retrieve “j index of 5”, our program goes to memory location 1000,

  28. 1:38

    plus an offset of 5, which in this case, holds a value of 4.

  29. 1:42

    It’s easy to confuse the fifth number in the array with the number at index 5.

  30. 1:45

    They are not the same.

  31. 1:46

    Remember, the number at index 5 is the 6th number in the array because the first number

  32. 1:50

    is at index 0.

  33. 1:51

    Arrays are extremely versatile data structures, used all the time, and so there are many functions

  34. 1:55

    that can handle them to do useful things.

  35. 1:57

    For example, pretty much every programming language comes with a built-in sort function,