๐Ÿš€Master Linear Search in Minutes (Simple DevOps Example + Time Complexity)

Raees Qazi | DevOps Engineer | Learner | Mentor | Creator | CEO-Briller Technologies

Today, I will explain algorithms in a very simple way, especially from a DevOps engineer’s point of view.

๐Ÿ”น Code vs Algorithm (Important Difference)

Before jumping into algorithms, let’s understand the difference:

Code:
 A set of instructions written in a programming language that a computer can understand and execute.

Algorithm:
 An algorithm is the idea or step-by-step logic to solve a problem.
 It is not code — it’s the thinking behind the code.

๐Ÿ‘‰ In simple words:

  • Algorithm = Plan
  • Code = Implementation of that plan

๐Ÿ” Linear Search Algorithm (Real DevOps Example)

Let’s take a simple DevOps-related example.

We have environments like:

env = ["dev", "stg", "prd"]
key = "stg"

Now, we want to find “stg” environment in the list.

๐Ÿง  Algorithm Steps (Thinking Process)

As a DevOps engineer, here’s how we think:

  1. Start
  2. Loop through all environments
  3. Compare each environment with the key
  4. If matched → Found
     Else → Not Found
  5. Stop

๐Ÿ‘‰ This is called Linear Search because we check elements one by one.

๐Ÿ’ป Convert Algorithm into Code (Python Example)

Now let’s implement this in code:

list_of_envs = ["dev", "stg", "prd", "test", "qa"]
key = "test"
for env in list_of_envs:
if env == key:
print("Found")
break

Explanation:

  • We loop through each environment
  • Compare it with the key
  • If found, we print “Found” and stop the loop

๐Ÿ” Alternative Approach (Better Practice)

list_of_envs = ["dev", "stg", "prd", "test", "qa"]
key = "test"
is_found = False
for env in list_of_envs:
if env == key:
is_found = True
if is_found:
print("Found")
else:
print("Not Found")

Why this is better?

  • Cleaner logic
  • More control (useful in real DevOps scripts and automation)

⏱️ Time Complexity (Very Important Concept)

When writing algorithms, we must think about performance.

What is Time Complexity?

It tells us how much time an algorithm takes based on input size.

๐Ÿ”น Single Loop Example

If we have n elements, and loop runs through all:

Time Complexity = O(n)

๐Ÿ‘‰ Example: Linear Search

๐Ÿ”น Nested Loop Example

for i in range(n):
for j in range(n):
print(i, j)

If n = 3, loop runs:

3 × 3 = 9 times

๐Ÿ‘‰ Time Complexity = O(n²)

⚠️ DevOps Insight

As a DevOps engineer:

  • Always try to reduce loops
  • Avoid unnecessary nested loops
  • Optimize scripts for better performance (important in CI/CD pipelines)

✅ Final Thoughts

  • Algorithm is your thinking process
  • Code is your execution
  • Always consider time complexity
  • Write efficient and clean scripts

If you found this helpful, feel free to share it with others in your DevOps community ๐Ÿš€

๐ŸŒ Online References

Comments

Popular posts from this blog

๐Ÿ“˜ Understanding Prometheus in a Simple Way-Part 3 (For DevOps Beginners)

Grafana Setup & Dashboard Creation (Part-5)— Explained by Raees Yaqoob Qazi

My First Python Program: A Simple Calculator