As my previous article 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 the key to become a better 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.
Some beginners will be discouraged and be frustrated at the beginning, feel that the data structure and algorithm are very abstract and obscure.
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, be patient and keep moving.
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.
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.
How do you find a book from a library?
Method #1: You can check each book one by one until you find the wanted
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.
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.
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.
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 is your choice
- Java: Data Structures and Abstractions with Java
- Python： Problem Solving with Algorithms and Data Structures Using Python
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 summarized many good practices for data structures.
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.
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:
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
There are many websites for deliberate practicing data structures and algorithms, I recommend these two, which both contain excellent online judge system:
- Leetcode: 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: 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 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.
Introduction to Algorithms, 3rd Edition 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, 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.
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?
Some great open-source projects will be the most useful resources for your learning.
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!