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 I 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
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 I 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
Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Modularization Techniques
Section: Chapter Questions
Problem 14RQ
Related questions
Question
Please help me with these questions. I am having trouble understanding what to do
Use Js, css, and html
Thank you
![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 I 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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe3935a4e-65b5-4e47-bf60-1d363b9e3dcc%2Fcfdf8ee8-b7b0-424e-b799-42e126953754%2Fikfnumb_processed.png&w=3840&q=75)
Transcribed Image Text: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 I 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
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning