Data Structures & Algorithms #1 - What Are Data Structures?

CS Dojo
11 Mar 201816:35

Summary

TLDRIn this informative video, YK, a former Google software developer, introduces viewers to the fundamental concepts of data structures and algorithms. Through relatable examples like a neighborhood map and a party scenario, YK illustrates how different data structures, such as arrays and linked lists, can be used to store and retrieve information efficiently. The video emphasizes the importance of these concepts in writing effective software, showcasing their practical applications and encouraging viewers to apply their learning through problem-solving.

Takeaways

  • πŸ‘‹ Introduction: YK, a former Google software developer, now runs a YouTube channel focusing on data structures and algorithms.
  • πŸ“š Definition: Data structures are different ways of storing data on a computer, essential for organizing information efficiently.
  • πŸ—ΊοΈ Example Scenario: A neighborhood mapping system using coordinates and street connections to illustrate the need for data structuring.
  • πŸ” Data Representation: Two methods discussed for representing data - a list of paths and a table of connections between places.
  • πŸ”‘ Data Structures Identified: The list corresponds to an array or list structure, while the table is akin to a hash table or hash map.
  • πŸ€– Algorithms Defined: A set of operations performed on data structures, providing step-by-step instructions to solve problems.
  • πŸ›£οΈ Shortest Path Problem: An example of using algorithms to find the shortest path in a neighborhood, highlighting the systematic approach required.
  • πŸ› οΈ Efficiency Importance: Emphasizing the importance of data structures and algorithms in writing efficient software, with a personal anecdote from YK's experience at Microsoft.
  • πŸŽ‰ Party Scenario: A light-hearted example using a party with named balls to compare array and linked list data structures in real-life situations.
  • ➑️ Resizing Data Structures: Discussing the ease of resizing linked lists versus arrays, and when each might be preferable based on expected data size.
  • πŸ“ Learning Application: Stressing the importance of applying learned concepts through problem-solving for better understanding and practical use.
  • 🌟 Resource Recommendation: YK recommends 'brilliant.org' for an interactive learning experience in computer science fundamentals, including algorithms.

Q & A

  • What is the one-sentence description of data structures according to the video?

    -Data structures are different ways of storing data on your computer.

  • What is an example of a data structure used to represent a neighborhood map with streets and locations?

    -One example is using a list to store all possible paths between locations, or using a hash table to map each location to all the places one can go from that location.

  • What is the difference between an array and a hash table as described in the video?

    -An array or list stores items sequentially, while a hash table or hash map uses key-value pairs to store data, allowing for faster access to elements based on keys.

  • What is an algorithm according to the video?

    -An algorithm is a set of operations performed on data structures and a set of instructions for executing them.

  • Can you explain the example of finding the shortest path from home to school in the video?

    -The example involves finding all possible paths from home to school, calculating the distance for each path using coordinates, and then selecting the path with the shortest distance.

  • How does the choice of data structure affect the implementation of an algorithm?

    -The choice of data structure can make certain operations more efficient or straightforward. For instance, finding all possible places from home is easier with a hash table than with a list.

  • What is the real-life example given in the video to illustrate data structures?

    -The real-life example is a party where guests bring balls with their names written on them, which can be stored in an array-like box with partitions or a linked list of individual boxes.

  • Why is it easier to fix a misspelled name in an array compared to a linked list?

    -In an array, you can directly access the 98th element by calculating its position, whereas in a linked list, you would need to traverse the list from the beginning to find the 98th element.

  • How does the video illustrate the advantage of a linked list over an array when more guests arrive unexpectedly?

    -With a linked list, you can easily add more boxes to the end without affecting the existing structure, whereas with an array, you might need to create a new array with more partitions or transfer elements to a new array.

  • What is the importance of learning data structures and algorithms as emphasized in the video?

    -Learning data structures and algorithms helps in writing efficient software, as demonstrated by the example of code optimization that reduced data retrieval time from hours to minutes.

  • How does the video suggest practicing and applying knowledge of data structures and algorithms?

    -The video recommends using platforms like Brilliant.org to solve problems related to data structures and algorithms, which helps in understanding and applying the concepts in real-world situations.

Outlines

00:00

πŸ“š Introduction to Data Structures and Algorithms

