avatarCoder's Cat

Summary

This article provides a comprehensive guide for beginners on learning data structures and algorithms, emphasizing the importance of these concepts for programmers and offering practical advice and resources for effective study and application.

Abstract

The article "How To Learn Data Structures And Algorithms (An Ultimate Guide For Beginners)" outlines the significance of understanding data structures and algorithms for programmers. It acknowledges the initial frustration that beginners may face but reassures them that with the right approach, these concepts can be mastered. The guide suggests that a solid grasp of high school mathematics is sufficient to start learning and that one should not be intimidated by the mathematical aspects of these subjects. It explains the relationship between data structures and algorithms, illustrating how they complement each other with examples such as searching for a book in a library. The article recommends starting with a few good books and resources tailored to the reader's preferred programming language and using visualization tools like visualgo.net to enhance understanding. It lists essential data structures and algorithms to focus on, advocating for a deep understanding rather than rote memorization. The author emphasizes learning by doing, suggesting practice platforms like Leetcode and HackerRank, and encourages going beyond theory by engaging with open-source projects. The article concludes by recommending in-depth study materials and motivating readers to be curious and persistent in their practice.

Opinions

  • The author believes that a thorough knowledge of data structures and algorithms is key to becoming a better programmer.
  • It is suggested that being able to perform a big-O complexity analysis is important but not necessary to start with.
  • The article posits that data structures and algorithms are not just theoretical concepts but practical tools that can be leveraged to solve common development problems.
  • The author advises against trying to memorize algorithms, instead recommending a focus on understanding and being able to reimplement them.
  • There is an opinion that some data structures and algorithms, such as bipartite graphs and maximum streams, are less intuitive and not commonly used in everyday development.
  • The author expresses that well-crafted open-source projects are valuable resources for learning how data structures and algorithms are applied in real-world scenarios.
  • The article implies that mastery of these subjects comes with years of practice and that they will become natural abstraction tools for problem-solving.

How To Learn Data Structures And Algorithms (An Ultimate Guide For Beginners)

Data structures and algorithms are essential for any programmer.

I strongly believe that a thorough knowledge and skill of these two topics are the key to becoming a better programmer.

An engineer with a deep understanding of algorithms and data structures will be able to make informed design choices and write programs that are more performant and easier to change.

I came, I saw, I conquered

As a beginner, you may feel discouraged and frustrated by these concepts. The terms data structures and algorithms both sound abstract and obscure.

Don’t worry, though. That’s a normal reaction for a beginner.

I had the same reaction when I started learning about the subject. The reason you feel that way is that you haven’t found the right method to let you study the subject deliberately.

I’m going to tell you about my roadmap and tips. Be patient, and always keep moving forward.

Don’t be intimidated by mathematics

Data structures and algorithms do involve some mathematical reasoning and proofs, particularly when analyzing the time and space complexity of an algorithm.

Being able to perform a big-O complexity analysis is certainly important, but you don’t need to worry about it too much to start with. You don’t need a high IQ or abstract mathematical knowledge.

As long as you understand high school mathematics, you have the tools needed to understand data structures and algorithms.

That may seem unlikely to you right now. In this article, I’ll argue otherwise: after a few months of directed study and practice, you’ll be able to approach the subject with confidence.

What is data structure and algorithm essentially?

Generally speaking, a data structure is a way to organize data, while an algorithm is a method or pattern for solving problems.

To illustrate this, let’s say you want to find a specific book in a library.

Take an example

How do you find a specific book from a library?

  • Method #1: You could check each book by shelves, one by one, first to last, until you find the book in question.
  • Method #2: You could first locate the bookshelf according to the category of the book in question. You determine whether the subject is the humanities, science, computer science and so on, and then you search only that specific bookshelf.

Each of these methods is an algorithm. This is the definition of an algorithm: a method for solving problems which can be implemented via programming.

In this analogy, the books, the shelves, and the way they are arranged are all data structures.

In concrete terms, when we speak about data structures, we are talking queues, stacks, heaps; when we say algorithms, we speak of binary search, dynamic programming, and so on.

