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
  • 6.3.1 [10] <§6.2> Consider the following binary search algorithm (a classic divide and conquer algorithm) that...

    6.3.1 [10] <§6.2> Consider the following binary search algorithm (a classic divide and conquer algorithm) that searches for a value X in a sorted N-element array A and returns the index of matched entry: BinarySearch(A[0..N−1], X) { low = 0 high = N −1 while (low <= high) { mid = (low + high) / 2 if (A[mid] >X) high = mid −1 else if (A[mid] <X) low = mid + 1 else return mid // found } return −1...

  • 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...

  • 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...

  • 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...

  • JAVA Algorithms course need help completing this method using binary search thank you in advance. -------------------------------------------------------------------------------------------------...

    JAVA Algorithms course need help completing this method using binary search thank you in advance. ------------------------------------------------------------------------------------------------- /** A class for executing binary searches in an array. */ public class BinarySearcher { /** Finds a value in a range of a sorted array, using the binary search algorithm. @param a the array in which to search @param low the low index of the range @param high the high index of the range @param value the value to find @return the index...

  • 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...

  • 1. What is the minimum number of locations a binary search algorithm will have to examine...

    1. What is the minimum number of locations a binary search algorithm will have to examine when looking for a particular value in a sorted array of 200 elements? (2 points) 1 6 7 8 200 2. In general, which of the following sorting algorithms is the MOST efficient? (2 points) Bubble sort Insertion sort Heap sort Merge sort Selection sort 3. Which of the following are quadratic-sorting algorithms? (2 points) I. insertion sort II. selection sort III. merge sort...

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