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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:53:41+00:00 2026-06-02T20:53:41+00:00

Is it possible to do an iterative in-order-traversal on a BST whose node has

  • 0

Is it possible to do an iterative in-order-traversal on a BST whose node has a parent pointer (the parent of the root is null) without using a visited flag or a stack?

I googled and didn’t find a reply. The point is, how can I know – at a certain node – that I’ve just come to it vs I’ve finished everything underneath 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-02T20:53:42+00:00Added an answer on June 2, 2026 at 8:53 pm

    You can do that, you just need to remember the last visited node along with the current node. Doing this is not disallowed by the problem statement: both visited flag on each node and a stack are (worst case) O(n), remembering the last node is just O(1).

    In C#, the algorithm could look like this:

    static void Walk(Node node)
    {
        Node lastNode = null;
        while (node != null)
        {
            if (lastNode == node.Parent)
            {
                if (node.Left != null)
                {
                    lastNode = node;
                    node = node.Left;
                    continue;
                }
                else
                    lastNode = null;
            }
            if (lastNode == node.Left)
            {
                Output(node);
    
                if (node.Right != null)
                {
                    lastNode = node;
                    node = node.Right;
                    continue;
                }
                else
                    lastNode = null;
            }
            if (lastNode == node.Right)
            {
                lastNode = node;
                node = node.Parent;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to perform iterative * pre-order * traversal on a binary tree
Using JSTL's forEach tag, is it possible to iterate in reverse order?
Possible Duplicate: Does fast enumeration in Objective-C guarantee the order of iteration? Just a
Possible Duplicate: Iterating through a LinkedHashMap in reverse order How to traverse Linked Hash
Possible Duplicate: Can one do a for each loop in java in reverse order?
I am using a CDbCriteria with its own conditions, with & order clauses. However,
I would like to have your assistance in order to know if it's possible
Possible Duplicate: Why does the order of the loops affect performance when iterating over
Is it possible to iterate through a collection of files in Javascript? I am
Possible Duplicate: C++ STL: Which method of iteration over a STL container is better?

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.