Write a recursive function BSTsmallcount
that, given a BST and a value key
, returns the number of nodes having values less than key
. Your...
Search Results
Searching for: binary search trees
Individual Exercises
Write a recursive function that returns true if there is a node in the given binary tree with the given value, and false otherwise. Note...
Write a recursive function to set the value for each node in a binary tree to be its depth then return the modified tree. Assume that...
We define a "root-to-node path" to be any sequence of nodes in a tree starting with the root and proceeding downward to a given node. The...
Write a recursive function int BTsumall(BinNode root)
that returns the sum of the values for all of the nodes of the binary tree with...
Given two binary trees, return true if they are identical (they have nodes with the same values, arranged in the same way).
Here are...
The height of a binary tree is the length of the path to the deepest node. An empty tree has a height of 0, a tree with one node has a...
Given a binary tree, check if the tree satisfies the property that for each node, the sum of the values of its left and right children...
Write a recursive function int BTleaf(BinNode root)
to count the number of leaf nodes in the binary tree pointed at by root
. You must use...
Given two binary trees, return true if and only if they are mirror images of each other. Note that two empty trees are considered mirror...
Given two binary trees, return true if and only if they are structurally identical (they have the same shape, but their nodes can have...
Given a binary tree, write a recursive function to return the difference between the sum of all node values at odd levels and sum of all...
Write a recursive function that increments by one the value for every node in the binary tree pointed at by root
, then returns the...
What is the average time complexity for inserting an element into a binary search tree?
Complete the following binary search method. Find the number num
in the array array
. Return -1 if the number is not found. You may assume...
Which operation has a different Big O complexity from the others?
Write an algorithm that takes an ArrayList and uses a recursive binary search to return both the index of a given String, or -1 if the...
Write a recursive function int countBTleaves(BinNode root)
to count the number of leaf nodes in the binary tree pointed at by root
. You...
Below is an implementation of binary search on a list of integers. Fill in the remaining lines to complete the method. You can always...
Below is an implementation of binary search on a list of objects of type T. In this case, you can assume that T will always extend...
The animated image below shows a traversal of a binary tree. Which type of traversal is it?
The animated image below shows a traversal of a binary tree. Which type of traversal is it?
The animated image below shows a traversal of a binary tree. Which type of traversal is it?
The image below shows an in progress inorder traversal. The nodes highlighted in purple have already been visited in order (e.g. 36 14 24...
The image below shows a binary tree. Which of the options below include only internal nodes?