Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top, sitting on top of a square...
Exercises
Write a recursive function named checkPalindrome
that takes a string as input, and returns true if the string is a palindrome and false...
Write a recursive function that takes a start index, array of integers, and a target sum. Your goal is to find whether a subset of the...
Pascal's triangle is a useful recursive definition that tells us the coefficients in the expansion of the polynomial (x + a)^n. Each...
Use appropriate method calls from the List ADT to create the following list:
< 4 19 | 23 30 >
You should assume that L is passed to...
Write a recursive function BSTsmallcount
that, given a BST and a value key
, returns the number of nodes having values less than key
. Your...
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...
Write a LinkedBag<T>
member method called contains()
that takes an element as a parameter and returns true if the bag contains the...
Given the name of a person and a phrase that person said, return a String
in the following format, including the quotation marks:
...
Given an integer representing the radius of a sphere, compute and return the sphere's volume based on the following formula:
Volume = 4/3...
Given two integers, return true if the first number is evenly divisible by the second, and false otherwise. Return false if the second...
Given three double
values representing prices, return the smallest price. For example, if the values passed in are 19.95, 12.85, and...
Given a day number (1-7), return the day of the week ("Sunday", "Monday", etc.). If an invalid day number is provided, return "Invalid".
...Given two integers low
and high
representing a range, return the sum of the integers in that range. For example, if low
is 12 and high
is...