How I improved my skills in working with algorithms, data structures and learned how to use all this in practice.



    From the translator: today we publish for you an article by Fabian Terh . The article will be primarily useful for novice programmers.

    I am a self-taught programmer, this post reflects my personal experience and skills in the field of algorithms and data structures; besides, I also talk about ways to solve problems (by the way, the second gives me a little worse than the first).

    Skillbox recommends: a two-year hands-on course “I am a web developer PRO” .

    We remind: for all readers of "Habr" - a discount of 10,000 rubles when writing to any Skillbox course on the promotional code "Habr".

    Problem: you know the theory, but you have difficulty with practice


    Not so long ago, I had a problem that can be described as “I don’t know what I don’t know,” one might say, a curiosity. The fact is that I understand the theory, and very well. I know how lists work, what are separate operations, what are abstract data types, etc.

    But the problem is that I don’t know what information may be useful to me in practice, and I don’t have any idea what may not be enough to accomplish some tasks. So, it is difficult for me when I need to solve some problems.

    Types of tasks that may occur

    An example of a question about data structures: describe how you would insert a node into a linked list, and specify the time complexity.

    Here is the question about the algorithms:find the element in the rotated sorted array and define the time complexity.

    Finally, the last question of a higher "level" than the previous ones - please describe how to solve the problem and list the requirements for its implementation.

    In the course of work you may need exactly this, i.e. description of the solution. In competitive programming, it is often necessary to provide working code without explicitly specifying any data structures or algorithms. In other words, they are expecting you to be able to use the optimal in each case data structures and algorithms for the most effective solution of the problem.

    How can I improve my skills?


    Personally, I used three resources for this: HackerRank, LeetCode and Kattis. They look alike, especially the first two, but not identical.

    I would divide the skills that are needed to solve problems into three groups:

    • knowledge of data structures;
    • knowledge of algorithms;
    • ability to apply data structures and algorithms.

    The first two categories are basic, they lie at the very bottom. The third category is a higher class.

    Knowledge of data structures

    Here HackerRank was most useful to me. It has a section on data structures, where information can be filtered by type, including trees, linked lists, arrays, etc.

    The issues that are addressed at HackerRank are mainly related to working with data structures:

    • Arrays: rotation of the array and other actions with it.
    • Linked lists: reversing, cycle detection.
    • Trees: node swapping, BST validation.

    You probably already understand what's wrong. Questions submitted by the resource cannot be used directly in solving problems. But they are necessary for understanding the basics, which was extremely important in my case.

    HackerRank does not have publicly available "decision models", although in the discussion section you can find a lot of tips, hints and even fragments of working code. It all helped me a lot.

    Knowledge of algorithms

    HackerRank has a section with algorithms, although LeetCode provides information for me more closely. It seems to me that on the second resource, the list of issues under consideration is much broader, and there are explanations and tips.

    It is best to start with the 100 most common questions (this section is on LeetCode). Some were very useful to me:

    • merging accounts;
    • the largest continuously increasing subsequence;
    • search in a rotated sorted array.

    Unlike issues related to data structures, the focus here is on how to do something. For example, the problem of merging accounts is mainly related to the use of standard UFDS algorithms. The search problem in a rotated sorted array is a twist in a binary search. Sometimes it is possible to find qualitatively new methods for solving problems - for example, the “sliding window” method for the task of the longest continuous increasing subsequence ”.

    Ability to use data structures and algorithms.

    Well, I already pumped this skill using the Kattis resource. There is a huge archive of solved problems, where data from various sources are collected, including competitions of programmers from around the world.

    Unfortunately, Kattis has no forum, plus cases are private, not general cases. Therefore, there are several problems that I could not solve with his help.

    However, the resource can help many programmers. I myself spent his study not too much time.

    Other resources


    Geeksforgeeks is another valuable resource for learning algorithms and data structures. I like the fact that it provides snippets in various languages, including C ++, Java and Python. You can use them without any problems.

    And, of course, there are good old Google from YouTube.

    Conclusion


    Actually, the main thing is to write code, debug, study the code of other developers, which will help to quickly deal with your current tasks. It is difficult to solve problems, but with each attempt, with each solved question, you will get better and better.



    Also popular now: