🚀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