YK, a former Google software developer, introduces the concept of data structures as different ways to store data on a computer. He uses the analogy of a neighborhood map system to illustrate the need for data structures to understand how locations are connected. The example includes storing coordinates and street connections, comparing list-based and table-based methods. The paragraph also explains algorithms as operations and instructions for data structures, using the shortest path problem as an example to demonstrate the need for systematic problem-solving in computer science.

05:02

πŸ›£οΈ Data Structures in Real-World Scenarios

The script continues with a detailed explanation of how data structures can be applied to real-world problems, such as finding the shortest path in a neighborhood using algorithms. YK discusses the impact of the choice of data structure on the implementation of an algorithm, using the examples of an array and a hash table. He also shares a personal experience from his time at Microsoft, where knowledge of data structures and algorithms significantly improved the efficiency of his code.

10:03

πŸŽ‰ Practical Examples of Data Structures

YK presents a hypothetical party scenario to further elucidate data structures. He contrasts the use of an array, represented by a long box with partitions, with a linked list, symbolized by individual boxes connected by strings. The example highlights the advantages and disadvantages of each structure, such as ease of access in an array versus ease of resizing in a linked list. The narrative emphasizes the importance of choosing the right data structure based on the specific requirements of a situation.

15:03

πŸš€ Embracing Data Structures and Problem Solving

The final paragraph emphasizes the importance of applying learned concepts through problem-solving. YK recommends Brilliant.org for interactive learning of computer science fundamentals, including algorithms, and mentions a special offer for the first 200 visitors from his channel. He concludes by expressing excitement about his first sponsor and invites viewers to join him in the next video for further exploration of data structures.

Mindmap

Keywords

πŸ’‘Data Structures

Data structures are the different ways of organizing and storing data in a computer so that it can be used efficiently. In the context of the video, they are essential for developing efficient software and algorithms. The script uses examples like a neighborhood map system and a party scenario to illustrate different data structures such as arrays and linked lists.

πŸ’‘Algorithms

Algorithms are a set of instructions or rules to be followed in order to solve a problem or perform a computation. The video defines them as operations performed on data structures and emphasizes their importance in creating efficient software solutions, such as finding the shortest path in a neighborhood map example.

πŸ’‘Software Developer

A software developer is a person who designs, codes, and maintains applications or systems software. The video's presenter, YK, identifies as a former software developer at Google, highlighting the relevance of data structures and algorithms in the field.

πŸ’‘Google Maps

Google Maps is a web service that provides detailed information about geographical locations and routes. The script uses it as an analogy for creating a neighborhood map system, emphasizing the need for efficient data storage and retrieval of location and connectivity information.

πŸ’‘Latitude and Longitude

Latitude and longitude are geographical coordinates that specify the north-south and east-west position of a point on the Earth's surface, respectively. In the video, they are used to pinpoint the exact location of places in the neighborhood map system example.

πŸ’‘One-Way Streets

One-way streets are roads that allow traffic to move in only one direction. The script uses one-way streets in the neighborhood map analogy to demonstrate the need for data structures that can represent directional connectivity between locations.

πŸ’‘Arrays

An array is a data structure consisting of a collection of elements, each identified by one or more indices. The video script uses the concept of an array to illustrate how a list of paths can be stored in a neighborhood map system.

πŸ’‘Hash Tables

A hash table, also known as a hash map, is a data structure that implements an associative array, a structure that can map keys to values. The script contrasts hash tables with arrays to show different methods of storing connectivity information in the neighborhood map system.

πŸ’‘Shortest Path

The shortest path problem involves finding the quickest or most direct route between two points. The video uses the example of finding the shortest path from home to school to explain how algorithms can be applied to solve practical problems using data structures.

πŸ’‘Efficient Software

Efficient software refers to programs that perform well in terms of speed and resource usage. The video emphasizes the importance of understanding data structures and algorithms to write efficient software, as illustrated by YK's experience at Microsoft.

πŸ’‘Brilliant.org

Brilliant.org is an educational platform that offers courses in various subjects, including computer science. The video mentions it as a resource for learning data structures and algorithms through problem-solving, with a special offer for viewers to support the channel.

Highlights

Introduction to the concept of data structures as different ways of storing data on a computer.

Use of a neighborhood map analogy to explain the need for data structures to represent connections and relationships.

