Блог пользователя AndrijaMlad

Автор AndrijaMlad, история, 15 месяцев назад, По-английски

Hello, I have a question for all the REDS/yellows on codeforces, How do you learn algorithm fast?

  • Проголосовать: нравится
  • -18
  • Проголосовать: не нравится

»
15 месяцев назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

I'm neither red nor yellow, but my advice would be to make sure you fully understand the algorithms you're implementing. You should be able to explain how (and ideally why, although this gets more difficult with advanced algorithms) the algorithm works. From there, it comes down to translating thoughts into code, and that gets easier with practice.

IMO, you should never have to memorize the exact code for an algorithm. At most, you should remember a few implementation tricks specific to the algorithm.

»
15 месяцев назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

Why cope? If I don't understand, it's fun to understand it a bit more each time. If I understand it, it's just a few minutes of coding, so not a big deal.

In general, if you need to code something a 100 times before you're confident, you should probably go back to studying it and understanding it better. Or just learn something else and give it some time — sometimes it takes time for it to settle in your head and to mature as a coder to understand something fully (I wouldn't say I fully understood DFS for the first 4-5 years of my career, even though I could probably code it blindfolded).

  • »
    »
    15 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    What do you mean by you didn't fully understand DFS? And what parts of BFS does OP not understand before they coded 100 times?

    • »
      »
      »
      15 месяцев назад, # ^ |
        Проголосовать: нравится +9 Проголосовать: не нравится

      Well, I pretended I knew DFS, but I would just memorize algorithms like AP/Bridge finding or SCC, which are just based on DFS properties. One day it just clicked, and I could code them like I was coding any other DFS problem.

      The in-out orderings, the all-edges-are-backedges property are very simple when you read about them, but using them creatively in solutions took me that long.

  • »
    »
    15 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Vidim da ste iz Srbije, pa cu da vam pisem na srpskom :) Ja neznam zasto ali sam mislio da zada bi naucio algoritam trebam da ga kucam dok ga ne memorizujem, ali hvala na savetu. Potrudi cu se da ga primenujem u buducnosti. Imajte lep dan

»
15 месяцев назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

I think you should put in more time to actually understand it rather than write it 100 times. What I usually did was to carefully study the code for the new algorithm I was trying to learn, then solve a few related easy/standard problems, while trying to write the code on my own, without looking at an example implementation of that new algo. This way, you kind of test if you really understood what you learnt.

»
15 месяцев назад, # |
  Проголосовать: нравится +42 Проголосовать: не нравится

you don't. doing something 100 times is stupid.

  • »
    »
    15 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    When I said 100 times I didn't mean like writhing DP 100 times for the Coin Change problem for example, but like you have to learn knapsack, Range DP, Com. DP, Digit DP... And at some point you learn all the things, and you now need to just solve solve Solve. I used BFS as an example, but My question was when you are bad at for example DP you should do more DP problems, but nobody likes to do what they are bad at. So how do you disciplin your self?

    • »
      »
      »
      15 месяцев назад, # ^ |
        Проголосовать: нравится +11 Проголосовать: не нравится

      Well, if you don't want to do smth, and you can't force yourself to do it, then there is no solution for it.

    • »
      »
      »
      15 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I really like Greedy, so like every time I code I tend to solve Greedy/math problems instead of DP problems

»
15 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

if you understand something, you don't have to write it even a single time to know how to use it :3 though practice still helps

»
15 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I am cleary not qualified for this but I think that for learning any algorithm you don't need to write it a 100 times to learn it, don't try to memorize the algorithm, understand it and I think it will mostly take you 20-30 problems to get it.

»
15 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I don't think i am enough qualified to say something . But when i learn some algorithm for example BFS DFS i try to understand the algorithm step by step . After understanding i try to implement it by myself without seeing the code on the basis of the steps if i fail then i see the code and try to understand how the code if working and logic behind it. After that I try to write that code for 2/3 time. After that I try to solve few easy questions of that algorithm . I learned BFS DFS like this 5/6 month ago and still didn't forget that.

»
15 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by AndrijaMlad (previous revision, new revision, compare).