DSA Tutorial



ALGORITHM IN DSA


⚙️ What is an Algorithm in DSA?

An algorithm is a step-by-step method to solve a problem in a finite number of steps. In DSA, algorithms help in efficiently processing and manipulating data.

🧠 Simple Example:

Imagine you want to make tea. Your algorithm would be:

  1. Boil water
  2. Add tea leaves
  3. Add sugar and milk
  4. Stir and strain
This is an algorithm! It solves the "make tea" problem.

🧩 Characteristics of a Good Algorithm

  • Input: Clearly defined inputs
  • Output: Clearly defined output
  • Finiteness: Must terminate after a finite number of steps
  • Effectiveness: Every step must be basic and doable
  • Unambiguity: Steps should be clear and not vague

📦 Types of Algorithms

🔁 Recursion

Solves problems by calling itself.

🚀 Greedy

Chooses the best option at each step.

🧮 Dynamic Programming

Stores results of subproblems to avoid repetition.

📊 Divide and Conquer

Divides the problem into smaller parts and solves each.

🔍 How Do We Measure an Algorithm?

  • Time Complexity: How fast the algorithm runs.
  • Space Complexity: How much memory it uses.
🛠 Sample Algorithm - Find Maximum Number
1. Start
2. Take input array of n numbers
3. Set max = first element
4. Loop i from 1 to n-1
     → If arr[i] > max
         → max = arr[i]
5. Print max
6. Stop
    
Next: Time & Space Complexity ➜

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review