Consider function search(elm, low, high, myArray) that searches for the value elm in the array myArray between the indexes low and high and returns the index where elm is found in the array or returns -1 if not found.
For this Discussion Board, please complete the following:
Consider function search(elm, low, high, myArray) that searches for the value elm in the array myArray between the indexes low and high and returns the index where elm is found in the array or returns -1 if not found.
For example, if myArray is [4, 7, 8, 9, 12, 56], then you have the following:
search(12, 0, 5, myArray) returns 4
search(10, 0, 5, myArray) returns -1
Now consider the linear and binary algorithms below for the function search:
Linear Search
Function search(elm,low,high, myArray)
index = low
While(index <= high)
If myArray[index] == elm then
Return index // found
Else index = index + 1
End While
Return -1 // not found
End Function
Binary Search
Function search(elm,low,high, myArray)
While(high >= low) then
mid = (low + high) / 2
If (myArray[mid] == elm
Return mid; // found
Else
If (myArray[mid] > elm) then // search in the left half
high = mid-1
Else // search in right half
Low = mid +1
End While
Return -1 // not found
End Function
Complete the following:
How many iterations are performed in each algorithm for the function call search(12, 0, 6, myArray) if myArray = [2, 3, 6, 9, 12, 15, 19]?
Which of these two algorithms runs faster?
Why do you believe that one runs faster than the other?
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.