Answered step by step
Verified Expert Solution
Question
1 Approved Answer
b . Problem 2 . Again, create an array of 3 0 random numbers that range between 1 and And again, write a function that
b Problem Again, create an array of random numbers that range between and
And again, write a function that will receive a number from the user and
determine if that number exists in the array or not.
Approach:
This time, implement a method called indB where is the number we are
looking for and A is an array. In the body of the function, compare with the MIDDLE
item that is in the array. If this item is equal to return true. If not, divide A into
TWO lists as follows:
Call the middle of index of the array mid.
Place items at indices mid to A length in one array and call it A
Place items at indices to mid excluding mid in an array called A
Then, recursively call indB and findB If you call find on an empty
list, you will want to return false.
Writing any explicit loop in your code results a for this question. Remember to provide
pre and postconditions. How many recursive calls will you need to search the entire
list? Do you think this implementation will run more quickly than your first
implementation? Why or why not? How might you limit the number of recursive calls in
your implementation?
Now copy the trace table on the next page in your Word file and trace your function
findBxA for when A and x are initially and
respectively. As a guideline, we have populated the tables with the values for the
first calls and the corresponding returned values for each of those calls. Again
remember that, the call numbers will be populated top down ie time elapses from
row to row while returned values are populated bottomup ie the value in
row is returned before the value in row You may want to use console.log to
observe these values when you write your solution.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started