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 algorithm, give the indexes of first, last,
and middle when searching for "Deb" in the
following list.
"Alf" "Ann" "Bev" "Bob" "Deb" "Jed" "Jim" "Joe" "Liz" "Meg"
"Ned" "Sam" "Sue" "Wes" "Zed"
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]
[14]
Show the steps of the binary search algorithm (pseudocode is given below); low = index of...
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...
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...
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...
//Generic interface that describes various searching and sorting //algorithms. Note that the type parameter is unbounded. However, //for these algorithms to work correctly, the data objects must //be compared using the method compareTo and equals. //In other words, the classes implementing the list objects //must implement the interface Comparable. The type parameter T //is unbounded because we would like to use these algorithms to //work on an array of objects as well as on objects of the classes //UnorderedArrayList and...
Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch algorithms as follows: Suppose list is an array of 2500 elements. 1. Use a random number generator to fill list; 2. Use a sorting algorithm to sort list; 3. Search list for some items as follows: a) Use the binary search algorithm to search list (please work on SearchSortAlgorithms.java and modify the algorithm to count the number of comparisons) b) Use the sequential search...
How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...
Need help with this Java. I need help with the "to do" sections.
Theres two parts to this and I added the photos with the entire
question
Lab14 Part 1:
1) change the XXX to a number in the list, and YYY to a
number
// not in the list
2.code a call to linearSearch with the item number
(XXX)
// that is in the list; store the return in the variable
result
3. change both XXX numbers to the...
What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...
My tests for sorting algorithms are not working. sorting.py has 6 sorting algorithms and test_sorting.py has test cases to run those algorithms, but test cases are not working. please correct the errors in test_sorting.py file so that it can test all the sorting algorithms. WARNING: DON'T COPY AND PASTE THE QUESTION IN ANSWER. I WILL REPORT YOU. sorting.py # 1. selection sort # 2. insertion sort # 3. shell sort # 4. heap sort # 5. merge sort # 6....
Read about Cokes strategy in Africa in the article below and discuss the ethics of selling soft drinks to very poor people. Is this an issue that a company like Coke should consider? Africa: Coke's Last Frontier Sales are flat in developed countries. For Coke to keep growing, Africa is it By Duane Stanford Piles of trash are burning outside the Mamakamau Shop in Uthiru, a suburb of Nairobi, Kenya. Sewage trickles by in an open trench. Across the street,...