LINEAR SEARCH
By
Dept. of CSE
PVPSIT, Kanuru.
PRASAD V. POTLURI SIDDHARTHA INSTITUTE OF TECHNOLOGY
Dept of CSE
2025- 26
LINEAR SEARCH
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025- 26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025- 26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025- 26
Case | Time Complexity |
Best Case | O(1) |
Average Case | O(n) |
Worst Case | O(n) |
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025- 26
Space Complexity | O(1) |
PVPSIT (Autonomous)
Problem Solving Techniques
a. if the value sought is equal to current array value then
(a.1) Assign i to pos and return pos
a’. increment i value by 1
4. If the pos is equal to -1 then write out Value not found
else write out value found at pos
Dept of CSE
2025- 26
Algorithm Description
PVPSIT (Autonomous)
Problem Solving Techniques
Otherwise print “Value is present at ith index”
Dept of CSE
2025- 26
Algorithm
PVPSIT (Autonomous)
Problem Solving Techniques
A[1..n] = [70, 40, 30, 11, 57, 41, 25, 14, 52]
key := 41
pos = -1
for i = 1 to n do
If a[i] = key then
begin
pos = i
return pos
end
If pos = -1 then display “Element is not found” else
Display “Element is found at pos”
Dept of CSE
2025- 26
Pseudo-code
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025- 26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025- 26
PVPSIT (Autonomous)
Problem Solving Techniques