Programmer's Picnic — Live Zoom Lesson
Fun, short lessons for curious programmers — hands-on, friendly, and practical.
Linear Search on Youtube
Topic: Algorithm picnic — Visualizing searching
Level: Beginner → Intermediate
Lesson Snapshot
Topic: Algorithm picnic — Visualizing linear search
Level: Beginner → Intermediate
Short description: Join us for a 40-minute interactive Zoom where we explain a compact algorithm, show pseudocode, implement it in Python , run a tiny demo, and finish with a 5-question MCQ lightning quiz.
Agenda
- Welcome & quick icebreaker
- Concept introduction & intuition
- Pseudocode walk-through + dry run on whiteboard
- Code implementations & live demo
- MCQ quiz + recap
- Q&A and next steps
Learning Outcomes
- Understand the algorithm's idea and when to use it.
- Read and follow pseudocode and dry-run examples.
- Implement the algorithm quickly in your preferred language.
- Spot basic complexity and possible optimisations.
Pre-work (Optional)
Please bring a laptop with a code editor or open browser console. If possible, paste the code snippets shared in the 'Materials' section into your editor before the meeting.
Left Linear Search
We'll do a whiteboard-style dry run on the sample array and annotate each swap step live.
Code — Implementations
Python
a = [7, 5, 1, 8, 5, 9, 5, 2]
print(a)
# a[3]=90
# print(a)
searchvalue=int(input("Enter value to search "))
n=len(a)
# print(f"n={n}")
# print(a[n-1])
position="Not found"
r=range(n)
for index in r:
# print(index,a[index])
if a[index]==searchvalue:
position=index
break
if position=="Not found":
print(f"{searchvalue} is {position}")
else:
print(f"{searchvalue} found at {position}")
Right Linear Search
We'll do a whiteboard-style dry run on the sample array and annotate each swap step live.
Code — Implementations
Python
a = [7, 5, 1, 8, 5, 9, 5, 2]
# 1,4 and 6
print(a)
searchvalue = int(input("Enter value to search "))
n = len(a)
position = "Not found"
r = range(n-1, -1, -1)
for index in r:
if a[index] == searchvalue:
position = index
print(position)
break
if position == "Not found":
print(f"{searchvalue} is {position}")
else:
print(f"{searchvalue} found at {position}")
You can copy-paste any snippet and run it during the live demo. We'll run the JS in the browser console for immediate visual feedback.
All Linear Search
We'll do a whiteboard-style dry run on the sample array and annotate each swap step live.
Code — Implementations
Python
a = [7, 5, 1, 8, 5, 9, 5, 2]
# 1,4 and 6
print(a)
searchvalue = int(input("Enter value to search "))
n = len(a)
positions = []
r = range(n-1, -1, -1)
for index in r:
if a[index] == searchvalue:
positions.append(n-1-index)
print(positions)
# break
# A1,B2,C3.......X24,Y25,Z26 27-1=26
if len(positions) == 0:
print(f"{searchvalue} is not found")
else:
print(f"{searchvalue} found at {positions}")
Complexity & Notes
- Time complexity: O(n) worst-case, O(n) best-case O(1).
- Space complexity: O(1) (in-place).
- Good for: small arrays, unsorted data, teaching/learning steps.
Lightning Quiz — 5 MCQs
1. Best-case time complexity of Linear Search?
2. Is linear search stable?
3. Space complexity of insertion search?
4. Which input suits linear search best?
5. In the right search we moved in from the right. That is an example of:
Next Steps & Resources
- Repo & code bundle: We will share a Google Drive / GitHub link during the Zoom.
- Recording: Will be available within 24 hours after the session.
- Homework: Implement a visualiser or convert the code to another language you prefer.
Prepared by Champak Roy — Programmer's Picnic series.
1 Comments
Sir, I learned programing, from many faculty in Hyderabad and Bangalore but they teaches only subject, but this type of analysis no one conducted in programing class, please upload more and more video, this will help many programmer...
ReplyDelete