Algorithm Analysis Consider searching algorithms on the following array of data:
ID: 2977754 • Letter: A
Question
Algorithm Analysis Consider searching algorithms on the following array of data: [22 21 9 4 16 2 10 14 20 31 26 19 17 28 8 13] Suppose you want to implement a searching algorithm to see if the data set contains the number 19. Demonstrate how the search would go if you used: A sequential search A binary search State the runtime for each of the searches, in this example, and for general data sets of size n. Address the issue of the order of the data in binary searching. Suppose an algorithm that processes a data set of size 8 has a runtime of 72. The same algorithm has a runtime of 110 when applied to a data set of size 10; and when applied to a data set of size 20, it has a runtime of 420. Using big-O notation, state the runtime for this algorithm for the general case of a data set of size n. Suppose you develop an algorithm that processes the first element of an array (length of n), then processes the first 2 elements, then the first 3 elements, and so on, until the last iteration of a loop, when it processes all elements. Thus, if n = 4, the runtime would be 1 + 2 + 3 + 4 = 10. Create a table that depicts the runtime for arrays of length 1 to 10. Would you expect the general runtime to be O(n), O(n2), O(n3), or some other function of n? Explain.Explanation / Answer
1. first I would sort the data
2. in the sequential search I would then look at the first item and check if it is 19 then look at the 2nd item and check etc.
In a binary search snce there are 16 items
1.check item 8 if item 8 is less than 19 check item 12
if item 8 is greater than 19 check item 4
continue in this manner
in the sequential search you will need 10 searches
in the binary search you will need 3 searches
item 8 17 between 1 -16
item 12 22 between 8-16
item 10 19 between 12 and 8 done
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.