Example of storing paths in a list format to represent one-way streets and their limitations.

Introduction of a table format to represent places and connections, illustrating the hash table or hash map data structure.

Definition of algorithms as operations performed on data structures and sets of instructions for executing them.

Illustration of finding the shortest path in a neighborhood using latitudes and longitudes as an example of an algorithmic problem.

Explanation of how data structures can affect the implementation and efficiency of algorithms.

Personal anecdote from the presenter's experience at Microsoft, highlighting the impact of data structures and algorithms on code performance.

Introduction of a party scenario to further explain the practical applications of data structures like arrays and linked lists.

Comparison of the advantages and disadvantages of using arrays versus linked lists in different situations.

Discussion on the importance of choosing the right data structure based on the specific requirements of a problem.

Emphasis on the practical importance of data structures and algorithms in writing efficient software.

Introduction to the concept of applying learned concepts through problem-solving to solidify understanding.

Promotion of Brilliant.org as a resource for learning computer science concepts through problem-solving.

Mention of a special offer for the first 200 people visiting Brilliant.org through a provided link, including a discount on the annual subscription.

Closing remarks by the presenter, expressing excitement about the first sponsor and looking forward to the next video.

Transcripts

play00:00

hey YouTube just in case you're new here

play00:02

my name is YK and I was formerly a

play00:05

software developer at Google and now I

play00:07

work on this YouTube channel full time

play00:09

and welcome to my data structures and

play00:11

algorithms series number one what are

play00:13

data structures so a one sentence

play00:16

description of what data structures are

play00:18

would be that there are basically

play00:20

different ways of storing data on your

play00:22

computer and this sentence might not be

play00:25

too clear right now so let me give you a

play00:27

more concrete example here let's say you

play00:29

want to make a system that's sort of

play00:31

like Google Maps for your neighborhood

play00:33

now let's say your neighborhood looks

play00:34

like this so your home is here and

play00:37

there's a store here and another store

play00:39

here and so on and there are some

play00:41

streets too so these arrows show that

play00:44

these are one-way streets there are a

play00:46

lot of one-way streets here and so for

play00:48

example you can go from store to store B

play00:51

but not the other way around and all the

play00:54

other lines here there are not arrows

play00:56

show that they are two-way streets and

play00:59

let's say that you already have each

play01:01

place is coordinates there are latitudes

play01:03

and longitudes stored on your computer

play01:06

like this as you can see from this table

play01:09

you can tell that the latitude of home

play01:12

is forty-nine point two and the

play01:15

longitude of home is minus one hundred

play01:18

twenty three point four and so on now

play01:20

from this table like information you can

play01:23

tell where each location is exactly

play01:25

where each point is exactly but you

play01:28

can't tell how these locations are

play01:31

connected with streets and where the

play01:33

streets are exactly so you need to

play01:35

figure a way to store that information

play01:37

somehow on your computer and there are

play01:39

actually a few different options for

play01:41

this one of those options will be to

play01:43

store all possible paths in a list like

play01:46

format so for example one of those paths

play01:49

will be from store a to home and another

play01:52

one will be home to store a and yet

play01:55

another path will be store a to store B

play01:58

and with that method your data might

play02:01

look like this and from this list like

play02:04

information you can tell that as we saw

play02:07

earlier you can go from home to store a

play02:10

and from store a to home and home

play02:13

to store B and so on but you can't go

play02:17

from store B to home because this is a

play02:19

one-way street and so there's no path

play02:22

from store B to home in this list okay

play02:25

so that's just one option another option

play02:28

might be to list each of these places

play02:30

and for each of those places just list

play02:33

all the places you can go from that

play02:35

place and with that method your data

play02:38

might look like this instead as you can

play02:41

see here we have table like information

play02:43

again where on the left hand side we

play02:46

have all the places listed home store a

play02:49

store B school and then intersection

play02:52

this one right here and on the right

play02:55

hand side for each of those places we

play02:57

have all the places you can go from

play02:59

there so from home you can go to store a

play03:03

store B and intersection as you can see

play03:06

here and from store a you can go to home

play03:09

or store B so these two methods are

play03:13

basically two different ways of storing

play03:15

exactly the same set of data and as you

play03:18

can see they have sort of different

play03:20

structures and so these are simplified

play03:24

examples of what data structures look

play03:26

like now if you're already familiar with

play03:28

data structures you might notice that

play03:30

the first method corresponds to the

play03:32

array or a list data structure and the

play03:35

second method corresponds to the hash

play03:37

table or hash map data structure okay so

play03:40

that's one simple example of what data

play03:43

structures are but this video series is

play03:45

called data structures and algorithms so

play03:48

what are algorithms one way to define

play03:51

what they are would be that there are

play03:53

the operations we can perform on

play03:55

different data structures and the sets

play03:57

of instructions for executing them so

play04:00

one example here might be something like

play04:02

this coming back to the previous example

play04:04

we had let's say you want to find the

play04:07

shortest path from home to school so in

play04:11

this problem by hand is pretty easy

play04:13

pretty much right away you can see that

play04:15

there are three potential paths from

play04:17

home to school one of them is this one

play04:20

just go to store a store B and then

play04:23

school another one is this one store B

play04:26

and this

play04:27

cool and another one the other one is

play04:29

from home to intersection to school and

play04:33

for these three paths just compare the

play04:36

distance that you need to travel for

play04:37

each of these paths and then pick the

play04:40

shortest one and to compute the distance

play04:42

that you need to travel for each of

play04:44

these paths you can for example use the

play04:47

longitudes and latitudes the coordinates

play04:49

of each of these places and find the

play04:52

distance in kilometers so solving this

play04:54

problem by hand is pretty much trivial

play04:57

but if you want to turn this into

play04:59

something a computer can understand you

play05:01

need to be much more systematic about it

play05:03

so to make this strategy something a

play05:06

computer can understand easily you might

play05:09

come up with a set of instructions like

play05:10

this one first of all find all the

play05:13

places you can go from home so in this

play05:16

example that's store a store B and then

play05:19

the intersection and then from each of

play05:22

those places find all the paths you can

play05:25

take from that place so from store a you

play05:28

can go to store B and from store B you

play05:31

can go to school and from intersection

play05:33

you can only go to school and as you go

play05:36

keep track of the distance you've

play05:38

traveled so far for each of those paths

play05:40

and keep repeating this process until

play05:43

you get to the school then if you happen

play05:46

to find multiple paths that allows you

play05:50

to go from home to school then compare

play05:52

the distance that you've traveled for

play05:54

each of those paths and finally find a

play05:56

path with the shortest distance traveled

play05:58

and then pick that as the shortest path

play06:01

okay so that's the result we were

play06:04

looking for in the first place and this

play06:06

is a good example of what an algorithm

play06:08

is basically you have a problem you're

play06:10

going to solve in this case finding the

play06:12

shortest path from home to school and

play06:14

then you have a set of systematic

play06:17

instructions for solving that problem

play06:19

now one thing to note here is that

play06:21

depending on what data structure you're

play06:24

using to store the data that you're

play06:27

performing the algorithm on your

play06:29

algorithm might look slightly

play06:31

differently you might even have in some

play06:34

cases completely different algorithms

play06:36

for solving the same problem depending

play06:38

on what data structure you're using

play06:40

in this particular example we talked

play06:43

about two different options for storing

play06:45

the information about where the streets

play06:48

are and how they connect different

play06:50

locations the first option was to just

play06:54

list all possible paths and remember

play06:57

that the first step in our algorithm was

play06:59

to find all the possible places you can

play07:02

go from home and to do that with the

play07:05

first stair structure this one right

play07:06

here you might actually need to go

play07:08

through the entire list because in this

play07:11

particular list we have three paths here

play07:14

from home but it's possible that we have

play07:17

another path from home right here at the

play07:19

end of the list so you need to go

play07:21

through the entire list just in case on

play07:24

the other hand if you use the second

play07:26

data structure that we discussed we have

play07:29

all the possible places you can go from

play07:30

home listed right here as a group so as

play07:35

soon as we find the home row in this

play07:38

table you won't need to go through the

play07:40

entire table anymore so in this

play07:42

particular example using the second

play07:44

structure actually makes it slightly

play07:46

easier to implement the algorithm that

play07:49

we discussed now there are structures

play07:51

and algorithms are really important to

play07:53

learn because they'll help you write

play07:55

efficient software as a software

play07:56

developer so for example when I was

play07:59

working at Microsoft as a data science

