Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:09:16+00:00 2026-06-12T02:09:16+00:00

I was reading an article on solving the problem of Longest Common Subsequence at

  • 0

I was reading an article on solving the problem of Longest Common Subsequence at geekforgeeks, where there are two solutions, one recursive, and another through DP by a 2-D array. The DP solution does it in O(NM) time, while the recursive one does it in O(2^N) time.

The main problem with the recursive solution is the occurrence of overlapping of subsequences, as given there. however, if I store each pair in a hash, so that the next time that value is required by a recursion of the function, it can directly fetch the value from the hash instead of recursing further. So how much will this addition improve the efficiency? Will it come to O(NM)?

And secondly, how come the recursive solution yields O(2^N) time? How to find out the complexity of recursive functions like this one, or the one to find Fibonacci sequence, etc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:09:17+00:00Added an answer on June 12, 2026 at 2:09 am

    Yes, using a hash will make it O(NM). The process, in this case, is called memoization (yes, without the r). Just make sure you don’t use an actual hashmap container as provided by your language of choice, make it a simple matrix: if the value for the current pair is -1, compute it recursively, otherwise assume it is already computed and return it.

    As for your second question, you can either do it mathematically to get the best bound, or get "good enough" by drawing it on paper like your link does:

                    f(n)
                   /    \
             f(n-1)      f(n-2)
            /     \        
      f(n-2)       f(n-3)
              ...
    

    This should be enough to inductively suggest that it will be O(2^n): the tree has height n, and at each node, you have two recursive calls that will reduce the problem from size n to size n - 1 (which will be O(2^(n - 1)). So the size n original problem will be O(2^n).

    Note that it is not incorrect to say that fibonacci is O(2^n), but you can get a tighter bound with other mathematical methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading this article, and at one point it gives me this nasm
I am reading an article ( JavaScript Closures for Dummies ) and one of
i never work wuth INotifyPropertyChanged. i was reading article and from there i found
I was reading this article today on two different regular expression algorithms. According to
I was reading the following article: http://msdn.microsoft.com/en-us/magazine/cc817398.aspx Solving 11 Likely Problems In Your Multithreaded
After reading this article about two different types of regular expression algorithms (Perl 5.8.7
Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
After reading this article, it makes sense to rebase to gather changes from the
After reading this article I don't have a clear answer: http://palizine.plynt.com/issues/2010Oct/bypass-xss-filters/ Will browsers interpret
After reading this article on thedailywtf.com, I'm not sure that I really got the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.