Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

As we have seen, as the traversal mechanisms were intrinsically recursive, the implementation was also easy through a recursive procedure. Though, in the case of a non-recursive method for traversal, it need to be an iterative process; meaning, all of steps for the traversal of a node need to be under a loop so that the similar can be applied to all the nodes in the tree.

Algorithm: Non-recursive preorder binary tree traversal

Stack S

push root onto S

repeat until S is empty

{

v = pop S

if v is not NULL

visit v

push v's right child onto S

push v's left child onto S

}

Program 5 illustrates the program segment for the implementation of non- recursive preorder traversal.

 

/* preorder traversal of a binary tree, implemented via a stack */

void preorder(binary_tree_type *tree)

{

stack_type *stack;

stack = create_stack();

push(tree, stack);          /* push the first element of the tree onto the stack */

while (!empty(stack))

{

tree = pop(stack);

visit(tree);

push(tree->right, stack); /* push right child onto the stack */

push(tree->left, stack);    /* push left child onto the stack */

}

}

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9619100

Have any Question?


Related Questions in Computer Engineering

The contracts manager at a company needs to make a large

The contracts manager at a company needs to make a large legal document available to an overseas customer. However, she has some challenges: The document contains sensitive information; it is too large to send via e-mail ...

What are the best practices to follow for microsoft windows

What are the best practices to follow for Microsoft Windows network security. Which two would you start with and why?

Can someone please wirte a complete algorith in c language

Can someone please wirte a complete algorith in c language that works without any errors on Visual Studio 2015 Given a list of integers, write a C function, similar to the partition process in QuickSort, that will rearra ...

The economic dynamism which is the index of productive

The economic dynamism, which is the index of productive growth in dollars for countries that are designated by the World Bank as middle-income are in table #8.3.9 ("SOCR data 2008," 2013). Compute a 95% confidence interv ...

Question three academically reviewed articles on management

Question: Three academically reviewed articles on Management Information Systems and complete the following activities: 1. Summarize all three (3) articles in 600 words or more in APA format with reference 2. Discuss at ...

Question suppose you were looking at network traffic and

Question : Suppose you were looking at network traffic and saw one computer transmit: Who has 192.168.1.1 And saw the reply 192.168.1.1 is at 00:cc:11:8b:73:22. What process would you be looking at? Why is this process n ...

Can someone please help in this question - if the the price

Can someone please help in this question - If the the price of a pack of 35-count Wipes box-pack increased by 12% while revenue from those wipes increased by 5%. Calculate the own-price elasticity of demand for Wipes box ...

Suppose you are given a six-sided die that might be biased

Suppose you are given a six-sided die, that might be biased in an unknown way. Explain how to use die rolls to generate unbiased coin flips, and determine the expected number of die rolls until a coin flip is generated. ...

You are a systems analyst at outback outsourcing a firm

You are a systems analyst at Outback Outsourcing, a firm that handles payroll processing for many large companies. Outback Outsourcing uses a combination of payroll package programs and in-house developed software to del ...

Suppose that you want an operation for the adt list that

Suppose that you want an operation for the ADT list that adds an array of items to the end of the list. The header of the method could be as follows. public void addAll(T[] items) Write an implementation of this method f ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As