play08:02

intern I had to write this piece of code

play08:04

to retrieve some data and when I wrote

play08:07

it originally it was taking like seven

play08:09

to ten hours and basically it was too

play08:11

slow because we didn't want we didn't

play08:13

want to wait that long so I rewrote it

play08:16

using my knowledge of data structures

play08:18

and algorithms and after rewriting it

play08:20

the new version only took like five to

play08:23

ten minutes to load that data so that's

play08:26

why learning them is important and it's

play08:28

actually useful in many practical

play08:30

situations that you might encounter as a

play08:32

software developer - okay to give you an

play08:34

even better idea about what data

play08:36

structures are like let me give you

play08:38

another example here let's say you're

play08:41

hosting a party and you're expecting a

play08:43

bunch of people and this example is

play08:45

gonna be a little bit silly but just

play08:47

follow along and you're gonna see why

play08:49

I'm talking about this particular

play08:50

example anyway let's say that each

play08:53

person

play08:54

come to the party we'll bring sort of

play08:57

like a small ball with them like a ball

play08:59

that can fit in their hand and this ball

play09:02

will have their name written on it so

play09:04

when David comes to the party he'll have

play09:07

a ball with David written on it and when

play09:11

Kevin arrives to the party he'll have a

play09:13

ball with Kevin written on it and so on

play09:16

and this is just a silly little system

play09:18

that you came up with for keeping track

play09:21

of who came to the party in which order

play09:23

because writing now each person's name

play09:26

would be a lot of work you're just too

play09:28

busy hosting a party so as someone who's

play09:31

studying computer science let's say

play09:33

you're trying to come up with an

play09:34

efficient system for storing these balls

play09:37

so that you can keep track of who came

play09:39

to the party one idea you have is this

play09:42

one you get a very long box with 100

play09:46

partitions a lot of partitions and each

play09:49

partition let's say has exactly the same

play09:51

shape you know 10 centimeters by 10

play09:54

centimeters let's say and every time

play09:56

someone comes to the party you're just

play09:58

gonna put that person's ball with their

play10:01

name written on it in the order they

play10:03

came to the party so David's ball will

play10:05

come in here and Kevin's will come in

play10:07

here and so on and this is actually sort

play10:10

of like a data structure that's realized

play10:12

in real life and this actually

play10:15

corresponds to the data structure called

play10:17

array in computer science and here's

play10:20

another idea you have you get a bunch of

play10:23

boxes and this time instead of getting a

play10:26

long box with many many partitions you

play10:29

want to get individual boxes that are

play10:31

connected with strings so the first box

play10:34

is connected to the second box with a

play10:36

string and that's connected to the third

play10:39

box with a string and so on and just

play10:41

like before you want to put these tokens

play10:44

with participants names written on them

play10:46

in these boxes just one by one in the

play10:49

order they came in so David's token will

play10:52

come in here and Kevin's ball will come

play10:54

in here and so on and this sort of data

play10:57

structure that's realized in real life

play10:59

corresponds to the linked list data

play11:02

structure in computer science okay so

play11:04

the natural question here would be which

play11:07

data structure

play11:08

use for this party well it actually

play11:11

depends because it highly depends on the

play11:14

particular situation and the nature of

play11:16

the party really and each data structure

play11:18

has advantages and disadvantages okay

play11:21

think about this situation let's say 100

play11:24

people showed up to your party and

play11:26

you're pretty happy about it but

play11:28

suddenly you realize that the 98th

play11:30

person is Paul had been misspelled that

play11:33

person's name had been misspelled so you

play11:35

want to fix that with the array data

play11:37

structure it's actually pretty easy you

play11:39

just need to find the 98th partition and

play11:42

that exact location can be calculated

play11:45

easily because you know that each

play11:48

partition is ten centimeters wide so you

play11:51

just need to find ten centimeters times

play11:54

ninety seven actually which is nine

play11:57

hundred seventy centimeters so you just

play12:00

need to walk over from the beginning

play12:02

nine hundred seventy centimeters and

play12:04

then you can find the 98th person's

play12:07

token pretty easily you just need to

play12:09

replace that with the correct token with

play12:11

the link list data structure though

play12:13

doing the same thing would be slightly

play12:15

more tricky and that's because finding

play12:17

the 98th person or finding the 98th box

