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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:29:46+00:00 2026-06-13T16:29:46+00:00

I am currently trying to wrap my head around recursion so I picked a

  • 0

I am currently trying to wrap my head around recursion so I picked a c++ textbook and began to read. The first couple of pages in the chapter on recursion were easy to understand but then I got to an item that doesn’t make sense to me.

 int height(node *p)
 {
    if(p==NULL)
       return 0;
    else{
   return 1 + max(height(p->llink),height(p->rlink));

  }

If max gives me the greatest of two values, how does max get its arguments from what height it’s returning.
If anyone could help I would greatly appreciate it…..

  • 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-13T16:29:48+00:00Added an answer on June 13, 2026 at 4:29 pm

    To understand recursion you have to think recursively:

    • you can understand that an empty tree has height 0
    • you can understand that a generic non-empty tree has height 1 + the height of the longest subtree (which can be the one starting from the left or from the right)

    Starting from this you can trivially understand the code. If you draw the tree you will see what happens. If you have for example

         A
        / \
       B   C
      / \  
     D   E
    
    • height(A) will return 1 + max(height(B), height(C))
    • height(B) will return 1 + max(height(D), height(E))
    • height(C) will return 1 + max(height(NULL), height(NULL)) = 1
    • height(D) will return 1 + max(height(NULL), height(NULL)) = 1
    • height(E) will return 1 + max(height(NULL), height(NULL)) = 1

    so

    height(A) = 1 + max(height(B), height(C)) =
    = 1 + max(1 + max(height(D),height(E)), 1) =
    = 1 + max(1 + 1, 1) = 1 + max(2, 1) = 3
    

    (I omitted calls to height(NULL) because they are trivially 0 and otherwise it would have been too much verbose.)

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

Sidebar

Related Questions

I'm currently trying to wrap my head around regex, I have a validation snippet
I am currently trying to wrap my head around working with JPA. I can't
I'm currently trying to wrap my head around WPF, and I'm at the stage
I'm currently trying to wrap my head around learning Python and I've come to
I'm currently trying to get my head wrap around Cassandra/thrift with Erlang... I have
I'm currently trying to wrap my head around pointers in C, coming from front-end
I'm currently trying to wrap my head around some JavaScript. What I want is
Trying to wrap my head around updating UI controls from other threads. Currently using
I am trying to wrap my head around block programming, and currently stuck in
I'm trying to wrap my head around the OpenGL object model on iPhone OS.

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.