STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 9.2, Problem 9.2CP
Program Description Answer
The average number of comparison for the array with 1,000 elements is “500”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
If a linear search is performed on an array, and it is known that some items are searched for more frequently than others, how can the contents of the array be reordered to improve the average performance of the search?
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?
Chapter 9 Solutions
STARTING OUT WITH C++ MPL
Ch. 9.2 - Prob. 9.1CPCh. 9.2 - Prob. 9.2CPCh. 9.2 - Prob. 9.3CPCh. 9.2 - Prob. 9.4CPCh. 9.3 - True or false: Any sort can be modified to sort in...Ch. 9.3 - Prob. 9.6CPCh. 9.3 - Prob. 9.7CPCh. 9.3 - Prob. 9.8CPCh. 9.3 - Prob. 9.9CPCh. 9.6 - Prob. 9.10CP
Ch. 9.6 - Prob. 9.11CPCh. 9.6 - Prob. 9.12CPCh. 9.6 - Prob. 9.13CPCh. 9.6 - Prob. 9.14CPCh. 9.6 - Prob. 9.15CPCh. 9 - Prob. 1RQECh. 9 - Prob. 2RQECh. 9 - Prob. 3RQECh. 9 - Prob. 4RQECh. 9 - Prob. 5RQECh. 9 - Prob. 6RQECh. 9 - Prob. 7RQECh. 9 - A binary search will find the value it is looking...Ch. 9 - The maximum number of comparisons that a binary...Ch. 9 - Prob. 11RQECh. 9 - Prob. 12RQECh. 9 - Bubble sort places ______ number(s) in place on...Ch. 9 - Selection sort places ______ number(s) in place on...Ch. 9 - Prob. 15RQECh. 9 - Prob. 16RQECh. 9 - Why is selection sort more efficient than bubble...Ch. 9 - Prob. 18RQECh. 9 - Prob. 19RQECh. 9 - Prob. 20RQECh. 9 - Prob. 21RQECh. 9 - Charge Account Validation Write a program that...Ch. 9 - Lottery Winners A lottery ticket buyer purchases...Ch. 9 - Lottery Winners Modification Modify the program...Ch. 9 - Batting Averages Write a program that creates and...Ch. 9 - Hit the Slopes Write a program that can be used by...Ch. 9 - String Selection Sort Modify the selectionSort...Ch. 9 - Binary String Search Modify the binarySearch...Ch. 9 - Search Benchmarks Write a program that has at...Ch. 9 - Sorting Benchmarks Write a program that uses two...Ch. 9 - Sorting Orders Write a program that uses two...Ch. 9 - Ascending Circles Program 8-31 from Chapter 8...Ch. 9 - Modified Bin Manager Class Modify the BinManager...Ch. 9 - Using Files-Birthday List Write a program that...Ch. 9 - Prob. 14PCCh. 9 - Using Files-String Selection Sort Modification...Ch. 9 - Using Vectors String 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
- Using r create a 4×3×4 array where for each of the 3 students, a 4×3 matrix holds their six scores and six averages (i.e., two averages by scores, three averages by subject, and the grand average). The last (i.e., 21st) matrix should hold the elementwise averages of the previous 20 matrices. Do not use a loop. Ini A1 A2 B1 B2 C1 C2 RE 81.9 75.1 78.3 69.2 79.6 74.4 ON 82.7 72.6 85.3 78.9 78.3 75.7 KS 83.8 63.4 73.4 73.5 80.4 66.2 Ini is the student's initials, A1 is subject 1 first, A2 is subject 1 second, etc.arrow_forwardPlease correct answer only to get Upvotearrow_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
- Consider 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_forwardGiven 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_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_forwardWhen we apply the mergesort on a 12-element array, how many comparisons do we need for the worst case? Ans:arrow_forwardHow many times will the array {70, 71, 72, 76, 80, 82, 83, 84, 87, 92, 95, 96, 102, 103, 107, 109, 111, 112, 113, 115, 116} need to be halved using binary search in order to find that element 112 is in in the list?arrow_forward
- Write down the algorithm for linear search.arrow_forwardSuppose 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_forwardالسؤال sequential search: what is the running time of the best case to search if all the elements of an array are equal ? الاجابات O(1) O(n) O(n^2) n log narrow_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