Given a binary square matrix of order $n$. Can the problem of finding the longest sequence of 1's (horizontal or vertical) be solved with recursion?

I know how to solve the problem without recursion by iterating over the columns and rows, but was wondering it there is a solution using recursion.

  • 1
    $\begingroup$ Can you define your problem in more detail? Also, what do you mean by solve with recursion? $\endgroup$ Oct 9, 2021 at 7:12
  • $\begingroup$ Usually a solution not using recursion is thought to be better than one that uses recursion, if they both have the same time complexity. $\endgroup$
    – nir shahar
    Oct 9, 2021 at 9:13
  • 1
    $\begingroup$ If you know how to solve the problem without recursion then you also know how to solve it with recursion. Simply recurse as many times you desire and, once the desired depth of recursion is reached, solve the problem using your current strategy. That's probably not what you want but if the only constraint is to solve the problem "using recursion", then this approach formally satisfies the request. $\endgroup$
    – Steven
    Oct 9, 2021 at 16:33


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.