Together, data structures and algorithms represent tried and tested patterns for abstraction and problem-solving. They were invented by pioneers in the field. They did the hard work that we can leverage in order to solve many common development problems.

How data structures and algorithms relate

Data structures and algorithms complement each other. The data structure exists for the algorithm, and an algorithm generally suits a specific data structure.

For instance, arrays are contiguous. The binary search algorithm applies to direct access of contiguous memory, so an array is used to store the data for a binary search algorithm.

If instead, we want to use a different data structure such as a linked list, the binary search algorithm wouldn’t work, as the linked list data structure doesn’t support direct access.

The Steps

Pick a few good books and resources

There are several classic works on data structure and algorithms. They are useful resources but can be difficult for a beginner. At the outset, you’re better off working with resources that use a programming language you already know.

Visualizations will help you understand how data structure and algorithms work. You can find awesome animations of this kind from the site: visualgo.net.

visualgo.net

Some data structures and algorithms, such as bipartite graphs, maximum streams, etc, are less intuitive than others. All general algorithms are useful tools, but you rarely need to use these in day-to-day development. If you stick to learning the more intuitive and general algorithms first, you’ll eventually be able to master more difficult, niche techniques.

I recommend these eleven basic data structures to start:

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

Learn how they work, how they are implemented, their common APIs, and how they perform in terms of big-O complexity.

Additionally, GeeksforGeeks has a bunch of good practices for using data structures.

From my experience, when studying algorithms, trying to memorize the steps and implementation details often isn’t the best strategy.

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.

Don’t try to remember every last detail about the implementation you read about. Instead, try to reinvent, reason and reimplement the algorithm by yourself.

Here’s my preferred workflow for learning algorithms. Repeatedly following it will give substantial results.

Repeat this procedure will make you learn more effectively.

Below basic algorithms are the ones most commonly used. By following the principle of deliberate practice, you should focus on one specific category of algorithms at a time, and try to understand them in order.

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

There are harder problems that need tweaking or require you to combine several algorithms for a viable solution. You should try them after mastering the basics.

Learn by doing

Several websites can help with deliberate practice of data structures and algorithms. I recommend these two, which both have excellent online judging systems:

  • Leetcode: which details almost all common interview questions asked by the big companies (such as Facebook, Google, Amazon); a very helpful resource for interviewing.
  • HackerRank: which has very clean categories for data structures and algorithms, and offers lessons in mathematics, database, and security. It also lets you enter programming contests for fun.

Another good way to practice is to create trivial projects that use one specific data structure or algorithm.

For example, this project uses the union-set data structure to create a maze, and also tries to implement pathfinding algorithms. Finishing small projects of this sort will build your confidence, and also teach you its use for creating real applications.

Go deeper

Introduction to Algorithms, 3rd Edition is a great choice for in-depth study. The section on algorithmic reasoning is awesome, and it also offers more details on complexity analysis and mathematical tools.

The other book I would recommend is The Art of Computer Programming. Few programmers have read it from cover to cover, but it remains perhaps the ultimate and authoritative in-depth reference on the subject. It covers almost all facets of programming, and its section on data structures and algorithms is second to none.

Knowledge and skill only matter when applied to tangible products.

For instance, you may be curious about how Google’s search suggestions work in terms of data structures or algorithms.

Well-crafted open-source projects are incredibly valuable learning resources.

Redis demonstrates the use of many commonly used data structures, and has many performance-related optimizations. The Linux Kernel relies heavily on data structures like linked list, red-black trees, hashes, etc., and fine-tunes its implementations in various ways.

You are not expected to master these things instantly. But after years of practice, you will discover that data structures have become your abstraction tools of choice, and that fitting data structures to custom algorithms has become a comfortable means of solving problems.

Be curious and keep practice!

  1. Quicksort: the history and implementations
  2. To Be A Great Programmer: Mindset And Learning Strategy

Originally published at https://www.coderscat.com.

Algorithms
Data Structures
Learning To Code
Programming
Recommended from ReadMedium