Please help me with this: using js create an array of 30 random numbers that range between 1and 100. And yet again, write a function that will receive a number from the userand determine if that number exists in the array or not. But this time, start bySORTING your input list. After a sort, the list in problem 1 is as follows:[2, 2, 3, 5, 12, 14, 14, 15, 23, 36, 39, 41, 44, 44, 45, 48,49, 50, 52, 52, 59, 71, 81, 82, 88, 89, 89, 93, 96, 97] Approach: Implement a method called findC(x, A, i, j), where x is the number we arelooking for in array A, the first index of the array is i and the last index is j. We wantto determine whether x exists in A anywhere between index i and index j. Your firstcall to this method will therefore look like this: findC(x, A, 0, A.length-1). In the body of your function, compare x with the item that is in the middle of thearray, as you did before. As before, call the middle of index of the array mid. But thistime, if x<=a[mid], recursively call your function to search ONLY the first half of thearray, i.e. between index i and mid. If x>a[mid], recursively call your function tosearch ONLY the second half of the array, i.e. from mid+1 to j. If you call findC(x, A, i, j) when i is equal to j, note that there is only oneelement in the range. In this case, compare x with a[i] (or a[j]). If they are equal,return true, otherwise return false. If you call the function when j<i, that also meansx does not exist in A and you should return false. Writing any explicit loop in your code results a 0 for this question. Remember to providepre- and post- conditions. How many recursive calls will you need to search the entirelist? Do you think this implementation will run more quickly than your otherimplementations? Why or why not? Now copy the trace table below in your Word file and trace your functionfindC(x,A,i,j) for when A, x, i, and j are initially [1, 6, 10, 14, 77, 82, 100],77, 0, and 7, respectively. As a guideline, we have populated the tables with thevalues for the first 2 calls and the corresponding returned values for each of thosecalls.                  Call#                       X                     A Value Returened to this  Call 1 77 [1, 6, 10, 14, 77, 82, 100]  TRUE 2 77 [77, 82, 100] TRUE Thank you

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

Please help me with this: using js

create an array of 30 random numbers that range between 1
and 100. And yet again, write a function that will receive a number from the user
and determine if that number exists in the array or not. But this time, start by
SORTING your input list. After a sort, the list in problem 1 is as follows:
[2, 2, 3, 5, 12, 14, 14, 15, 23, 36, 39, 41, 44, 44, 45, 48,
49, 50, 52, 52, 59, 71, 81, 82, 88, 89, 89, 93, 96, 97]

Approach:

Implement a method called findC(x, A, i, j), where x is the number we are
looking for in array A, the first index of the array is i and the last index is j. We want
to determine whether x exists in A anywhere between index i and index j. Your first
call to this method will therefore look like this: findC(x, A, 0, A.length-1).

In the body of your function, compare x with the item that is in the middle of the
array, as you did before. As before, call the middle of index of the array mid. But this
time, if x<=a[mid], recursively call your function to search ONLY the first half of the
array, i.e. between index i and mid. If x>a[mid], recursively call your function to
search ONLY the second half of the array, i.e. from mid+1 to j.

If you call findC(x, A, i, j) when i is equal to j, note that there is only one
element in the range. In this case, compare x with a[i] (or a[j]). If they are equal,
return true, otherwise return false. If you call the function when j<i, that also means
x does not exist in A and you should 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 other
implementations? Why or why not?

Now copy the trace table below in your Word file and trace your function
findC(x,A,i,j) for when A, x, i, and j are initially [1, 6, 10, 14, 77, 82, 100],
77, 0, and 7, 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 thosecalls.

                 Call#                       X                     A Value Returened to this  Call
1 77 [1, 6, 10, 14, 77, 82, 100]  TRUE
2 77 [77, 82, 100] TRUE

Thank you

 

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

Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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