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...

  • C++ ONLY Threaded Binary Search Tree Since a binary search tree with N nodes has N...

    C++ ONLY Threaded Binary Search Tree Since a binary search tree with N nodes has N + 1 NULL pointers, half the space allocated in a binary search tree for pointer information is wasted. Suppose that if a node has a NULL left child, we make its left child pointer link to its inorder predecessor, and if a node has a NULL right child, we make its right child pointer link to its inorder successor. This is known as a...

  • 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

  • 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...

  • 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...

  • in python 11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree...

    in python 11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree You will also need to implement a Node class. This class will not be tested, but is needed to implement the BST. Your BST must implement the following methods. You are free to implement additional helper methods. It is recommended you create your own helper methods Constructor: Creates an Empty Tree String Method: Returns the string "Empty Tree" for an empty tree. Otherwise, returns...

  • Using the following implementation of Tree class Node   {   public int iData;              // data item (key)   public...

    Using the following implementation of Tree class Node   {   public int iData;              // data item (key)   public double dData;           // data item   public Node leftChild;         // this node's left child   public Node rightChild;        // this node's right child   public void displayNode()      // display ourself      {      System.out.print('{');      System.out.print(iData);      System.out.print(", ");      System.out.print(dData);      System.out.print("} ");      }   }  // end class Node //------------------------------------------------------------------ import java.io.IOException; import java.util.Stack; public class Tree { private Node root; // first node of tree // ------------------------------------------------------------- public Tree() // constructor { root = null; }...

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