Question

In: Computer Science

Q1: The sorted values array contains the sixteen integers 1, 2, 3, 13, 13, 20, 24,...

Q1:

The sorted values array contains the sixteen integers 1, 2, 3, 13, 13, 20, 24, 25, 30, 32, 40, 45, 50, 52, 57, 60. How many recursive calls are made by our binarySearch method, given an initial invocation of binarySearch(25, 0, 15)?

Answer Choices :

3

   

2

   

4

   

0

   

1



Q2:

The sorted values array contains the sixteen integers 1, 2, 3, 13, 13, 20, 24, 25, 30, 32, 40, 45, 50, 52, 57, 60. How many recursive calls are made by our binarySearch method, given an initial invocation of binarySearch(24, 0, 15)?

Answer Choices :

1

   

4

   

2

   

3

   

0



Q3:

The number of recursive calls that a method goes through before returning is called:

Answer Choices:

combinatorial recursive count.

   

activation stack frame.

   

the depth of recursion.

   

order of growth efficiency.

Q4:

All programming languages support recursion.

Group of answer choices:

True

False

Solutions

Expert Solution

Q1. The answer is 0.

It is because in the process of binary search we find the low,high index of the sorted array. Then we find the mid value

ie. mid =( low +high)/2

If the mid value represents the number we are searching, then we stop. So no need for further checking and no recursive call. In the above case low=0, high=15 so mid=(0+15)/2 = 7.5=7(round off to smallest integer value)

At the index 7 we have 25 , that is we found what we are searching. So no recursive call . Answer 0

Q2. The answer is 3.

All the rules and formula applies as above.

step1: mid= (0+15)/2=7.5=7

value at 7 is 25 ie grater than 24(we are searching). so low=0,high=mid-1=7-1=6

RECURSION 1

step2: mid=(0+6)/2=3

value in 3 =13 is lower than 24 . so low=mid+1= 3+1=4, high=6

RECURSION 2

step3:mid= (4+6)/2=5

value(5)=20 is less than 24. low=5+1=6, high=6

RECURSION 3

step4: mid=(6+6)/2=6

value at 6= 24.

So we can stop.

So the no oof recursive call is 3

Q3. The no of recursive calls that is taken before returning is called the depth of recursion


Related Solutions

Q4: . The sorted values array contains the sixteen integers 1, 2, 3, 13, 13, 20,...
Q4: . The sorted values array contains the sixteen integers 1, 2, 3, 13, 13, 20, 24, 25, 30, 32, 40, 45, 50, 52, 57, 60. How many recursive calls are made by our binarySearch method given an initial invocation of binarySearch(45, 0, 15)? Answer Choices : 2     0     3     4     1
Run Solver.java, where 20 array instances of 1M random integers are sorted (using Insertion- sort and...
Run Solver.java, where 20 array instances of 1M random integers are sorted (using Insertion- sort and Heap-sort, respectively). Solver.java is given, however the two sorting algorithms of course are implemented by yourself. Report the time elapsed running Solver.java, using Insertion-sort, and Heap-sort, respectively. Based on your results, comment comparatively on time-efficiency of the two sorting algorithms ////// public class Solver {    public static void main(String[] args) { final int SIZE = 1000000; // 1 million final int Instances=20; int[][]...
1. Given an array of integers a dimension n. If the array contains the same number...
1. Given an array of integers a dimension n. If the array contains the same number of even and odd elements get (a1 + an) (a2 + an-1) ... 2. Given an array of integers dimension n. All array elements with even numbers preceding the first element to the maximum, multiplied by the maximum. 3. Given an array of dimension n. Insert after each zero element of the element in the middle (or the amount of secondary elements for even...
Python Question: Write a function that checks to see if an array of integers is sorted...
Python Question: Write a function that checks to see if an array of integers is sorted in an increasing fashion, returning true if it is, false otherwise. Test it with at least4 arrays - 2 sorted and 2 not sorted. Use a CSV formatted input file as described in the previous question to run your program through some tests, where again the filename is passed as an argument. Heres what I have so far: import sys # command line arguement...
Write a program to compute intersection of two sorted array of integers and compute the CPU...
Write a program to compute intersection of two sorted array of integers and compute the CPU time for different sets of unsigned integers generated by a random number generator. Test this using the same data sets: atleast 3 of size 1000 integers, atleast 3 of size 10000 integers, atleast 3 of size 100000 integers, atleast 3 of one million integers and atleast 3 of size 10 million integers DONT FORGET CPU TIME FOR EACH ONE NO HASH SET
you are asked to implement a C++ class to model a sorted array of unsigned integers....
you are asked to implement a C++ class to model a sorted array of unsigned integers. The class is to be used in an embedded application that cannot assume the presence of the STL. The array has to be dynamically allocated in such a way that allows programmers using it to specify the required size. Class will provide (1) provide the appropriate constructors and destructor; (2) provide methods for updating, and showing numbers in/to the array (e.g., to be used...
1. Read 20 integers into an array. Next, use the unique algorithm to reduce the array...
1. Read 20 integers into an array. Next, use the unique algorithm to reduce the array to the unique values entered by the user. Use the copy algorithm to display the unique values. 2. Modify the Exercise 1 above to use the unique_copy algorith. The unique values should be inserted into a vector that's initially empty. Use a back_inserter to enable the vector to grow as new items are added. Use the copy algorithm to display the unique values.
An array A[0..n - 2] contains n-1 integers from 1 to n in increasing order. (Thus...
An array A[0..n - 2] contains n-1 integers from 1 to n in increasing order. (Thus one integer in this range is missing.) Design an algorithm in ​(Theta(log n)) to find the missing integer. Your algorithm should be given in pseudo code. For example, the array A could be {1, 2, 3, 4, 6, 7, 8, 9, 10} in which 5 is missing.
We are given a non sorted array so that the values are not pairwise disjoint (the...
We are given a non sorted array so that the values are not pairwise disjoint (the same values may appear in many entries). Say that we can find the k-th smallest element number in the array in time O(n) for any 1 <= k <= n. Give an algorithm that finds if there is a value that appears at least n/3 times. Please explain the algorithm in words and analyze the run time.
Array indices must be positive integers or logical values?
How can I fix this MATLAB error Index in position 2 is invalid. Array indices must be positive integers or logical values?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT