Write pseudocode for the linear search algorithm, and then explain it’s complexity using big-O notation

Pseudocode: FUNCTION linearSearch(list, searchTerm):               FOR index FROM 0 -> length(list):                               IF list[index] == searchTerm THEN                                               RETURN index                               ENDIF               ENDLOOP               RETURN -1 ENDFUNCTION Complexity: Recognize that the single for loop will access each element in the list once in WCS.If each element is accessed once, then as list grows the time taken (WCS) grows in linear timeTherefore : O(n)What about best case? Average case?Encourage comparison with other known/unknown algorithms

JN

Related Computing A Level answers

All answers ▸

What is an Algorithm?


What is meant by the term spooling? Give an example of when it can be used.


Discuss the differences between operating systems designed for desktop computers and embedded systems.


What are the main differences between different loops when it comes to coding ?