Hello, welcome to my data structures and algorithms series. In this
series, we will dive into the basics of data structures and algorithms.
What Are Data Structures?
Data structures are different ways of storing data on your computer. For
example, let's say you want to make a system similar to Google Maps
for your neighborhood. You have all the locations' coordinates, but you
need to store information about how these locations are connected
with streets. There are different options for storing this information,
such as:
• Storing all possible paths in a list format
• Listing each location and the places you can go from there
In this example, 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.
What Are Algorithms?
Algorithms are sets of instructions for performing operations on
different data structures. For example, let's say you want to find the
shortest path from your home to your school. You can come up with a
systematic set of instructions to solve this problem, such as:
1. Find all the places you can go from home
2. From each of those places, find all the paths you can take to
school and keep track of the distance traveled for each path
3. Compare the distance traveled and pick the shortest path
Depending on the data structure you use, the algorithm might look
slightly different. It's important to learn data structures and algorithms
to write efficient software as a software developer.
, Practical Use of Data Structures and Algorithms
Learning data structures and algorithms can be useful in many practical
situations as a software developer. For example, when working at
Microsoft as a data science intern, I had to retrieve some data, and the
original code was taking too long to load. By rewriting it using my
knowledge of data structures and algorithms, I was able to reduce the
loading time from 7-10 hours to 5-10 minutes.
Data Structures in Real Life: Hosting a Party
Imagine you're hosting a party and each guest brings a small ball with
their name written on it. You need an efficient system to keep track of
who came to the party and in what order. As a computer science
student, you come up with two ideas:
Idea 1: The Array Data Structure
In this system, you get a long box with 100 partitions, each partition
being 10cm x 10cm. Every time a guest arrives, you put their ball with
their name written on it in the order they came to the party. This
corresponds to the array data structure in computer science.
Idea 2: The Linked List Data Structure
In this system, you get a bunch of boxes that are connected with
strings. The first box is connected to the second box with a string, and
so on. You put each guest's ball with their name written on it in the
order they arrived, just like in the array system. This corresponds to the
linked list data structure in computer science.
So which data structure should you use? It depends on the situation.
The array data structure is easier to find a specific ball, but the linked
list data structure is easier to add new balls.
If you have no idea how many people are coming to the party, the
linked list data structure might be more convenient because linked lists
are easier to resize than arrays.