Binary tree traversals, Data Structure & Algorithms

Assignment Help:

 We have discussed already about three tree traversal methods in the earlier section on general tree. The similar three different ways to do the traversal -inorder , preorder, and postorder are applicable to binary tree also.

Let us discuss the inorder binary tree traversal for given binary tree:

We begin from the root i.e. * we are assumed to visit its left sub-tree then visit the node itself & its right sub-tree. Here, root contain a left sub-tree rooted at +. Thus, we move to + and verify for its left sub-tree (we are supposed repeat this for each node). Again, + contain a left sub-tree rooted at 4. Thus, we need to check for 4's left sub-tree now, however 4 doesn't have any left sub-tree and therefore we will visit node 4 first (print in our case) and verify for its right sub-tree. As 4 doesn't contain any right sub-tree, we'll go back & visit node +; and verify for the right sub-tree of +. It contains a right sub-tree rooted at 5 and thus we move to 5. Well, 5 don't have any left or right sub-tree. Thus, we just visit 5 (print 5) and track back to +. As we already have visited + thus we track back to * . As we are yet to visit the node itself and thus we visit * before checking for the right sub-tree of *, which is 3. As 3 do not have any left or right sub-trees, we visit 3 . Thus, the inorder traversal results in 4 + 5 * 3


Related Discussions:- Binary tree traversals

Array-based representation of a binary tree, Assume a complete binary tree ...

Assume a complete binary tree T with n nodes where each node has an item (value). Label the nodes of the complete binary tree T from top to bottom & from left to right 0, 1, ..., n

Determine the disjoint of division method, Determine the Disjoint of divisi...

Determine the Disjoint of division method A polygon is disjoint from the viewport if the x- and y-extents of the polygon do not overlap the viewport anywhere. In this case; reg

Explain insertion sort, Q. Explain the insertion sort with a proper algorit...

Q. Explain the insertion sort with a proper algorithm. What is the complication of insertion sort in the worst case?

Calculate the k-th power and recursive algorithem, 1. The following is a r...

1. The following is a recursive algorithm to calculate the k -th power of 2. Input k a natural number Output kth power of 2 Algorithem: If k =0then return 1 Else return 2* po

Write an algorithm outputs number of books using psuedocode, A shop sells b...

A shop sells books, maps and magazines. Every item is identified by a unique 4 - digit code. All books have a code starting with a 1, all maps have a code which starts with a 2 and

What is called the basic operation of an algorithm, What is called the basi...

What is called the basic operation of an algorithm? The most significant operation of the algorithm is the operation contributing the most to the total running time is known as

Array vs. ordinary variable, Q. Describe what do you understand by the term...

Q. Describe what do you understand by the term array? How does an array vary from an ordinary variable? How are the arrays represented in the specific memory?

Explain time complexity, Time Complexity, Big O notation The amount of ...

Time Complexity, Big O notation The amount of time needed by an algorithm to run to its completion is referred as time complexity. The asymptotic running time of an algorithm i

Storing a sparse matrix in memory, Explain an efficient method of storing a...

Explain an efficient method of storing a sparse matrix in memory. Write a module to find the transpose of the sparse matrix stored in this way. A matrix which contains number o

Explain the stack, QUESTION Explain the following data structures: ...

QUESTION Explain the following data structures: (a) List (b) Stack (c) Queues Note : your explanation should consist of the definition, operations and examples.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd