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...
Exercises
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...
Write a recursive function that increments by one the value for every node in the binary tree pointed at by root
, then returns the...
Write a recursive function to count the number of leaf nodes in the binary tree pointed at by root
. You must use the isLeaf
method to...
We define a "root-to-leaf path" to be any sequence of nodes in a tree starting with the root node and proceeding downward to a leaf. The...
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...
Write a recursive function that returns the sum of the values for all of the nodes of the binary tree with root root
.
Here are methods...
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 they are identical (they have nodes with the same values, arranged in the same way).
Here are...
Given two binary trees, return true if and only if they are structurally identical (they have the same shape, but their nodes can have...
Consider the following class definition:
class Link{
Object data;
Link next;
}
Create a new node with info 'D' and insert it at the end...
Consider the following class definition:
class Link{
Object data;
Link next;
}
Write a while loop to make q refer successively to each...
Consider the following class definition:
class Link{
Object data;
Link next;
}
Link objects can be "linked" together to create a...
Consider the following class definition:
class Link{ public Object data; public Link next; }
In the method below, you will receive a...
Consider the following class definition:
class Link{
Object data;
Link next;
}
Return a reference to the second to last node (null if...
Write a member method balanceBags in Java that implements the following logic: Given a String parameter the methods returns the String...
Consider the following class definition:
class Link{
Object data;
Link next;
}
List L has a reference p to the first node. Write code...
Consider the following class definition:
class Link{
Object data;
Link next;
}
List L has a reference p to the first node. Write code...
Consider the following class definition:
class Link{
Object data;
Link next;
}
List L has a reference p to the first node. Write code...
Consider the following class definition:
class Link{
Object data;
Link next;
}
List L has a reference p to the first node. Write code...
Consider the following class definition:
class Link{
Object data;
Link next;
}
p is a reference to the first node in a List L. Create a...
Write the member method 'playBagBingo()' that implements the player logic for the game described below. Bag Bingo is a game of chance...
For this assignment, create a method that will turn a fixed-size arrayBag into a set.
A Set is an abstract data type somewhat similar...
Consider the following class definition:
class Link{
Object data;
Link next;
}
List L has a reference to the first node. Write code that...
Write an ArrayBasedStack<T>
member method called reverseString()
that takes a String as a parameter, then uses an ArrayBasedStack...