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

Автор i_m_jp99, история, 3 года назад, По-английски

can anyone suggest me how to be good at recursion and what should be my approach? From where shall i solve questions?

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

»
3 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

Standard recursion problem are in most cases easy. Recursion becomes harder when you’re solving dp with recursion so try some recursion dp problems.

»
3 года назад, # |
  Проголосовать: нравится +25 Проголосовать: не нравится

Solving problems involving dfs is also a good thing to practice recursion.

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

Try to solve standard problems on dp. If not able to solve, understand it properly and solve some similar problems. Solve 50+ problems(if totally uncomfortable) and you will be good to go.

»
3 года назад, # |
  Проголосовать: нравится +160 Проголосовать: не нравится

Check this

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

You can practice those problems for improving your skill on recursion. I hope it will be helpful for you.

Problems Link: https://codeforces.com/group/MWSDmqGsZm/contest/223339

»
3 года назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

solve recursion problems, duh

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

Solve problems tagged DP, Divide and Conquer, DFS and similar, for example 1461D - Divide and Summarize.

Surprisingly only 5 problems are tagged Divide and Conquer but are below 1600 rating.

»
3 года назад, # |
  Проголосовать: нравится -6 Проголосовать: не нравится

Recursion? Check this out.

»
3 года назад, # |
  Проголосовать: нравится +77 Проголосовать: не нравится

First, you must be good at recursion

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

    ivan100sic can u plz suggest me some good places to start with recursion?

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

      Okay, let's be a bit more serious now.

      To be good at recursion, you must first identify simple cases which you will not solve recursively. Depending on the problem, this may be small values of $$$n$$$ e.g. $$$0,1$$$, or leaf nodes of a tree. Then, you must figure out how solving one instance of a problem relates to smaller problems. For example, when finding the maximum depth of a tree, the solution is the maximum of the maximum depths of all direct subtrees, plus one. Finally, when writing the recursive function, put the "simple case check" at the top and return the solution immediately if true, otherwise, make recursive calls, gather all the results, and form the return value based on those.

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

TLDR, learn from multiple resources. read and watch a lot of examples being solved. and do a lot of examples by yourself, gradually increase level, understand well how recursive code behaves. think of recursion as a method of solving problems by decomposing them into smaller versions. try to write a formal definition of your recursive solutions.

Some details
»
3 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

Solve backtracking problems, especially those with lengthy implementation.