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
Concept explainers
Question
Chapter 8.2, Problem 8.2CP
Program Plan Intro
Linear search:
- Linear search or sequential search is a process of searching for a particular element that is present in the array on by one till the last element until the search element is found.
- The search uses 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 with the 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
def weighted_mse_grad(w, X, y, V):"""Calculate gradient of the weight MSE loss in the given point w
Parameters----------w: array_likeCurrent point, in which we want to evaluate gradient (vector with k+1 elements)X: array_likeDesign matrix with N rows and k+1 columnsy: array_likeVector with N observations of the target variableV: array_likeDiagonal matrix N x N, with the weightsReturns----------out: ndarrayvector of gradient, k+1"""# your code here
# TEST weighted_mse_grad()w = np.zeros(5)X = np.random.randn(10, 5)y = np.ones(10)V = np.diag(np.ones(10))
L_grad = weighted_mse_grad(w, X, y, V)assert(L_grad.shape == (5,))
w = np.zeros(5)X = np.eye(5)y = np.ones(5)V = np.diag(np.ones(5))L_grad = weighted_mse_grad(w, X, y, V)assert(L_grad.shape == (5,)), 'The shape of the output on the test case is wrong'assert(np.allclose(5 * L_grad,- y * 2)), 'The values of the output on the test case is wrong'
The element being searched for is not in an array of 100 elements. What is the maximum number of comparisons needed in a sequential search to determine that the element is not there if the elements are completely unsorted?
Please correct answer only to get Upvote
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
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
- Detailed answer please. I will Upvotearrow_forwardGiven an 8-element array: A = {x1, X2, X3, X4, X5, X6, 7, x8}, we would like to find its 3rd smallest element. It is known that x₁ and 8 are the two extreme elements: max and min, but we do not know which one is the max and which one is the min. It is also known that x4 and x5 are the two medians: left-median and right-median. What is the minimum number of comparisons you need to find the 3rd smallest element of the original array? Ans:arrow_forwardHow many times will the array {45, 47, 48, 51, 53, 54, 56, 57, 67, 70, 72, 73, 74, 79, 82, 85, 87, 89} need to be halved using binary search in order to find that element 30 is not in the array?arrow_forward
- Given a random array, please design an algorithm to find the median. First describe your algorithm, and then simulate your algorithm on the following array: {14, 2, 15, 1, 6, 30, 9, 7, 8, 11}.arrow_forwardConsider the following linear array: array=[-6,2,1,-5,-1,7,8] If you remove an element in index 2 and then insert an element in index 4, MINIMUM how many elements in total need to be shifted for the full operation? When an element in a particular index moves to its adjacent left or right index, it is counted as one shift. 7 8arrow_forwardAssume an array has been ordered as (8, 14, 23, 45, 53, 67, 81, 85, 88, 94, 104, 111}. If we apply the binary search algorithm to this array to search element 104, how many iterations will be needed? (You need to show your work to receive full credit.)arrow_forward
- we'll be working with the following set of nine numbers for binary searches set below:4, 10, 15, 18, 23, 26, 30, 34, 40Our objective is to pinpoint the number 26 within this array.The initial segment will comprehensively explain how to conduct a linear search to locate the number 26 within this array.arrow_forwardWhat is the worst case running time for finding the kth value in an array?arrow_forwardWhen we apply the mergesort on a 12-element array, how many comparisons do we need for the worst case? Ans:arrow_forward
- Suppose you have to search a key element from a list of array using divide and conquertechnique, then which searching method is appropriate to use? Write the best case and worstcase time complexity for the identified search.arrow_forwardFor selection sort, how many comparisons would be needed to sort an array containing 100 elements if the original array elements were already sorted? What if the original array elements were sorted in reverse order? What if the original array elements were all identical?arrow_forwardFor insertion sort, how many comparisons would be needed to sort an array containing 100 elements if the original array elements were already sorted? What if the original array elements were sorted in reverse order? AV What if the original array elements were all identical?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