Data Structures & Algorithms #1 - What Are Data Structures?
Skills:
Algorithm Basics80%
Key Takeaways
Introduces data structures and algorithms concepts for beginners
Full Transcript
hey YouTube just in case you're new here my name is YK and I was formerly a software developer at Google and now I work on this YouTube channel full time and welcome to my data structures and algorithms series number one what are data structures so a one sentence description of what data structures are would be that there are basically different ways of storing data on your computer and this sentence might not be too clear right now so let me give you a more concrete example here let's say you want to make a system that's sort of like Google Maps for your neighborhood now let's say your neighborhood looks like this so your home is here and there's a store here and another store here and so on and there are some streets too so these arrows show that these are one-way streets there are a lot of one-way streets here and so for example you can go from store to store B but not the other way around and all the other lines here there are not arrows show that they are two-way streets and let's say that you already have each place is coordinates there are latitudes and longitudes stored on your computer like this as you can see from this table you can tell that the latitude of home is forty-nine point two and the longitude of home is minus one hundred twenty three point four and so on now from this table like information you can tell where each location is exactly where each point is exactly but you can't tell how these locations are connected with streets and where the streets are exactly so you need to figure a way to store that information somehow on your computer and there are actually a few different options for this one of those options will be to store all possible paths in a list like format so for example one of those paths will be from store a to home and another one will be home to store a and yet another path will be store a to store B and with that method your data might look like this and from this list like information you can tell that as we saw earlier you can go from home to store a and from store a to home and home to store B and so on but you can't go from store B to home because this is a one-way street and so there's no path from store B to home in this list okay so that's just one option another option might be to list each of these places and for each of those places just list all the places you can go from that place and with that method your data might look like this instead as you can see here we have table like information again where on the left hand side we have all the places listed home store a store B school and then intersection this one right here and on the right hand side for each of those places we have all the places you can go from there so from home you can go to store a store B and intersection as you can see here and from store a you can go to home or store B so these two methods are basically two different ways of storing exactly the same set of data and as you can see they have sort of different structures and so these are simplified examples of what data structures look like now if you're already familiar with data structures you might notice that the first method corresponds to the array or a list data structure and the second method corresponds to the hash table or hash map data structure okay so that's one simple example of what data structures are but this video series is called data structures and algorithms so what are algorithms one way to define what they are would be that there are the operations we can perform on different data structures and the sets of instructions for executing them so one example here might be something like this coming back to the previous example we had let's say you want to find the shortest path from home to school so in this problem by hand is pretty easy pretty much right away you can see that there are three potential paths from home to school one of them is this one just go to store a store B and then school another one is this one store B and this cool and another one the other one is from home to intersection to school and for these three paths just compare the distance that you need to travel for each of these paths and then pick the shortest one and to compute the distance that you need to travel for each of these paths you can for example use the longitudes and latitudes the coordinates of each of these places and find the distance in kilometers so solving this problem by hand is pretty much trivial but if you want to turn this into something a computer can understand you need to be much more systematic about it so to make this strategy something a computer can understand easily you might come up with a set of instructions like this one first of all find all the places you can go from home so in this example that's store a store B and then the intersection and then from each of those places find all the paths you can take from that place so from store a you can go to store B and from store B you can go to school and from intersection you can only go to school and as you go keep track of the distance you've traveled so far for each of those paths and keep repeating this process until you get to the school then if you happen to find multiple paths that allows you to go from home to school then compare the distance that you've traveled for each of those paths and finally find a path with the shortest distance traveled and then pick that as the shortest path okay so that's the result we were looking for in the first place and this is a good example of what an algorithm is basically you have a problem you're going to solve in this case finding the shortest path from home to school and then you have a set of systematic instructions for solving that problem now one thing to note here is that depending on what data structure you're using to store the data that you're performing the algorithm on your algorithm might look slightly differently you might even have in some cases completely different algorithms for solving the same problem depending on what data structure you're using in this particular example we talked about two different options for storing the information about where the streets are and how they connect different locations the first option was to just list all possible paths and remember that the first step in our algorithm was to find all the possible places you can go from home and to do that with the first stair structure this one right here you might actually need to go through the entire list because in this particular list we have three paths here from home but it's possible that we have another path from home right here at the end of the list so you need to go through the entire list just in case on the other hand if you use the second data structure that we discussed we have all the possible places you can go from home listed right here as a group so as soon as we find the home row in this table you won't need to go through the entire table anymore so in this particular example using the second structure actually makes it slightly easier to implement the algorithm that we discussed now there are structures and algorithms are really important to learn because they'll help you write efficient software as a software developer so for example when I was working at Microsoft as a data science intern I had to write this piece of code to retrieve some data and when I wrote it originally it was taking like seven to ten hours and basically it was too slow because we didn't want we didn't want to wait that long so I rewrote it using my knowledge of data structures and algorithms and after rewriting it the new version only took like five to ten minutes to load that data so that's why learning them is important and it's actually useful in many practical situations that you might encounter as a software developer - okay to give you an even better idea about what data structures are like let me give you another example here let's say you're hosting a party and you're expecting a bunch of people and this example is gonna be a little bit silly but just follow along and you're gonna see why I'm talking about this particular example anyway let's say that each person come to the party we'll bring sort of like a small ball with them like a ball that can fit in their hand and this ball will have their name written on it so when David comes to the party he'll have a ball with David written on it and when Kevin arrives to the party he'll have a ball with Kevin written on it and so on and this is just a silly little system that you came up with for keeping track of who came to the party in which order because writing now each person's name would be a lot of work you're just too busy hosting a party so as someone who's studying computer science let's say you're trying to come up with an efficient system for storing these balls so that you can keep track of who came to the party one idea you have is this one you get a very long box with 100 partitions a lot of partitions and each partition let's say has exactly the same shape you know 10 centimeters by 10 centimeters let's say and every time someone comes to the party you're just gonna put that person's ball with their name written on it in the order they came to the party so David's ball will come in here and Kevin's will come in here and so on and this is actually sort of like a data structure that's realized in real life and this actually corresponds to the data structure called array in computer science and here's another idea you have you get a bunch of boxes and this time instead of getting a long box with many many partitions you want to get individual boxes that are connected with strings so the first box is connected to the second box with a string and that's connected to the third box with a string and so on and just like before you want to put these tokens with participants names written on them in these boxes just one by one in the order they came in so David's token will come in here and Kevin's ball will come in here and so on and this sort of data structure that's realized in real life corresponds to the linked list data structure in computer science okay so the natural question here would be which data structure use for this party well it actually depends because it highly depends on the particular situation and the nature of the party really and each data structure has advantages and disadvantages okay think about this situation let's say 100 people showed up to your party and you're pretty happy about it but suddenly you realize that the 98th person is Paul had been misspelled that person's name had been misspelled so you want to fix that with the array data structure it's actually pretty easy you just need to find the 98th partition and that exact location can be calculated easily because you know that each partition is ten centimeters wide so you just need to find ten centimeters times ninety seven actually which is nine hundred seventy centimeters so you just need to walk over from the beginning nine hundred seventy centimeters and then you can find the 98th person's token pretty easily you just need to replace that with the correct token with the link list data structure though doing the same thing would be slightly more tricky and that's because finding the 98th person or finding the 98th box here would be much harder and the reason for that is because these strings are pretty soft and they can be pretty much any lengths so each box can be in any location relative to the previous box so this first box might be in the living room and the second box might be in the kitchen and so on so to find in 98th box what you need to do is you need to count them one by one so you need to say okay this is the first box and then this is the second box and let's find the third box fourth and so on until you get to the 98th person at this point you might say well the array data structure is a better one then well not necessarily so think about this situation let's say you have 100 people showing up to the party and you're pretty happy about it but suddenly five more people show up that you didn't expect with the linked list data structure it's pretty easy to deal with that you can just add five more boxes find five more boxes somewhere and then five more strings and just add them to the last box you had in the linked list data structure and then store the five people's tokens in those boxes with the array data structure though it's a little bit more tricky one option here would be to get another box with let's say 100 partitions again and store those people's tokens there and use the two boxes together or you could destroy the first box you had and then get a box with even more partitions let's say 200 partitions and then transfer all the balls you had for the first 100 people to the new box and then after that add the additional five people's tokens in the new box and in general if you have no idea how many people are coming to the party let's say anywhere between 5 to 1,000 people the linked list data structure might be slightly more convenient than the array because linked lists are so much easier to resize than it is to resize a race ok and this was another simplified example of what data structures are like on a computer and this sort of gives you a rough idea about how to actually start thinking about them and throughout this course I'm going to introduce you to even more data structures and this time I'm going to explain them in a much more technical way using concepts like classes objects memory and maybe even some code snippets too now if you're just getting started with data structures and algorithms one thing to keep in mind that's actually really important is to apply what you've learned through solving problems and the reason I say that is because it's so common for beginners to learn these concepts and not actually be able to use them in a real-world situation because they haven't had enough practice and actually this video sponsor brilliant org has an interesting website for learning these concepts in a sort of a new way ok to show you what I mean let's take a look at their computer science fundamentals course right here which I would recommend for you guys and let's go into the intro to algorithms section and you can see that it covers topics like arrays searching insertion sort and Big O notation and in the arrays section they have a bunch of explanations about the topic and as you continue you'll give you a quiz to test your understanding of the topic so it's definitely an interesting way to learn computer science concepts by solving problems okay if you want to check it out for yourself just go to brilliant org slash CS no joke and going to this link will actually help support this channel and the first 200 people will get 20% off the annual subscription and actually I'm super excited about this because they're the first sponsor I have on this YouTube channel and I feel like I'm becoming a professional youtuber finally so thanks for that brilliant ok as always I'm YK from CS dojo thanks for watching and I'll see you guys in the next video
Original Description
Data structures and algorithms tutorial #1 - let's go!
Check out Brilliant.org, a website for learning computer science concepts through solving problems: https://brilliant.org/csdojo/
Special thanks to Brilliant for sponsoring this video.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from CS Dojo · CS Dojo · 40 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
▶
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
4 Hacks for Finding the Optimal Answer in Coding Interview QUICKLY!
CS Dojo
Dynamic Programming Tutorial with Fibonacci Sequence
CS Dojo
Kadane's Algorithm to Maximum Sum Subarray Problem
CS Dojo
Longest Common Subsequence (Dynamic Programming)
CS Dojo
0-1 Knapsack Problem (Dynamic Programming)
CS Dojo
Amazon Coding Interview: Count Negative Integers in Row/Column-Wise Sorted Matrix
CS Dojo
Microsoft Coding Interview Question and Answer: Lowest Common Ancestor
CS Dojo
Learn Counting Sort Algorithm in LESS THAN 6 MINUTES!
CS Dojo
Radix Sort Algorithm Introduction in 5 Minutes
CS Dojo
Coding Interview Question and Answer: Longest Consecutive Characters
CS Dojo
Coding Interview: Can You RANDOMLY Reorder Array in O(N)?
CS Dojo
Coding Interview Question: Tower Hopper Problem
CS Dojo
Problem Solving Technique #1 for Coding Interviews with Google, Amazon, Microsoft, Facebook, etc.
CS Dojo
Google Coding Interview Question and Answer #1: First Recurring Character
CS Dojo
Facebook Coding Interview Question and Answer #1: All Subsets of a Set
CS Dojo
Think you're not smart enough to work at Google? Well, think again.
CS Dojo
How to Crack a Google Coding Interview - An Ex-Googler’s Guide
CS Dojo
Amazon Coding Interview Question - K Closest Points to the Origin
CS Dojo
How I Got an Internship at Microsoft
CS Dojo
How I Got a Job at Google as a Software Engineer (without a Computer Science Degree!)
CS Dojo
Why I Left My $100,000+ Job at Google
CS Dojo
Top 5 Programming Languages to Learn to Get a Job at Google, Facebook, Microsoft, etc.
CS Dojo
How I Learned to Code - and Got a Job at Google!
CS Dojo
Why I Left Google To Be A YouTuber FULL-TIME (and NOT part-time!)
CS Dojo
What Is Dynamic Programming and How To Use It
CS Dojo
Python Tutorial for Absolute Beginners #1 - What Are Variables?
CS Dojo
What's It Really Like To Intern At Google? (LIVE with a former Google software engineer intern)
CS Dojo
How to Use If Else Statements in Python (Python Tutorial #2)
CS Dojo
Dynamic Programming Interview Question #1 - Find Sets Of Numbers That Add Up To 16
CS Dojo
How To Use Functions In Python (Python Tutorial #3)
CS Dojo
What’s It Like To Be A Program Manager Intern At Microsoft? (LIVE with a former Microsoft intern)
CS Dojo
Introduction To Lists In Python (Python Tutorial #4)
CS Dojo
Introduction to For Loops in Python (Python Tutorial #5)
CS Dojo
What Programming Language Should I Learn First?
CS Dojo
What Is Competitive Programming and How To Prepare For It (LIVE with Gaurav Sen)
CS Dojo
While Loops and The Break Statement in Python (Python Tutorial #6)
CS Dojo
More About For Loops in Python & Solutions to the Last 2 Problems (Python Tutorial #7)
CS Dojo
How to Learn to Code - Best Resources, How to Choose a Project, and more!
CS Dojo
How To Use Dictionaries In Python (Python Tutorial #8)
CS Dojo
Data Structures & Algorithms #1 - What Are Data Structures?
CS Dojo
An Overview of Arrays and Memory (Data Structures & Algorithms #2)
CS Dojo
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3)
CS Dojo
Classes and Objects with Python - Part 1 (Python Tutorial #9)
CS Dojo
Introduction to Classes and Objects - Part 2 (Data Structures & Algorithms #4)
CS Dojo
Classes and Objects with Python - Part 2 (Python Tutorial #10)
CS Dojo
Introduction to Linked Lists (Data Structures & Algorithms #5)
CS Dojo
Introduction to Recursion (Data Structures & Algorithms #6)
CS Dojo
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7)
CS Dojo
Amazon Coding Interview Question - Recursive Staircase Problem
CS Dojo
Using Boolean in Python (Python Tutorial #11)
CS Dojo
Intro to Data Analysis / Visualization with Python, Matplotlib and Pandas | Matplotlib Tutorial
CS Dojo
What Can You Do with Python? - The 3 Main Applications
CS Dojo
Facebook Coding Interview Question - How Many Ways to Decode This Message?
CS Dojo
List Comprehension Basics with Python (Python Tutorial #12)
CS Dojo
How To Use Sets in Python (Python Tutorial #13)
CS Dojo
Python books for beginners? What Python projects to work on? | 2 Python Beginner FAQ’s!
CS Dojo
Resources for Learning Data Structures and Algorithms (Data Structures & Algorithms #8)
CS Dojo
6 Python Exercise Problems for Beginners - from CodingBat (Python Tutorial #14)
CS Dojo
Google Coding Interview - Universal Value Tree Problem
CS Dojo
Best laptops for programming? How to get a job at Google? - And other FAQ’s!
CS Dojo
More on: Algorithm Basics
View skill →Related Reads
📰
📰
📰
📰
Morris Pre Order Traversal
Dev.to · Jaspreet singh
Advanced Stack ApplicationsData Structures and Algorithms Deep‑Dive — Advanced Stack Applications…
Medium · Programming
The Minecraft anvil is a tree-cost optimization problem in disguise
Dev.to · Mark
KMP Algorithm (Knuth-Morris-Pratt): The Smart Way to Perform String Matching in O(N)
Dev.to · Jaspreet singh
🎓
Tutor Explanation
DeepCamp AI