Back

Linear Search Pseudocode

Inputs: An array A[] with length n, and a target item ‘key’.

      i = 0 
      found = FALSE 
      WHILE i <= n AND found == FALSE    
      BEGIN 
        IF A[i] == key THEN 
          found = TRUE 
        ELSE 
          i = i + 1 
      END 

      IF found == TRUE THEN 
        output i //Output the index the item was found at. 
      ELSE 
        output “Item not found”