How To Learn Data Structures And Algorithms (An Ultimate Guide For Beginners)
Tags: beginners, tutorial, firstyearincode, career
Published: 2019-12-25 13:43:56

Original Post: https://www.coderscat.com/how-to-learn-data-structures-and-algorithms

## Mindset

As my [previous article ](https://www.coderscat.com/to-be-a-programmer)elaborated, data structure and algorithms are the ultimate basis for a programmer. I strongly believe that a good knowledge of these two topics is also key to become a [better programmer](https://www.coderscat.com/to-be-a-programmer) because an engineer who has a good understanding of algorithms and data structures can make thoughtful choices and write programs that can handle changes better and perform well.


### I come, I conquer

Some beginners will be discouraged and be frustrated at the beginning, feel that the data structure and algorithm are very abstract and obscure.

![How to learn data structures and algorithms (An ultimate guide for beginners) 2](https://www.coderscat.com/wp-content/uploads/2019/09/gihpy.gif)

*Don’t worry, that is very normal for beginners*. I also got the same feeling when started learning. The real reason is that you did not find your own learning method, and haven’t built confidence for it.  This is my roadmap and tips for you, Keep patience and keep moving.

### Don’t be afraid of the mathematical part.

Data structure and algorithms do involve some mathematical reasoning and proof, especially when analyzing the time and space complexity of an algorithm.

The big-O complexity analysis is important, but you don’t need to worry about it too much. You don’t need a high IQ or abstract mathematical knowledge. You can master it as long as you have a high school mathematics level.

You will have more confidence after months of practice and learning.  

### What is data structure and algorithm essentially?

Generally speaking, the data structure is a storage structure for a set of data, an algorithm is a method and pattern for solving problems.

I will help you understand these two concepts from examples.

#### Take an example

![How to learn data structures and algorithms (An ultimate guide for beginners) 3](https://www.coderscat.com/wp-content/uploads/2019/09/image-17.png)

 
How do you find a book from a library?

- Method #1: You can check each book one by one until you find the wanted
  book.

- Method #2: You can first locate the bookshelf according to the category
  of a book, whether it is humanity, or science, or computer science,
  and then you search in the specific bookshelf.  

In general terms, these two methods for finding a book are both *algorithms*, so we get the definition of an algorithm is: *The methods for solving problems, which could be implemented in programming.*

In detail, when we talk about data structures and algorithms, we are talking queues, stacks, heaps, binary search, dynamic programming and so on. 

These are patterns for abstraction and solving problems, which invented by computer pioneers. We can effectively learn them and use them to solve many practical development problems.

#### The relationship between data structures and algorithm

Data structures and algorithms complement each other. The data structure is for the algorithm, and the algorithm is applied to a specific data structure. Therefore, we can’t isolate the data structure and algorithms.

[![How to learn data structures and algorithms (An ultimate guide for beginners) 4](https://www.coderscat.com/wp-content/uploads/2019/09/image-15.png)](https://amzn.to/2J5E4AM)


For example, because arrays have the characteristics of random access, the commonly used binary search algorithm requires an array to store data. But if we chose a data structure like a linked list, the binary search algorithm will not work because the linked list does not support random access.

## The Steps

### Get good books and resources

There are some really good textbooks for data structure and algorithms, but at the beginning, you maybe need the books which are coded in a programming language you have mastered.

- C:  [Algorithms](https://amzn.to/33NIhBb) is your choice
- Java: [Data Structures and Abstractions with Java](https://amzn.to/2Mu2Exr) 
- Python： [Problem Solving with Algorithms and Data Structures Using Python](https://amzn.to/32ywK8B)

[Visualizations](https://www.cs.usfca.edu/~galles/visualization/Algorithms.html) will help you understand how data structure and algorithms works, you can find awesome animations of this kind from the site: [visualgo.net.](https://visualgo.net/en)


![How to learn data structures and algorithms (An ultimate guide for beginners) 5](https://www.coderscat.com/wp-content/uploads/2019/09/Jietu20191225-210919.png)
 

### Learning the basics data structures

Many advanced data structures and algorithms, such as bipartite graphs, maximum streams, etc., are rarely used in our usual development.  So, you don’t have to look at them at the beginning.

Here are 11 basic data structures for your starting:

```
array, linked list, stack, queue, hash table, 
map, heap, binary tree, trie tree, 
graph, skip list
```

You should learn these data structure APIs and also the complexity of their operations.

[GeeksforGeeks](https://www.geeksforgeeks.org/data-structures/) summarized many good practices for data structures.

### Learning basic algorithm design pattern

From my experience, studying algorithms should not try to remember the steps and details of algorithms, but try to reinvent, reason and reimplement the algorithm by ourselves.

Why?

**If you didn't understand how it works, you could not remember the details and will forget it later. Implied ideas in algorithms are more important than details.**

My recommended flow for learning classic algorithms is:

![How to learn data structures and algorithms (An ultimate guide for beginners) 6](https://www.coderscat.com/wp-content/uploads/2019/09/learn-datastructures-and-algorithms.png)

Repeat this procedure will make you learn more effectively.

The most used algorithms come to these categories, some harder problems need some variants, you need to combine several algorithms to solve one problem.

Follow the principle of deliberate practice, you should focus on one specific category in a short time, try to learn them one after another:

```
  sorting, binary search, search, string matching, recursion,
  hash algorithm, greedy algorithm, 
  divide and conquer algorithm, backtracking algorithm,
  dynamic programming
```


### Learn by doing

There are many websites for deliberate practicing data structures and algorithms, I recommend these two, which both contain excellent online judge system: 

- [Leetcode](https://leetcode.com/): which contains almost all the interview questions frequently asked by big companies(like Facebook, Google, Amazon), it's a very helpful resource for interviewing.
- [HackerRank](https://www.hackerrank.com/): which has very clean categories for data structures and algorithms, even contains problems of mathematics, database, and security. And you can also enter the programming contest for fun.

Another good practice is finishing some trivial projects which using one specific data structure or algorithm.

For example, [this project creates a Maze](https://github.com/chenyukang/Maze) with the data structure of “union-set” and also tries to implement pathfinding algorithms. Finish this kind of projects will build your confidence, and also lets you realize it’s useful for creating real applications.

## Get deeper

### More books

[Introduction to Algorithms, 3rd Edition](https://amzn.to/2Bv2xeR) is for your deeper studying, the algorithm reason part is awesome and also has more details on complexity analysis and mathematical tools.

And the final book is:[ The Art of Computer Programming](https://amzn.to/2Jme6th), very few programmers have finished reading all this book. This is the ultimate and authoritative reference for you to dig deeper, this book almost covers all the corners of programming, especially about data structures and algorithms. 

### Learn from real projects

Knowledge and skill will only prove the value when they are applied to products.

You could learn much from existing products and applications.

For instance, are you curious about what data structure or algorithm used for Google’s search suggestion?

![learn from real applications](https://www.coderscat.com/wp-content/uploads/2019/12/2019_09_12_learn-data-structures-and-algorihtms.org_20191229_091704.png)

Some great open-source projects will be the most useful resources for your learning.

[Redis](https://github.com/antirez/redis) contains many mostly used data structures and has many optimizations on performances. The Linux Kernel also used many data structures like link list, red-black tree, hash, etc.

After more years of practice, data structures will be yous tools for abstraction and algorithms designing will be the natural pattern for your problem-solving.

*Keep curiosity and practice!*