Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8, Problem 16RQE
Program Plan Intro
Linear search:
- Linear search or sequential search is the process of searching for a particular element that is present in the array one by one till the last element in the search element is found.
- The search uses a loop that iterates from the beginning till the last element to find the search element.
- The search continues for all the elements present in the array until the last element.
- The search of the target element is made after comparing it with each and every element that is present in the array.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Fill-in-the-Blank
The average number of comparisons performed by linear search to find an item in an array of N elements is _________.
Fill-in-the-Blank
The maximum number of comparisons performed by linear search to find an item in an array of N elements is _________.
Data Structure & Algorithm:
Here is an array with exactly 15 elements:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15Suppose that we are doing a serial search for an element. Circle any elements that will be found by examining two or fewer numbers from the array.
Chapter 8 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 8.2 - Prob. 8.1CPCh. 8.2 - Prob. 8.2CPCh. 8.2 - Prob. 8.3CPCh. 8.2 - Prob. 8.4CPCh. 8 - Prob. 1RQECh. 8 - If a linear search function is searching for a...Ch. 8 - Prob. 3RQECh. 8 - A binary search function is searching for a value...Ch. 8 - What is the maximum number of comparisons that a...Ch. 8 - Prob. 6RQE
Ch. 8 - Why is the selection sort more efficient than the...Ch. 8 - Prob. 8RQECh. 8 - The __________ search algorithm repeatedly divides...Ch. 8 - Prob. 10RQECh. 8 - The ____________ search algorithm requires that...Ch. 8 - If an array is sorted in ______________ order, the...Ch. 8 - If an array is sorted in _____________ order, the...Ch. 8 - Prob. 14RQECh. 8 - Prob. 15RQECh. 8 - Prob. 16RQECh. 8 - T F The maximum number of comparisons performed by...Ch. 8 - Prob. 18RQECh. 8 - Charge Account Validation Write a program that...Ch. 8 - Lottery Winners A lottery ticket buyer purchases...Ch. 8 - Lottery Winners Modification Modify the program...Ch. 8 - Charge Account Validation Modification Modify the...Ch. 8 - Rainfall Statistics Modification Modify the...Ch. 8 - String Selection Sort Modify the selectionSort...Ch. 8 - Binary String Search Modify the binarySearch...Ch. 8 - Search Benchmarks Write a program that has an...Ch. 8 - Sorting Benchmarks Write a program that uses two...Ch. 8 - Sorting Orders Write a program that uses two...Ch. 8 - Using FilesString Selection Sort Modification...
Knowledge Booster
Similar questions
- For a two-dimensional array list, the value of list.length indicates: It dependes on Array Size The number of Columns C) The number of rows D) Not Valid for 2D arrayarrow_forwardArray implementation of List ADT Display the array elements from Left to Right and Right to left. Input: Enter the size of array MAX Enter number of elements N Enter the element to be inserted. Output: Display the Array For example: Test Input 1 2 10 W3 123 10 5 11 12 13 14 15 Result Forward: 1 2 3 Backward:3 2 1 Forward: 11 12 13 14 15 Backward:15 14 13 12 11arrow_forwardT/F: Selection Sort has both a best case and worst case runtime of O(n^2).arrow_forward
- Show how the Selection Sort works on this list array to sort it in ascending order. 55 35 20 80 90 40 60 95 10 75arrow_forwardQ1: Suppose an array contains the following elements: -31 . . -27 . -9 14 17 18 Determine the number of comparisons needed to find each element in the array using a binary search. (explain in detail how to get the answer ) For example, three comparisons are needed to find -9. . -31 -27 14 17 48 7 29 30 48arrow_forwardList all the steps used to search for 18 in the sequence 1, 2, 4, 8, 10, 12, 18, 20, 22. Be sure to show EVERY step. A. linear search B. binary search Use the following array and indices in your answer: Array: 1 2 4 8 10 12 18 20 22 Index: 1 2 3 4 5 6 7 8 9arrow_forward
- Removes all odd elements from a partially filled array @param values a partially filled array@param size the number of elements in values@return the new size (the expected output is also attached)arrow_forwardLet N be an unordered array of integers. The maximum number of compares required to find the minimum value is N Select one: OTrue OFalsearrow_forwardweight You are given 4 items as {value, weightpairs in this format {{20,5}, {60, 20}, {25, 10}, {X, 25}}You can assume that the array is sorted based on the value ratio. The capacity of knapsack is 50. The item no. 4 (whose weightis 25 ) is taken fractionally to fill upto the knapsack capacity. That fraction is represented informat. What is the lowest possible value of 6? For the question above, assume the total value stored in the knapsack is 135 after you have filled upto the knapsack capacity. What is the value of X(in other words, the value of the item no. 4) ? Give your answer to at least two decimal places.arrow_forward
- 2. For the following array, you are to perform a binary search: Int nums[ ]= {1, 13, 78, 89, 96, 100, 112, 125, 230, 310, 423, 578, 1000); Search for the number 126 by showing the low, midpoint and high values at each step before it reports that 126 is NOT found in the array. Low Mid Higharrow_forwardGiven the following 1D array of 7 strings: "MILK" "TEETH" The first element located at index 0 is "MILK". The last element located at index 6 is "APPLE". (Note that the indexing starts from 0) "HORSE" "YOYO" 1. Right after the first iteration, the element at index 6 is: Fill in the blanks below: 2. Right after the second iteration, the element at index 1 is: Perform Selection Sort to rearrange the elements in alphabetical order. Simulate the algorithm and fill in the required array element values in the following items. You have the option not to to type the double quotes in your answers. Use ALL CAPS when entering the text. 3. Right after the third iteration, the element at index 6 is: "ROBOT" 4. Right after the fourth iteration, the element at index 3 is: "QUEEN" "APPLE" MILKarrow_forward25. Minimum Difference Sum Given an array of n integers, rearrange them so that the sum of the absolute differences of all adjacent elements is minimized. Then, compute the sum of those absolute differences. Example n = 5 arr = [1, 3, 3, 2, 4] If the list is rearranged as arr' = [1, 2, 3, 3, 4], the absolute differences are /1-2/ = 1, 12-3|= 1, 13- 3|=0, 13-4/= 1. The sum of those differences is 1+1+0+1 = 3. Function Description Complete the function minDiff in the editor below. minDiff has the following parameter: arr: an integer array Returns: int: the sum of the absolute differences of adjacent elements Constraints 1 > #include ... 'PRENENANG 19 20 21 22 23 24 25 26 28 * Complete the 'minDiff' function below. ★ 27 int minDiff(int arr_count, int* arr) { * The function is expected to return an INTEGER. * The function accepts INTEGER_ARRAY arr as parameter. */ 29 } 30 31 > int main() ...arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage