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 6809497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:05:37+00:00 2026-05-26T20:05:37+00:00

Here is program for memoized version matrix chain multiplication program from Introduction to Algorithms

  • 0

Here is program for memoized version matrix chain multiplication program from Introduction to Algorithms by cormen etc

MEMOIZED-MATRIX-CHAIN(p)

1 n  length[p] - 1   
2 for i = 1 to n
3      do for j = i to n
4             do m[i, j]  = infinity   
5 return LOOKUP-CHAIN(p, 1, n)

LOOKUP-CHAIN(p, i, j)

1 if m[i,j] < infinity
2    then return m[i, j]
3 if i = j
4    then m[i, j]  0
5    else for k =  i to j - 1
6             do q = LOOKUP-CHAIN(p, i, k) +
                     LOOKUP-CHAIN(p, k + 1, j) +
                     p(i - 1)* p(k) *p(j) 
7                if q < m[i, j]
8                   then m[i, j] = q
9 return m[i, j]

It is mentioned in description as we can categorize the calls of LOOKUP-CHAIN into two types:

  1. calls in which m[i,j] = infinity, so that lines 3-9 are executed.
  2. calls in which m[i,j] is less than infinity, so that LOOKUP-CHAIN simply returns in line

There are n square calls of first type, one per table entry. All calls of the second type are made as recursive calls by calls of the first type.
Whenever, a given call of LOOKUP-CHAIN makes recursive calls, it makes “n” of them. Therfore, there are n cube calls of the second type in all. Each call of
the second type takes O(1) time, and each call of the first type takes O(n) time plus the spent in recursive calls. There for total time is O(n cube).

My question is

  1. What does author mean by “All calls of the second type are made as recursive calls by calls of the first type” ?
  2. How author came up with ” given call of LOOKUP-CHAIN makes recursive calls, it makes “n” of them” in above sentence?

Thanks!

  • 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-05-26T20:05:38+00:00Added an answer on May 26, 2026 at 8:05 pm
    1. I think they meant that if you consider the tree of recursive calls, the calls of the second type appear as leaves (no more recursion), while the calls of the first type are the inner nodes of the tree. So yes, the second type is called by the first type.

    2. The for loop on line 5 of LOOKUP-CHAIN performs at most n iterations (because 1≤i≤j≤n) so it can make up to 2n=O(n) recursive calls.

    Maybe it is easier to understand the complexity of this recursive algorithm if you picture it as a tree:

    • The inner node corresponds to “type 2”, there cannot be more than n² of them (because of the memoization), and they each perform O(n) operations

    • The leaves correspond to “type 1”. Because there are at most n² inner nodes with at most 2n children, so you cannot have more than 2n³ leaves and each of these performs θ(1) operations

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

Sidebar

Related Questions

hi i have a little program here that gets a directory from the command
I have a program here: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ipc.h> #include
there is this check-in-out program here at my workplace, it only takes the data
I've got a Schroedinger's Cat type of problem here -- my program (actually the
Here's my program so far: int main() { char choice = 'D'; string inputString;
Okay here's the program I have typed up(stdio.h is included also): /* function main
Thanks to pbos help and its program (published here , for xoring a big
Here is a quick test program: public static void main( String[] args ) {
Here is a little test program: #include <iostream> class Test { public: static void
Here's a short test program: sub foo($;@) { my $sql = shift; my @params

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.