When the index is known, what is the time complexity for accessing an element in an array list?
Recursion and Big O Exercises
Score: 0 / 46.0
Exercises
What is the complexity of searching an ArrayList?
Given an array of int
s, compute recursively the number of times that the value 11 appears in the array (no loops). We'll use the...
Given a non-negative int n
, compute recursively (no loops) the count of the occurrences of 8 as a digit, except that an 8 with another 8...
Given a non-negative int n
, return the sum of its digits recursively (no loops). Note that mod (%
) by 10 yields the rightmost digit (126...
Given a string, compute recursively a new string where all the adjacent chars are now separated by a "*". So given "hello", return...
Given a string, compute the number of times lowercase "hi" appears in the string. Make the countHi
be recursive.
Given a string that contains a single pair of parenthesis, compute recursively a new string containing only the parentheses and their...
Count recursively (no loops) the total number of "abc" and "aba" substrings that appear in the given string.
Given a string, compute recursively (no loops) a new string where all the lowercase 'x' chars have been changed to 'y' chars.
Given a string str
and a non-empty substring sub
, compute recursively the largest substring which both starts and ends with sub
and...
Given base
and n
that are both 1 or more, compute recursively (no loops) the value of base
to the n
power, so powerN(3, 2)
is 9 (3...
Given a string, compute recursively a new string where all the 'x' chars have been removed.
Write the missing base case for function largest
. Function largest
should find the largest number in array numbers
. When largest
is first...
For function multiply
, write the missing base case condition and action. This function will multiply two numbers x
and y
. You can assume...
For function sumtok
, write the missing recursive call. This function returns the sum of the values from 1 to k
.
For function countChr()
write the missing part of the recursive call. This function should return the number of times that the letter "A"...
When a method is directly recursive, what does it call?
Use the following recursive method:
public int mysteryMethod(int n) { if (n < 0) { return 5; } else { return mysteryMethod(n - 1) +...
This method returns the value of the minimum element in the subsection of the array "y", starting at position "first" and ending at...