Question

In: Advanced Math

Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int...

  1. Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function:

int BBOX(int n, int k)

            if (n <= 0) return 0;

            else if (A[n] < k) return (1+ 2*BBOX(n-1,k+1));

            else return BBOX(n-1,k-2);

            Find BBOX(8, 5)

Solutions

Expert Solution

If you find my answer useful please put thumbs up. Thank you.

Explaination of the function BBOX(int n, int k):

  1. The value of n is checked first. If the value of n is less than or equal to 0, then the programs returns zero. If the value of n is not less than or equal to 0, then go to step 2.
  2. Here, the value of A[n] is compared with the value of k. If A[n] is less than the value of k, then the program recursively calls itself, i.e BBOX(n-1, k+1). Then multiplies its value with 2, adds 1 and retuens the final value. If the condition is not true, i.e if A[n] is not less than k then go to step 3.
  3. Here, the function calls itself BB)X(n-1, k-2)

The working of the function call BBOX(8,5) is shown below


Related Solutions

Consider the following function ?(?) = ?^ 4+ 2? ^3 + 8?^ 2+ 5? With the...
Consider the following function ?(?) = ?^ 4+ 2? ^3 + 8?^ 2+ 5? With the initial guesses of ?1 = −2, ?2 = −1, and ?3 = 1, find the minimum of the given function using parabolic interpolation. Perform five iterations, reporting Ɛa based on the location of the minimum (i.e. xopt) and not the actual minimum value. (Round the final answer to four decimal places.)
Consider the following sorted int array: 1 3 4 5 7 9 10 12 If we...
Consider the following sorted int array: 1 3 4 5 7 9 10 12 If we search for the key value 10 in the array using the binary search algorithm, what is the sequence of indices that will be accessed in the array? (Hint: For a sublist between index values low and high, the middle index is calculated using: (low + high) / 2. So you need to show the sequence of indices of the middle index in each pass.)...
1.Consider the program: .data myArray: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
1.Consider the program: .data myArray: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 .text la $s0, myArray li $s1, 0 loop: sll $t0, $s1, 2 add $t0, $t0, $s0 lw $s2, 0($t0) lw $s3, 4($t0) add $s2, $s2, $s3 sw $s2, 0($t0) addi $s1, $s1, 1 slti $t1, $s1, 9 bne $t1, $zero, loop .end Explain what does this program do? How is the data bound from the .data segment to the base address register $s0? What...
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8...
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8 −9 6) (1) Count the number of rows that contain negative components. (2) Obtain the inverse of A and count the number of columns that contain even number of positive components. (3) Assign column names (a,b,c,d) to the columns of A. (4) Transform the matrix A into a vector object a by stacking rows. (5) Replace the diagonal components of A with (0,0,2,3). Hint:...
5.) For the data set 2 4 4 5 7 8 9 10 12 12 13...
5.) For the data set 2 4 4 5 7 8 9 10 12 12 13 13 16 16 16 16 17 19 19 20 23 24 24 24 25 26 26 27 28 28 29 31 32 34 34 36 37 38 42 44 45 46 47 47 48 50 52 53 53 54 55 56 56 57 58 (a) Find the 80th percentile. The 80t percentile is =    (a) Find the 42nd percentile. The 42nd percentile is...
5. (20%) Suppose we have an array int a [8] = {1, 2, 3, 5, 6};...
5. (20%) Suppose we have an array int a [8] = {1, 2, 3, 5, 6}; and we also have a linked list L of 5 entries 1 -> 2 -> 3 -> 5 -> 6, where 1 is the first in the linked list L, followed by 2 etc. We want to put a new item 4 between 3 and 5 in the array a and in the linked list L (a) Explain in plain English how you do...
Year 1 2 3 4 5 6 7 8 9 10 A 1 1.01 1.0201 1.0303...
Year 1 2 3 4 5 6 7 8 9 10 A 1 1.01 1.0201 1.0303 1.0406 1.0510 1.0615 1.0721 1.0829 12.0305 B 1 .9900 .9801 .9703 .9606 .9510 .9415 .9321 .9227 10.0487 Assume a purchase price of $10 Million for both properties. (a) What is the expected total return (IRR) on a 10-year investment in each property? Use a financial calculator or equation solver for this. (b) If the 10% cap rate represents a fair market value for each...
Consider the following set of observations: Obs. 1 2 3 4 5 6 7 8 9...
Consider the following set of observations: Obs. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 input 1 2 3 4 5 6 7 8 9 10 11 12 13 14 result 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Enter the data in L1 and L2 in your TI calculator, find the regression line, and construct a scatterplot with the regression line included. Does a line appear to...
Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write...
Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write a list comprehension to extract the first column of the matrix [1, 4, 7]. Write another list comprehension to create a vector of twice the square of the middle column.
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5]...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5] D = [1, -9, 5, -3] E = [3, 3, -1] Uz = 1/|z| ^z d(X,Y) = (Rθ) d = diameter R = Radius θ = Theta Find a. Uc b. d (D, C) c. Let P = B + 3E, UP = d. A x B e. 3B x E f. C x D
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT