Task 1: In this task, you will complete four recursive functions and trace them for some sample inputs. a. Create an HTML file that includes five buttons with the following labels: "recursive find A", "recursive find B", "recursive find C", "recursive palindrome", and "recursive count asterisks”. Create a div in your HTML to hold the results of calls to corresponding javascript methods. You can style this page as you like. Feel free to use the HTML and CSS from prior labs as a template, if you like. b. Create a JavaScript file that responds to clicks of these buttons. All implementations should be recursive. a. Problem 1. Create an array of 30 random numbers that range between 1 and 100. Then, write a function that will receive a number from the user and determine if that number exists in the array or not. For instance, assume the array is: [2, 93, 14, 89, 12, 3, 81, 15, 14, 89, 52, 96, 71, 82, 5, 2, 41, 23, 52, 59, 44, 44, 88, 39, 49, 50, 97, 45, 48, 36] Now, assume the user enters 89, the program should output true. But, if the user enters 77, the program should output false. Approach: We will be implementing this method in two different ways. Both will be recursive. First, implement a method called findA (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 FIRST item that is in the array. If this first item is equal to X, return true. If not, remove the first item from A and call findA(x,A) on the revised list. 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? Next, copy the following trace table in your Word file and trace the input values to the function findA(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. Note that in this example, 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# x A value returned to this call 1 77 [1, 6, 10, 14, 77, 82, 100] TRUE 2 77 [6, 10, 14, 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

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter8: Working With Trendlines, Pivottables, Pivotcharts, And Slicers
Section: Chapter Questions
Problem 8EYW
icon
Related questions
Question

Provide pre and post condition as well as truth table for the below. Thank you

Task 1: In this task, you will complete four recursive functions and trace them for some sample inputs.
a.
Create an HTML file that includes five buttons with the following labels: "recursive find A",
"recursive find B", "recursive find C", "recursive palindrome", and "recursive count
asterisks”. Create a div in your HTML to hold the results of calls to corresponding javascript
methods. You can style this page as you like. Feel free to use the HTML and CSS from prior
labs as a template, if you like.
b. Create a JavaScript file that responds to clicks of these buttons. All implementations should
be recursive.
a. Problem 1. Create an array of 30 random numbers that range between 1 and 100.
Then, write a function that will receive a number from the user and determine if
that number exists in the array or not.
For instance, assume the array is:
[2, 93, 14, 89, 12, 3, 81, 15, 14, 89, 52, 96, 71, 82, 5, 2, 41, 23, 52, 59, 44, 44, 88, 39,
49, 50, 97, 45, 48, 36]
Now, assume the user enters 89, the program should output true. But, if the user
enters 77, the program should output false.
Approach:
We will be implementing this method in two different ways. Both will be recursive.
First, implement a method called findA (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 FIRST item that
is in the array. If this first item is equal to X, return true. If not, remove the first item
from A and call findA(x,A) on the revised list. 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?
Next, copy the following trace table in your Word file and trace the input values to
the function findA(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. Note
that in this example, 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#
x
A
value returned to
this call
1
77
[1, 6, 10, 14, 77, 82, 100]
TRUE
2
77
[6, 10, 14, 77, 82, 100]
TRUE
Transcribed Image Text:Task 1: In this task, you will complete four recursive functions and trace them for some sample inputs. a. Create an HTML file that includes five buttons with the following labels: "recursive find A", "recursive find B", "recursive find C", "recursive palindrome", and "recursive count asterisks”. Create a div in your HTML to hold the results of calls to corresponding javascript methods. You can style this page as you like. Feel free to use the HTML and CSS from prior labs as a template, if you like. b. Create a JavaScript file that responds to clicks of these buttons. All implementations should be recursive. a. Problem 1. Create an array of 30 random numbers that range between 1 and 100. Then, write a function that will receive a number from the user and determine if that number exists in the array or not. For instance, assume the array is: [2, 93, 14, 89, 12, 3, 81, 15, 14, 89, 52, 96, 71, 82, 5, 2, 41, 23, 52, 59, 44, 44, 88, 39, 49, 50, 97, 45, 48, 36] Now, assume the user enters 89, the program should output true. But, if the user enters 77, the program should output false. Approach: We will be implementing this method in two different ways. Both will be recursive. First, implement a method called findA (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 FIRST item that is in the array. If this first item is equal to X, return true. If not, remove the first item from A and call findA(x,A) on the revised list. 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? Next, copy the following trace table in your Word file and trace the input values to the function findA(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. Note that in this example, 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# x A value returned to this call 1 77 [1, 6, 10, 14, 77, 82, 100] TRUE 2 77 [6, 10, 14, 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
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
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage