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

Answered by Jacob N. Computing tutor

26752 Views

See similar Computing A Level tutors

Related Computing A Level answers

All answers ▸

How does the Stack data type work?


What the main differences between an interpreter and a compiler?


Some problems are intractable. What does it mean for a problem to be described as intractable?


Taken from an AQA paper: A common misconception is that the Internet is the World Wide Web. Explain the differences between the Internet and the World Wide Web.


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy