Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 11.2, Problem 8STQ
Program Plan Intro
Binary search
- • Binary search is a smart search process that searches for the particular element that is present in the array from the middle towards the left or right until the search element is found.
- • The search continues in a narrow way that it searches for the quarter of the array until there are no values left in the array to search or compare.
- • The search of the target element is made in the smart way it eliminates a portion of array based on the given element as the array is sorted.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Bubble sort is used to arrange an array in an ascending or descending order. If we are using this algorithm to sort an array in descending order, then what will be the order of values after complete execution of outer loop 3 times: 9, 1, 4, 5, 2, 8, 6, 11, 7, 0 *
If a sorted array has duplicate items (max frequency is 2), binary search finds _________?
At what index in the array would you expect to find the smallest element in the binary search tree.
Chapter 11 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 11.1 - What output will be produced by the following...Ch. 11.1 - What is the output produced by the following code?Ch. 11.1 - Write a recursive definition for the following...Ch. 11.1 - What is the output of the following code? public...Ch. 11.1 - Prob. 5STQCh. 11.1 - Complete the definition of the following method....Ch. 11.2 - Revise the method getCount in Listing 11.5 so that...Ch. 11.2 - Prob. 8STQCh. 11.2 - Prob. 9STQCh. 11.2 - Suppose you want me class ArraySearcher to work...
Ch. 11.2 - What Java statement will sort the following array,...Ch. 11.2 - How would you change the class MergeSort so that...Ch. 11.2 - How would you change the class MergeSort so that...Ch. 11.2 - If a value in an array of base type int occurs...Ch. 11.3 - Convert the following event handler to use the...Ch. 11 - What output will be produced by the following...Ch. 11 - What output will be produced by the following...Ch. 11 - Write a recursive method that will compute the...Ch. 11 - Write a recursive method that will compute the sum...Ch. 11 - Complete a recursive definition of the following...Ch. 11 - Write a recursive method that will compute the sum...Ch. 11 - Write a recursive method that will find and return...Ch. 11 - Prob. 8ECh. 11 - Write a recursive method that will compute...Ch. 11 - Suppose we want to compute the amount of money in...Ch. 11 - Prob. 11ECh. 11 - Write a recursive method that will count the...Ch. 11 - Write a recursive method that will remove all the...Ch. 11 - Write a recursive method that will duplicate each...Ch. 11 - Write a recursive method that will reverse the...Ch. 11 - Write a static recursive method that returns the...Ch. 11 - Write a static recursive method that returns the...Ch. 11 - One of the most common examples of recursion is an...Ch. 11 - A common example of a recursive formula is one to...Ch. 11 - A palindrome is a string that reads the same...Ch. 11 - A geometric progression is defined as the product...Ch. 11 - The Fibonacci sequence occurs frequently in nature...Ch. 11 - Prob. 4PPCh. 11 - Once upon a time in a kingdom far away, the king...Ch. 11 - There are n people in a room, where n is an...Ch. 11 - Prob. 7PPCh. 11 - Prob. 10PPCh. 11 - Prob. 12PP
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Let A = [5,5,5,5,5,...,5] be an array where all of the elements are equal to 5. Determine whether Selection Sort or Insertion Sort sorts this array faster.arrow_forwardwrite code to The Modified search() and the New find() of the Ordered Arrayarrow_forwardplease do fast:-- Estimate how many times faster an average successful search will be in a sorted array of one million elements if it is done by binary search versus sequential search.arrow_forward
- Why does the binary search algorithm require the input to be sorted?arrow_forwardWrite java code and find the output - searching algorithm over array using binary searcharrow_forwardGiven an array of size 10, which is sorted in ascending order, perform binary search. Write the binary search algorithm. At most how many steps will be required to find out the desired item?arrow_forward
- The following is a code for Bubble Sort... But a reversed one. (It sorts the array in descending order!) Determine and prove the loop invariant of the following code.arrow_forwardThe binary search algorithm that follows may be used to search an array when the elements are in order. This algorithm is analogous to the following approach to finding a name in a telephone book. a. Open the book in the middle and look at the middle name on the page. b. b. If the middle name isn't the one, you're looking for, decide whether it comes before or after the name you want. c. Take the appropriate half of the section of the book you were looking in and repeat these steps until you land on the name. 1. Let the bottom be the subscript of the initial array element. 2. Let the top be the subscript of the last array element. 3. Let found be false. 4. Repeat as long as the bottom isn't greater than the top and the target has not been found. 5. Let middle be the subscript of the element halfway between bottom and top. 6. If the element in the middle is the target 7. Set found to true and index to middle. else if the element in the middle is larger than the target 8. Let the top be…arrow_forward2. An interpolation search assumes that the data in an array is sorted and uniformly distributed.Whereas a binary search always looks at the middle item in an array, an interpolation searchlooks where the sought-for item is more likely to occur. For example, if you searched yourtelephone book for Victoria Appleseed, you probably would look near its beginning ratherthan its middle. And if you discovered many Appleseeds, you would look near the lastAppleseed. Instead of looking at the element a[mid] of an array a, as the binary search would,an interpolation search examines a[index], where p = (desiredElement - a[first]) / (a[last] - a[first]) index = first + [(last – first) × p]Implement an interpolation search of an array. For particular arrays, compare the outcomesof an interpolation search and of a binary search. Consider arrays that have uniformlydistributed entries and arrays that do not. Modify and save the file asSearchComparerYourlastname.java.arrow_forward
- array unordered Arr has unsorted integers. SortedArr is an integer array. SortedArr performs which task better than unsortedArr? Use the fastest algorithms. Inserting a new element II Searching for a given element III Calculating the mean of the elements (A) I alone (B) II alone (C) III alone (D) I and II alone (E) I, II, and IIIarrow_forwardLinear search can be used on:a. Unsorted arrays.b. Sorted arrays.c. Integer arrays.d. Any of the above.arrow_forwardCan you explain the algorithm of insertion sort here? Also, add code for the binary search to search for a book by title or author.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education