Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with my c++ task please Statement Purpose: Purpose of this Lab is to familiarize the students with the code of linear search
I need help with my c++ task please
Statement Purpose: Purpose of this Lab is to familiarize the students with the code of linear search and binary search. Another aim is to teach the students the difference between the running times of linear search and its more efficient counterpart: binary search. The students are given small task related to linear search and binary search which they complete during the lab session under the supervision of the lab instructor. This helps them understand the concepts well which they learn in their lectures. Activity Outcomes: The students will learn how to write code for linear search and binary search methods. They will also understand how to find the difference between the running times of these two approaches. Theory Review: a) Linear Search: The linear search approach compares the key element key sequentially with each element in the array. It continues to do so until the key matches an element in the array or the array is exhausted without a match being found. If a match is made, the linear search returns the index of the element in the array that matches the key. If no match is found, the search returns -1. Code for Linear Search Method int linearSearch(int array[],size, int key) { for(int i = 0; i header and invoke sort(test, test + size) - To compute the running time, you need to get the time immediately before the search and then immediately after the search by using clock() which returns the processor time consumed by the program. clock_t start = clock(); statements.... clock_t stop = clock(); double totalTime = (double(stop)-double(start))/CLOCKS_PER_SECStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started