play12:21

here would be much harder and the reason

play12:24

for that is because these strings are

play12:27

pretty soft and they can be pretty much

play12:30

any lengths so each box can be in any

play12:34

location relative to the previous box so

play12:37

this first box might be in the living

play12:39

room and the second box might be in the

play12:42

kitchen and so on so to find in 98th box

play12:45

what you need to do is you need to count

play12:47

them one by one so you need to say okay

play12:50

this is the first box and then this is

play12:52

the second box and let's find the third

play12:55

box fourth and so on until you get to

play12:58

the 98th person at this point you might

play13:00

say well the array data structure is a

play13:03

better one then well not necessarily so

play13:05

think about this situation let's say you

play13:08

have 100 people showing up to the party

play13:11

and you're pretty happy about it but

play13:13

suddenly five more people show up that

play13:15

you didn't expect with the linked list

play13:18

data structure it's pretty easy to deal

play13:20

with that you can just

play13:22

add five more boxes find five more boxes

play13:25

somewhere and then five more strings and

play13:27

just add them to the last box you had in

play13:32

the linked list data structure and then

play13:34

store the five people's tokens in those

play13:37

boxes with the array data structure

play13:40

though it's a little bit more tricky one

play13:42

option here would be to get another box

play13:45

with let's say 100 partitions again and

play13:49

store those people's tokens there and

play13:52

use the two boxes together or you could

play13:56

destroy the first box you had and then

play13:59

get a box with even more partitions

play14:02

let's say 200 partitions and then

play14:05

transfer all the balls you had for the

play14:07

first 100 people to the new box and then

play14:10

after that add the additional five

play14:13

people's tokens in the new box and in

play14:16

general if you have no idea how many

play14:18

people are coming to the party let's say

play14:21

anywhere between 5 to 1,000 people

play14:24

the linked list data structure might be

play14:27

slightly more convenient than the array

play14:29

because linked lists are so much easier

play14:32

to resize than it is to resize a race ok

play14:36

and this was another simplified example

play14:38

of what data structures are like on a

play14:41

computer and this sort of gives you a

play14:43

rough idea about how to actually start

play14:46

thinking about them and throughout this

play14:48

course I'm going to introduce you to

play14:50

even more data structures and this time

play14:52

I'm going to explain them in a much more

play14:54

technical way using concepts like

play14:56

classes objects memory and maybe even

play14:59

some code snippets too now if you're

play15:02

just getting started with data

play15:03

structures and algorithms one thing to

play15:05

keep in mind that's actually really

play15:07

important is to apply what you've

play15:09

learned through solving problems and the

play15:12

reason I say that is because it's so

play15:14

common for beginners to learn these

play15:16

concepts and not actually be able to use

play15:19

them in a real-world situation because

play15:21

they haven't had enough practice and

play15:23

actually this video sponsor brilliant

play15:25

org has an interesting website for

play15:28

learning these concepts in a sort of a

play15:30

new way ok to show you what I mean let's

play15:32

take a look at their computer science

play15:34

fundamentals course right

play15:35

here which I would recommend for you

play15:37

guys and let's go into the intro to

play15:39

algorithms section and you can see that

play15:41

it covers topics like arrays searching

play15:44

insertion sort and Big O notation and in

play15:47

the arrays section they have a bunch of

play15:49

explanations about the topic and as you

play15:52

continue you'll give you a quiz to test

play15:55

your understanding of the topic so it's

play15:58

definitely an interesting way to learn

play16:00

computer science concepts by solving

play16:02

problems okay if you want to check it

play16:04

out for yourself just go to brilliant

play16:06

org slash CS no joke

play16:08

and going to this link will actually

play16:10

help support this channel and the first

play16:13

200 people will get 20% off the annual

play16:16

subscription and actually I'm super

play16:19

excited about this because they're the

play16:21

first sponsor I have on this YouTube

play16:23

channel and I feel like I'm becoming a

play16:25

professional youtuber finally so thanks

play16:27

for that brilliant ok as always I'm YK

play16:30

from CS dojo thanks for watching and

play16:32

I'll see you guys in the next video

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Data StructuresAlgorithmsSoftware DevelopmentGoogleYouTube ChannelEducational SeriesMaps SystemPathfindingEfficiencyComputer ScienceParty Example