answersLogoWhite

0

Use depth-first traversal. By convention, binary trees place lower values in the left branch and larger or equal values in the right branch. Given any node in the tree (starting from the root), output all the values to the right of that node, then output the node's value, and finally output all the values to the left of that node. The algorithm can be implemented recursively as follows:

void print_descending (node* n) {

if (n->right) print_descending (n->right); // recursively output all values greater than or equal to n->data

printf ("%d\n", n->data); // output the data (assumes an integral type)

if (n->left) print_descending (n->left); // recursively output all values less than n->data

}

User Avatar

Wiki User

7y ago

What else can I help you with?

Related Questions

What is the time complexity of binary tree traversal?

The time complexity of binary tree traversal is O(n), where n is the number of nodes in the tree.


What is the time complexity of inorder traversal in a binary tree?

The time complexity of inorder traversal in a binary tree is O(n), where n is the number of nodes in the tree.


Which of the following traversal is used for printing the keys of binary search tree in ascending order?

In order traversal is used.


What is the significance of the reverse postorder traversal in binary trees?

Reverse postorder traversal in binary trees is significant because it allows for efficient processing of nodes in a specific order: right child, left child, root. This traversal method is useful for tasks like deleting nodes or evaluating expressions in a tree structure.


Is sorting a binary search tree simple?

A binary search tree is already ordered. An in order traversal will give you a sorted list of nodes.


C program which accepts in order and preorder traversal outputs of a binary tree as input and prints the corresponding binary tree?

any body can help on this ?


What is the definition of binary sequence?

A binary sequence is one in which only two different values are allowed. In computers, 1 and 0 are the conventional ones. So 10100110001 is a binary sequence. The sex of children born to a given set of parents could be b,g,g,b. This is a binary sequence. There is no conceptual limit to the length of a binary sequence.


What is the purpose of performing a binary search tree inorder traversal?

Performing a binary search tree inorder traversal helps to visit all nodes in the tree in ascending order, making it easier to search for specific values or perform operations like sorting and printing the elements in a sorted order.


What is 16 in binary sequence?

16 (decimal) = 10000 (binary).


What is the process for conducting a reverse in-order traversal of a binary tree?

To conduct a reverse in-order traversal of a binary tree, start at the right child, then visit the root node, and finally visit the left child. Repeat this process recursively for each node in the tree until all nodes have been visited.


How do you print all data in a Binary Search Tree?

By using Depth First Search or Breadth First search Tree traversal algorithm we can print data in Binary search tree.


Definition of threaded binary tree?

A binary tree variant that allows fast traversal: given a pointer to a node in a threaded tree, it is possible to cheaply find its in-order successor (and/or predecessor).