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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:11:09+00:00 2026-05-30T05:11:09+00:00

I am looking a lot of interview problems where the question requires traversing two

  • 0

I am looking a lot of interview problems where the question requires traversing two trees together, I am not sure exactly how to go about doing this.

e.g.

Given references to roots of two binary trees, how do you determine
whether the sequence of the leaf elements equal but you must
implement short circuiting return when the first node violates the
rule.

  • 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-30T05:11:10+00:00Added an answer on May 30, 2026 at 5:11 am

    Is your question asking to find out whether:
    “the sequence created by visiting all the leaf nodes of 2 trees is same”

    with a constraint that when found a mismatch of leaf values, then we must quit immediately.

    If so, I propose following solution:

    insert (root of tree1) in stack1
    insert (root of tree2) in stack2
    
    temp1 = (root of tree1) -> left child
    temp2 = (root of tree2) -> left child
    
    while(stack1 and stack2 arent empty) 
    {
        found = false
        while(found == false) {
            if (temp1 is leaf node)
                child1 = value of temp1
                found = true
                pop element from stack1
                set temp1 to its right child
    
            if (temp1 has left child)
                put temp1 in stack1
                set temp1 to its left child
        }
    
        found = false
        while(found == false) {
            if (temp2 is leaf node)
                child2 = value of temp2
                found = true
                pop element from stack2
                set temp2 to its right child
    
            if (temp2 has left child)
                put temp2 in stack2
                set temp2 to its left child
        }
    
        if(child1 != child2) 
            return
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking a lot at SOA recently. Isn't CORBA exactly the same
Im learning a lot about how MVC frameworks work by looking around and studying
I've done a lot of looking around and have not found what I'm looking
This is an interview question Looking for best optimal solution to trim multiple spaces
Been looking at a lot of post/articles about using Iif(). All of this started
I've been looking through a lot of blog posts, documentation, etc. about JavaScript's strict
I've been looking at a lot of JavaScript code lately and I've seen two
I was looking a lot for method to get parent process in .NET, but
There is an issue that I cannot solve, I've been looking a lot in
I'm getting started with Astoria/ADO.NET Data Services/WCF Data Services. Looking through a lot of

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.