[solved]-Unit 4 Advanced Topics Prepare 44 Instrumentation Assignment Week Determine Relative Speed Q39026620


Unit 4. Advanced Topics PREPARE 4.4: INSTRUMENTATION Our assignment this week is to determine the relative speed of a linear search versus a binary search using instrumentation. To do this, start with the code at: /home/cs124/assignments/assign44.cpp Here, you will need to modify the functions binary() and linear() to count the number of comparisons that are performed to find the target number. Next, you will need to modify computeAveragelinear() and computeAverageBinary() to determine the number of compares on average it takes to find each element in the array. Example Consider the file numbers.txt that has the following values: 1 4 10 36 47 92 100 110 125 136 142 143 150 160 167 For the above example, the list is: 0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 1|4|10|36|47|92|100110125136|142 143|150|1601167 When we run the program on the above list, the program will compute how long it takes to find an element in the list using the linear search method and using the binary search method. If I call linear() (a function performing a linear search from left to right) with the search parameter set to 4, then I will find it with two comparisons. This means linear(list, num, 4) == 2 because the function linear() will return the number of comparisions, list contains the list of numbers, and num is the number of items in list. Thus linear(list, num, 47) == 5. To find the average cost of the linear search, the equation will be: (linear(list, num, 1) + linear(list, num, 4) + … + linear(list, num, 167)) /num == (1 + 2 + … + 15) / 15 == 120 / 15 == 8.0 To compute the average cost of the binary search, the equation will be: (binary(list, num, 1) + binary(list, num, 4) + … + binary(list, num, 167)) /num == 3.3 The user input is underlined. Enter filename of list: numbers.txt Linear search: 8.0 Binary search: 3.3 Assignment The test bed is available at: test Bed cs124/assign44 assignment44.cpp Don’t forget to submit your assignment with the name “Assignment 44” in the header. Show transcribed image text Unit 4. Advanced Topics PREPARE 4.4: INSTRUMENTATION Our assignment this week is to determine the relative speed of a linear search versus a binary search using instrumentation. To do this, start with the code at: /home/cs124/assignments/assign44.cpp Here, you will need to modify the functions binary() and linear() to count the number of comparisons that are performed to find the target number. Next, you will need to modify computeAveragelinear() and computeAverageBinary() to determine the number of compares on average it takes to find each element in the array. Example Consider the file numbers.txt that has the following values: 1 4 10 36 47 92 100 110 125 136 142 143 150 160 167 For the above example, the list is: 0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 1|4|10|36|47|92|100110125136|142 143|150|1601167 When we run the program on the above list, the program will compute how long it takes to find an element in the list using the linear search method and using the binary search method. If I call linear() (a function performing a linear search from left to right) with the search parameter set to 4, then I will find it with two comparisons. This means linear(list, num, 4) == 2 because the function linear() will return the number of comparisions, list contains the list of numbers, and num is the number of items in list. Thus linear(list, num, 47) == 5. To find the average cost of the linear search, the equation will be:
(linear(list, num, 1) + linear(list, num, 4) + … + linear(list, num, 167)) /num == (1 + 2 + … + 15) / 15 == 120 / 15 == 8.0 To compute the average cost of the binary search, the equation will be: (binary(list, num, 1) + binary(list, num, 4) + … + binary(list, num, 167)) /num == 3.3 The user input is underlined. Enter filename of list: numbers.txt Linear search: 8.0 Binary search: 3.3 Assignment The test bed is available at: test Bed cs124/assign44 assignment44.cpp Don’t forget to submit your assignment with the name “Assignment 44” in the header.
Expert Answer
Answer to Unit 4. Advanced Topics PREPARE 4.4: INSTRUMENTATION Our assignment this week is to determine the relative speed of a li… . . .
OR

