Question

Let x be an internal node in a binary search tree and y its successor in...

Let x be an internal node in a binary search tree and y its successor in the infix tree-traversal (then x.key cannot be maximal).

Show that either x.right = null and y.left ≠ null, OR x.right ≠ null and y.left = null. (if provide pseudo-code, use Python)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANS:---

# Python Programm for INFIX TREE-TRAVERSAL without recursion

  

# A binary tree node

class Node:

  

# Constructor to create a new node

def _init_(self, data):

self.data = data

self.left = None

self.right = None

  

# Iterative function for inorder tree traversal

def inOrder(root):

  

# Set current to root of binary tree

current = root

stack = [] # initialize stack

done = 0

  

while True:

  

# Reach the left most Node of the current Node

if current is not None:

  

# Place pointer to a tree node on the stack

# before traversing the node's left subtree

stack.append(current)

  

current = current.left

  

  

# BackTrack from the empty subtree and visit the Node

# at the top of the stack; however, if the stack is

# empty you are done

elif(stack):

current = stack.pop()

print(current.data, end=" ") # Python 3 printing

  

# We have visited the node and its left

# subtree. Now, it's right subtree's turn

current = current.right

  

else:

break

print()

  

# Driver program to test above function

  

""" Constructed binary tree is

1

/ \

2 3

/ \

4 5 """

  

root = Node(1)

root.left = Node(2)

root.right = Node(3)

root.left.left = Node(4)

root.left.right = Node(5)

inOrder(root)

NOTE:-Please check the code. If you have any doubts comment below and I am happy to help

Add a comment
Know the answer?
Add Answer to:
Let x be an internal node in a binary search tree and y its successor in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A binary search tree includes n nodes and has an height h. Check all that applies...

    A binary search tree includes n nodes and has an height h. Check all that applies about the space complexity of TREE-MINIMUMX) TREE-MINIMUM () 1 while x. left NIL 2 3 return x x x.left O it is e (lg n) ■ it is 0(h). D it is e (1) ■ It is in place ■ it is Θ (n) A binary search tree includes n nodes and has an height h. Check all that applies about the space complexity...

  • QUESTION 1 In a tree, a ____ is a node with successor nodes. root child descendent...

    QUESTION 1 In a tree, a ____ is a node with successor nodes. root child descendent parent sibling QUESTION 2 In a tree, the ____ is a measure of the distance from a node to the root. count degree branch height level QUESTION 3 Which of the following is not a characteristic of a binary search tree? Each node has zero, one, or two successors. The preorder traversal processes the node first, then the left subtree, and then the right...

  • c++ Let's say sub_root is a node in a given binary search tree. Write a code...

    c++ Let's say sub_root is a node in a given binary search tree. Write a code segment to find the immediate successor of the sub_root

  • An in-order tree walk of an n-node binary search tree can be implemented by finding the...

    An in-order tree walk of an n-node binary search tree can be implemented by finding the minimum element in the tree with TREE-MINIMUM and then making n-1 calls to TREE-SUCCESSOR. Prove that this algorithm runs in Θ(n) time.

  • A Binary Search Tree is a binary tree where nodes are ordered in the following way:...

    A Binary Search Tree is a binary tree where nodes are ordered in the following way: each node contains one key (also known as data) the keys in the left subtree are less than the key in its parent node the keys in the right subtree are greater than the key in its parent node duplicate keys are not allowed Create a Binary Search Tree inserting the following list of numbers in order from left to right. 10,          6,           4,            8,            18,          15,          21 Please type...

  • Binary Search Tree Part A: The code attached in this document is a sample code to demonstrate ins...

    Binary Search Tree Part A: The code attached in this document is a sample code to demonstrate insert operation in binary search tree. Please fill in the missing part for the insert method to make the program work. The expected output should be as follows. 20 30 40 50 60 70 80 Part B: Find Lowest Common Ancestor (LCA) of a Binary Search Tree. According to WikiPedia definition , The lowest common ancestor is defined between two nodes v and...

  • Think about the DELETE(x) operation for a Binary Search Tree with no duplicate elements. Define the...

    Think about the DELETE(x) operation for a Binary Search Tree with no duplicate elements. Define the predecessor of a node x as the node whose value immediately precedes x if you sort all the node values in the tree smallest to largest. Define the successor of a node x similarly -- the one "just after" x. If x has a left child, is the predecessor of x always in x's left sub-tree? If x has a right child, is the...

  • I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if...

    I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if we are to insert following elements into the tree in given order, [34, 12, 23, 27,31,9,11,45, 20, 37. i) Show the resulting balanced binary search tree if we are to insert following sorted elements into the tree, [9,12,21, 23, 29, 31, 34, 45, 48, 52, 55] iii What is the pre-order traversal of the balanced binary search tree? v) What is the post-order traversal...

  • Draw a binary tree T that simultaneously satisfies the following: Each internal node of T stores...

    Draw a binary tree T that simultaneously satisfies the following: Each internal node of T stores a single character A preorder traversal of T yields EXAMFUN An inorder traversal of T yields MAFXUEN

  • QUESTION 8   In the _____ traversal, the root is processed first, before its subtrees. breadth first...

    QUESTION 8   In the _____ traversal, the root is processed first, before its subtrees. breadth first preorder postorder inorder 0.10000 points    QUESTION 9 What kind of traversal does the following algorithm (in pseudo-code) describe? Algorithm traversal (root) if (root is not null)      traversal (leftSubTree)      process (root)      traversal (rightSubTree) end if end traversal breadth first preorder inorder postorder 0.10000 points    QUESTION 10 What kind of traversal does the following algorithm (in pseudo-code)  describe? Algorithm traversal (root) if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT