Concept explainers
Hi, can you give me a hand with this exercise. thanks!
Binary Bubbles. Create an array full of 11 integers which the user will generate. assume that the values will be between -100 and +100. Then, using the sorting
The BinarySearch code will implement the algorithm described below:
int low = 0, mid = 0;
int high = arraySize;
bool found = false;
while (high >= low)
{
mid = (low + high) / 2;
if (find < searchArray[mid]) {
high = mid - 1;
}
else if (find == searchArray[mid]) {
found = true; break;
}
else low = mid + 1;
}
Print out a few key values which help Binary Search function. For example, this algorithm
focuses on a low, mid, and high which correspond to the indices in the array the algorithm is
currently considering and searching.
Printing these values during the search process will help with debugging and fixing any issues.
• BubbleSort sorts the array to prepare for the next step
• BinarySearch searches the now sorted array to determine if the target value is in the array or not.
The user input is indicated in bold.
Sample output #1
Please enter 11 numbers:
Integer 1: 15
Integer 2: 12
Integer 3: 89
Integer 4: -14
Integer 5: 11
Integer 6: -99
Integer 7: 1
Integer 8: 42
Integer 9: 27
Integer 10: 2
Integer 11: 67
What is the target number : 42
The sorted set is: -99 -14 1 2 11 12 15 27 42 67 89
Low is 0
High is 10
Mid is 5
Searching
Low is 6
High is 10
Mid is 8
Searching
The target is in the set.
Sample output #2
What is the target number: -5
The sorted set is: -99 -14 1 2 11 12 15 27 42 67 89
Low is 0
High is 10
Mid is 5
Searching
Low is 0
High is 4
Mid is 2
Searching
Low is 0
High is 1
Mid is 0
Searching
The target is not in the set.
Step by stepSolved in 3 steps with 1 images
- The Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, ... where each number (after the first two values) is the sum of the previous two numbers. Write a program that declares an integer array called fib_numbers with a length of 25 elements. The program then fills the array with the first 25 Fibonacci numbers using a loop. The program then prints the values to the screen using a separate loop.arrow_forwardInitialize two integer arrays, a[6] and b[6]. First print their elements in two rows, and then print them out in two columns. : Initialize the arrays with random integers in the range between 0 & 20, inclusivearrow_forwardC++ . Please make sure code has "Enter integer 1, etc" instead of allowing you to type integers without prompt.arrow_forward
- Array a is an integer array with all the elements in ascending order. The element at position 15 is the 15th largest and also the 15th smallest. You can assume integers are 4 bytes long. How many bytes are there in the array? O 116 124 O None of the other answers is correct. 120arrow_forwardThis is method is in the Java Arrays and uses the most efficient sort algorithm possible to sort an array. We should always use it in practice because it has been verified by years of use by Java programmer._______arrow_forwardAn int array stores the following values: 9 4 12 2 6 8 18 How many passes will it take for a selection sort to sort this array?arrow_forward
- A(n) ___ is used in an array to across each element? a. Index b. Subscript C. Both a and b d. None of the abovearrow_forwardThe contents of the array below represent a maxHeap. What would be the contents of the array after a deletion. Briefly explain how the deletion is done. 60 20 30 5 10 15 25arrow_forwardCode to how do you total all of the matching integer elements in an array?. ASAP.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education