Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 7.10, Problem 7.10.3CP
Program Plan Intro
Array:
An array is defined as a group that consists of similar data types.
- The array size must be specified by an “int” value and not long or short.
- In Java, all arrays are allocated dynamically.
- An array is always indexed, starting from 0.
Binary Search:
Binary search
- The binary search algorithm is used to find an item in an array.
- The algorithm assumes that the item search array is sorted.
- The searching process starts at the middle of the array.
- In the searching process, the algorithm finds an item or eliminates half of the array in each comparison.
- If the search item is less than the middle item, then it eliminates the second half of the array and continues to search in the first half of the array.
- If the search item is greater than the middle item, then it eliminates the first half of the array, and it continues to search in the second half of the array.
- Once again, it examines the middle and repeats the above steps to find an item.
- If the middle item is equal to the search item, then the searching process is stopped.
- The search is stopped when an item is found or the search reaches the empty portion of the array.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
How can you count duplicate elements in a given list?
From the following code that collects the data entered by the user of the animals according to their type of food. Pastebin: https://pastebin.com/VuBfRp0s
I have an error when deleting animals. It asks me for the code and when I enter it, it says that it deletes the animal. However, it does not disappear from the list and the same animal continues to be printed. What I can do?
How do you find the lowest and highest values in a list?
Chapter 7 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 7.2 - Prob. 7.2.1CPCh. 7.2 - Prob. 7.2.2CPCh. 7.2 - What is the output of the following code? int x =...Ch. 7.2 - Indicate true or false for the following...Ch. 7.2 - Which of the following statements are valid? a....Ch. 7.2 - Prob. 7.2.6CPCh. 7.2 - What is the array index type? What is the lowest...Ch. 7.2 - Write statements to do the following: a. Create an...Ch. 7.2 - What happens when your program attempts to access...Ch. 7.2 - Identify and fix the errors in the following code:...
Ch. 7.2 - What is the output of the following code? 1....Ch. 7.4 - Will the program pick four random cards if you...Ch. 7.5 - Use the arraycopy method to copy the following...Ch. 7.5 - Prob. 7.5.2CPCh. 7.7 - Suppose the following code is written to reverse...Ch. 7.8 - Prob. 7.8.1CPCh. 7.8 - Prob. 7.8.2CPCh. 7.9 - Prob. 7.9.1CPCh. 7.9 - Prob. 7.9.2CPCh. 7.10 - If high is a very large integer such as the...Ch. 7.10 - Prob. 7.10.2CPCh. 7.10 - Prob. 7.10.3CPCh. 7.11 - Prob. 7.11.1CPCh. 7.11 - How do you modify the selectionSort method in...Ch. 7.12 - What types of array can be sorted using the...Ch. 7.12 - To apply java.util.Arrays.binarySearch (array,...Ch. 7.12 - Show the output of the following code: int[] list1...Ch. 7.13 - This book declares the main method as public...Ch. 7.13 - Show the output of the following program when...Ch. 7 - (Assign grades) Write a program that reads student...Ch. 7 - (Reverse the numbers entered) Write a program that...Ch. 7 - (Count occurrence of numbers) Write a program that...Ch. 7 - (Analyze scores) Write a program that reads an...Ch. 7 - (Print distinct numbers) Write a program that...Ch. 7 - (Revise Listing 5.1 5, PrimeNumber.java) Listing...Ch. 7 - (Count single digits) Write a program that...Ch. 7 - (Average an array) Write two overloaded methods...Ch. 7 - (Find the smallest element) Write a method that...Ch. 7 - Prob. 7.10PECh. 7 - (Statistics: compute deviation) Programming...Ch. 7 - (Reverse an array) The reverse method in Section...Ch. 7 - Prob. 7.13PECh. 7 - Prob. 7.14PECh. 7 - 7 .15 (Eliminate duplicates) Write a method that...Ch. 7 - (Execution time) Write a program that randomly...Ch. 7 - Prob. 7.17PECh. 7 - (Bubble sort) Write a sort method that uses the...Ch. 7 - (Sorted?) Write the following method that returns...Ch. 7 - (Revise selection sort) In Listing 7 .8, you used...Ch. 7 - (Sum integers) Write a program that passes an...Ch. 7 - (Find the number of uppercase letters in a string)...Ch. 7 - (Game: locker puzzle) A school bas 100 lockers and...Ch. 7 - (Simulation: coupon collectors problem) Coupon...Ch. 7 - (Algebra: solve quadratic equations) Write a...Ch. 7 - (Strictly identical arrays) The arrays 1ist1 and...Ch. 7 - (Identical arrays) The arrays 1ist1 and 1ist2 are...Ch. 7 - (Math: combinations) Write a program that prompts...Ch. 7 - (Game: pick four cards) Write a program that picks...Ch. 7 - (Pattern recognition: consecutive four equal...Ch. 7 - (Merge two sorted Lists) Write the following...Ch. 7 - (Partition of a list) Write the following method...Ch. 7 - Prob. 7.33PECh. 7 - (Sort characters in a string) Write a method that...Ch. 7 - (Game: hangman) Write a hangman game that randomly...Ch. 7 - (Game: Eight Queens) The classic Eight Queens...Ch. 7 - Prob. 7.37PE
Knowledge Booster
Similar questions
- How many stopwords are in the text in total? Hint : you can use the nltk stopwords dictionary Function Specifications: Function should take a list as inputThe number of stopwords should be returned as an intarrow_forwardWhat keyword parameter is used to send a key-function to the sort method?a) reverse b) reversed c) cmp d) keyarrow_forwardWhat does the following error message normally mean? IndexError: list index out of range Select one: а. This error normally indicates that you have tried to access an element of a list that doesn't exist. O b. This error normally means that you have used the range() function incorrectly. С. This error normally means that you have used a list where you should have used a tuple. d. This error normally means that you used too many lines of code in your program.arrow_forward
- operator is used to combine 2 or more lists.arrow_forwardHow do you find the average of numbers in a list? .arrow_forwardntify the choice that best cómpleles 1. The following procedure is intended to return the number of times the value val appears in the list myList. The procedure does not work as intended. Line 01: PROCEDURE countNumOccurences (myList, val) Line 02: { Line 03: FOR EACH item IN myList Line 04: } Line 05: count 0 Line 06: IF(item = val) %3D } count count + 1 Line 07: Line 08: Line 09: { Line 10: } Line 11: RETURN(count) Line 12: } Which of the following changes can be made so that the procedure will work as intended? a. Moving the statement in line 5 so that it between lines 2 and 3 c. Changing line 6 to IF(myList[item] = val) appears b. Changing line 6 to IF(item = count) d. Moving the statement in line 11 so that it appears between lines 9 and 10 1.arrow_forward
- For each of the following Python list methods indicate whether the method mutates the list. Write "yes" if the method mutates the list or "no" if the method does not mutate the list. append sort reverse index insert count remove poparrow_forward12. Which method do you use to remove an element from a set or list named x? a. x.remove (element) b. x.removes (element) w w c. X.delete (element) d. None of the above e. x.deletes (element)arrow_forwardhdex mplete the following function according to its docstring using a while loop. The lists we test will not all be sho cribed in English. If you fail any test cases, you will need to read the description and make your own test. def smaller_index(items: list[int]) -> int: 3\ Return the index of the first integer in items that is less than its index, 4. or -1 if no such integer exists in items. 6. >>> smaller_index([2, 5, 7, 99, 6]) 7. -1 8 >>> smaller_index([-5, 8, 9, 16]) 9. 10 >>> smaller_index([5, 8, 9, 0, 1, 3]) 11 3 12 for i in range (len(items)): if items [i] < i: 13 14 15 return i 16 return -1 History X Your solution passed 0 out of 6 cases!arrow_forward
- The elements in the set cannot be accessed using indexing and slicing, choose whether this statement is true or false. a. True b. False Clear my choicearrow_forwardHello it is possible to modify the binary search to only display the result with Title of the book and its ID number where user's input is the title of the book?arrow_forwardWhat does the operator delete do?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you