Linear Search
GlobalSearching
Created by pattakorn.k on Oct 1, 2026
Pseudocode
// PSC:1.0 LinearSearch
// Description: Finds the position of a target value by checking every item in turn
FUNCTION findIndex(list, n, target)
FOR i FROM 0 TO n - 1
IF list[i] = target
RETURN i
END IF
END FOR
RETURN -1
END FUNCTION
BEGIN LinearSearch
INPUT "How many numbers? " n
FOR k FROM 0 TO n - 1
INPUT "Next number: " value
LET list[k] = value
END FOR
INPUT "Number to find: " target
LET position = CALL findIndex(list, n, target)
IF position = -1
OUTPUT target " is not in the list"
ELSE
OUTPUT target " found at position " position
END IF
ENDInteractive Preview
Generating flowchart…