b. Problem 2. Again, create an array of 30 random numbers that range between 1 and 100. 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 findB(x,A), where x is the number we are looking for and A is an array. In the body of the function, compare x with the MIDDLE item that is in the array. If this item is equal to X, 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+1 to A.length-1 in one array and call it A1. Place items at indices 0 to mid (excluding mid) in an array called A2. Then, recursively call findB(x,Al) and findB(x,A2). If you call find on an empty list, you will want to return false. Writing any explicit loop in your code results a 0 for this question. Remember to provide pre- and post-conditions. 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 findB(x,A) for when A and x are initially [1, 6, 10, 14, 77, 82, 100] and 77, respectively. As a guideline, we have populated the tables with the values for the first 2 calls and the corresponding returned values for each of those calls. Again remember that, the call numbers will be populated top down (i.e. time elapses from row x to row x+1) while returned values are populated bottom-up (i.e. the value in row x is returned before the value in rowx-1). You may want to use console.log to observe these values when you write your solution. call# A value returned to this call 1 77 [1, 6, 10, 14, 77, 82, 100] TRUE 2 77 [77, 82, 100] TRUE

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
b. Problem 2. Again, create an array of 30 random numbers that range between 1 and
100. 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 findB(x,A), where x is the number we are
looking for and A is an array. In the body of the function, compare x with the MIDDLE
item that is in the array. If this item is equal to X, 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+1 to A.length-1 in one array and call it A1.
Place items at indices 0 to mid (excluding mid) in an array called A2.
Then, recursively call findB(x,Al) and findB(x,A2). If you call find on an empty
list, you will want to return false.
Writing any explicit loop in your code results a 0 for this question. Remember to provide
pre- and post-conditions. 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
findB(x,A) for when A and x are initially [1, 6, 10, 14, 77, 82, 100] and 77,
respectively. As a guideline, we have populated the tables with the values for the
first 2 calls and the corresponding returned values for each of those calls. Again
remember that, the call numbers will be populated top down (i.e. time elapses from
row x to row x+1) while returned values are populated bottom-up (i.e. the value in
row x is returned before the value in rowx-1). You may want to use console.log to
observe these values when you write your solution.
call#
A
value returned to
this call
1
77
[1, 6, 10, 14, 77, 82, 100]
TRUE
2
77
[77, 82, 100]
TRUE
Transcribed Image Text:b. Problem 2. Again, create an array of 30 random numbers that range between 1 and 100. 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 findB(x,A), where x is the number we are looking for and A is an array. In the body of the function, compare x with the MIDDLE item that is in the array. If this item is equal to X, 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+1 to A.length-1 in one array and call it A1. Place items at indices 0 to mid (excluding mid) in an array called A2. Then, recursively call findB(x,Al) and findB(x,A2). If you call find on an empty list, you will want to return false. Writing any explicit loop in your code results a 0 for this question. Remember to provide pre- and post-conditions. 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 findB(x,A) for when A and x are initially [1, 6, 10, 14, 77, 82, 100] and 77, respectively. As a guideline, we have populated the tables with the values for the first 2 calls and the corresponding returned values for each of those calls. Again remember that, the call numbers will be populated top down (i.e. time elapses from row x to row x+1) while returned values are populated bottom-up (i.e. the value in row x is returned before the value in rowx-1). You may want to use console.log to observe these values when you write your solution. call# A value returned to this call 1 77 [1, 6, 10, 14, 77, 82, 100] TRUE 2 77 [77, 82, 100] TRUE
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education