CrashCourse · @crashcourse
Data Structures: Crash Course Computer Science #14
Uploaded June 8, 2017 · Length 10:07
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.
- 0:03
Hi, I'm Carrie Anne, and welcome to Crash Course Computer Science!
- 0:05
Last episode, we discussed a few example classic algorithms, like sorting a list of numbers
- 0:09
and finding the shortest path in a graph.
- 0:11
What we didn’t talk much about, is how the data the algorithms ran on was stored in computer
- 0:16
memory.
- 0:16
You don’t want your data to be like John Green’s college dorm room, with food, clothing
- 0:19
and papers strewn everywhere.
- 0:21
Instead, we want our data to be structured, so that it’s organized, allowing things
- 0:25
to be easily retrieved and read.
- 0:27
For this, computer scientists use Data Structures!
- 0:29
INTRO
- 0:39
We already introduced one basic data structure last episode, Arrays, also called lists or
- 0:43
Vectors in some languages.
- 0:45
These are a series of values stored in memory.
- 0:47
So instead of just a single value being saved into a variable, like ‘j equals 5’, we
- 0:51
can define a whole series of numbers, and save that into an array variable.
- 0:55
To be able to find a particular value in this array, we have to specify an index.
- 0:59
Almost all programing languages start arrays at index 0, and use a square bracket syntax
- 1:04
to denote array access.
- 1:05
So, for example, if we want to add the values in the first and third spots of our array
- 1:10
‘j’, and save that into a variable ‘a’, we would write a line of code like this.
- 1:14
How an array is stored in memory is pretty straightforward.
- 1:16
For simplicity, let’s say that the compiler chose to store ours at memory location 1,000.
- 1:21
The array contains 7 numbers, and these are stored one after another in memory, as seen here.
- 1:26
So when we write “j index of 0”, the computer goes to memory location 1,000, with an offset
- 1:31
of 0, and we get the value 5.
- 1:33
If we wanted to retrieve “j index of 5”, our program goes to memory location 1000,
- 1:38
plus an offset of 5, which in this case, holds a value of 4.
- 1:42
It’s easy to confuse the fifth number in the array with the number at index 5.
- 1:45
They are not the same.
- 1:46
Remember, the number at index 5 is the 6th number in the array because the first number
- 1:50
is at index 0.
- 1:51
Arrays are extremely versatile data structures, used all the time, and so there are many functions
- 1:55
that can handle them to do useful things.
- 1:57
For example, pretty much every programming language comes with a built-in sort function,


