Question

The binary search algorithm is used to search the following array for the value 59. In...

The binary search algorithm is used to search the following array for the value 59. In the table below, list the values for the subscript variables low, high, and mid for each pass through the algorithm's while loop. (There may be fewer than five passes.)

10 19 24 37 42 48 52 59 65 78

Pass 1: low =  high =  mid =

Pass 2: low =  high =  mid =

Pass 3: low =  high =  mid =

Pass 4: low =  high =  mid =

Pass 5: low =  high =  mid =

Given the following:

   double piValue = 3.14159;
   double* piPtr = &piValue;

Assume that piValue is stored at address 200 and piPtr is stored at address 400. What is the value of *piValue?

A.

200

B.

The expression *piValue will result in a syntax error.

C.

400

D.

3.14159

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Question 1:
Pass 1: low = 0 high = 9 mid = 4
Pass 2: low = 5 high = 9 mid = 7
Pass 3: low = 5 high = 6 mid = 5
Pass 4: low = 6 high = 6 mid = 6
It takes only 4 passes

Question 2:
The expression *piValue will result in a syntax error.

Add a comment
Know the answer?
Add Answer to:
The binary search algorithm is used to search the following array for the value 59. In...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the binary search function, answer following question: int binarySearch(int a[], int size, int target, int...

    Given the binary search function, answer following question: int binarySearch(int a[], int size, int target, int low, int high) { while (low <= high) { int mid = (low + high) / 2; if (a[mid] == target) return mid; else if (a[mid] < target) low = mid + 1; else high = mid 1: } return -1; } 1) If array a[] = {4, 5, 18, 25, 66, 70, 78}, size = 7, target = 71, low = 0, high...

  • Read the following pseudocode, note that A is a sorted array: BINARY-SEARCH(A, v) low := 1...

    Read the following pseudocode, note that A is a sorted array: BINARY-SEARCH(A, v) low := 1 high := n while low <= high mid = floor((low+ high)/2) if v == A[mid] return mid else if v > A[mid] low = mid + 1 else high = mid - 1 return NIL a) Find the Recurrence Relation. b) Is there a tight bound? If the answer is yes, find it. c) Find the best case and worst case running time.

  • Read the following pseudocode, note that A is a sorted array: BINARY-SEARCH(A, v) low := 1...

    Read the following pseudocode, note that A is a sorted array: BINARY-SEARCH(A, v) low := 1 high := n while low <= high mid = floor((low+ high)/2) if v == A[mid] return mid else if v > A[mid] low = mid + 1 else high = mid - 1 return NIL a) Find the Recurrence Relation. b) Is there a tight bound? If the answer is yes, find it. c) Find the best case and worst case running time.

  • JAVA question: Suppose we are performing a binary search on a sorted array called numbers initialized...

    JAVA question: Suppose we are performing a binary search on a sorted array called numbers initialized as follows: // index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 int[] numbers = {-30, -9, -6, -4, -2, -1, 0, 2, 4, 10, 12, 17, 22, 30}; ​ // search for the value -5 int index = binarySearch(numbers, -5); Write the indexes of the elements that would be examined by the binary search (the mid values...

  • The binary search algorithm from Chapter 9 is a very efficient algorithm for searching an ordered...

    The binary search algorithm from Chapter 9 is a very efficient algorithm for searching an ordered list. The algorithm (in pseudocode) is as follows: highIndex - the maximum index of the part of the list being searched lowIndex - the minimum index of the part of the list being searched target -- the item being searched for //look in the middle middleIndex = (highIndex + lowIndex) / 2 if the list element at the middleIndex is the target return the...

  • Show the steps of the binary search algorithm (pseudocode is given below); low = index of...

    Show the steps of the binary search algorithm (pseudocode is given below); low = index of first item in list high = index of last item in list while low is less than or equal to high mid = index halfway between low and high if item is less than list[mid] high = mid - 1 else if item is greater than list[mid] low = mid + 1 else return mid end while return not found For each step of...

  • Java The following questions ask about tracing a binary search. To trace the binary search, list...

    Java The following questions ask about tracing a binary search. To trace the binary search, list the value of first, last, and mid for each pass through the loop or method. Use one of these methods for your trace. public static int binarySearchIterative(int[] numbers, int target) { boolean found = false; int first = 0; int last = numbers.length - 1; while (first <= last && !found) { int mid = (first + last) / 2; if (numbers[mid] == target)...

  • without coding Give the Big O run-time of the following algorithms. Binary Search: def binary-search (arr,...

    without coding Give the Big O run-time of the following algorithms. Binary Search: def binary-search (arr, low, high, x): # Check base case if low > high : return None else: mid = (high + low) // 2 element arr[mid] == X: if element return mid elif element > X: return binary-search(arr, low, mid 1, x) else: return binary_search(arr, mid + 1, high, x) Selection Sort: def selection_sort (arr): for i in range (len(arr)): smallest index = i smallest value...

  • A linear search algorithm is written (as in the modules, for example) which searches an array...

    A linear search algorithm is written (as in the modules, for example) which searches an array or list for some user-defined value, client_data. If client data is stored in the array, it returns its array position, and if not found, it returns -1 (again, just like in the modules). Assume the array to be searched has 100 data elements in it. (Check all that apply): NOTE: due to common off-by-one interpretations when counting such things, if your predicted answer is...

  • Given a double variable named x that has been declared and given a value, let's use a binary search technique to assign...

    Given a double variable named x that has been declared and given a value, let's use a binary search technique to assign an estimate of its square root to another double variable, root that has also been declared. Let's assume that x's value is greater than 1.0 -- that will simplify things a bit. Here's the general idea: Since x>1, we know its square root must be between 1 and x itself. So declare two other variables of type double...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT