Question
in javascrift please








Given a pointer to the root of a binary tree write a routine that will delete every node in the tree that is currently a leaf
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

Page 1

script> // Binary Search Tree node: // Node class class Node { constructor(data) { this.data = data; this. left = null; this.Page 2

35 36 31 38 39 1/ Method to insert a node in a tree // it iterates over the tree to find the location / at which the new node

Page 3

removeLeaf (node) { if (node === null) { return null; leafNodes = 0; // if the tree is empty then 0 leaf nodes // if data toPage 4
טש1 // create an object for the BST var BST = new BinarySearchTree: // insert nodes to the BinarySearchTree BST.createNewNode

Add a comment
Know the answer?
Add Answer to:
in javascrift please Given a pointer to the root of a binary tree write a routine...
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
  • in java please thanks! Given a pointer to a binary tree write a routine which will...

    in java please thanks! Given a pointer to a binary tree write a routine which will traverse the tree and return the number of nodes in the tree whose information field which is an integer is between 59 and 112 In addition return the value of the node with the largest integer and as well return a count of the number of nodes that have no sons. For the 3rd part do not include nodes that have both right and...

  • java please IV. Given a pointer to a binary tree write a routine which will traverse...

    java please IV. Given a pointer to a binary tree write a routine which will traverse the tree and return the 59 and 112 number of nodes in the tree whose information field which is an integer is between In addition return the value of the node with the largest integer and as well return a count or the number of nodes that have no sons. For the 3rd part do not include nodes that have both right and left...

  • Given a pointer to a binary tree write a routine which will traverse the tree and...

    Given a pointer to a binary tree write a routine which will traverse the tree and return number of nodes in the tree who have just a right son or just a left son (do not include nodes have both right and left sons as well as do not include any nodes that do not have any sons at all).

  • CODE IN JAVA** V. Given a pointer to the root of a binary tree and a...

    CODE IN JAVA** V. Given a pointer to the root of a binary tree and a pointer ‘p’ to a given node in the tree and a second pointer ‘q’ to another node in the tree write a routine which will return the total number of nodes in the tree that are on level ‘p’ and ‘q’. If they are on the same level you should multiply the answer by 3.

  • In C++ Given a pointer to the root of a binary search tree (has left, right,...

    In C++ Given a pointer to the root of a binary search tree (has left, right, and parent pointers as well as a data section ) write a function (or functions) which will return an STL list (you should not define this class, it’s already included) with all of the values from the tree in sorted order. Your code should run in theta(N) time. for the second part,.given a pointer to the first node of a linked list, you are...

  • Write a Java function named smallcount that, given the pointer to the root of a Binary...

    Write a Java function named smallcount that, given the pointer to the root of a Binary Search Tree (BST) and a key K, returns the number of nodes having key values less than or equal to K. Function smallcount should visit as few nodes in the BST as possible.

  • A balanced binary tree is a binary tree structure in which the left and right subtrees of every node differ

    Data structures C++1- A balanced binary tree is a binary tree structure in which the left and right subtrees of every node differ in height by no more than 1 Out of the following choices, which is the minimum set of nodes, if removed, will make the BST balanced?2- Which of the following is true for Red-Black Trees ? Select all choices that apply! Select one or more: a. For each node in the tree, all paths from that node to any leaf nodes contain...

  • Which of the following is true for a Binary Tree? Question 7 options: A binary tree...

    Which of the following is true for a Binary Tree? Question 7 options: A binary tree is a tree, since no node has more than 2 children, they are known as the left child and the right child The root node is the node without a parent A leaf node is a node without child nodes All of the above

  • Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary...

    Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary tree. Add this function to the class binaryTreeType and create a program to test this function. #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType { elemType info; nodeType<elemType> *lLink; nodeType<elemType> *rLink; }; //Definition of the class template <class elemType> class binaryTreeType { public: //Overload the assignment operator. const binaryTreeType<elemType>& operator=(const binaryTreeType<elemType>&) { if (this != &otherTree) //avoid self-copy...

  • 2. A regular binary tree is a binary tree whose internal nodes all have two subtrees...

    2. A regular binary tree is a binary tree whose internal nodes all have two subtrees (left and right). In other words, all their nodes have either zero subtrees (in which case they are leaves) or two subtrees (in which case they are internal nodes). Suppose that you have a boolean function that tells you, for each node of the tree, whether it is a leaf or not (call it: leaf(n), for node n). a) Write a recursive function that...

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