Algorithm

Copy

সহজভাবে বললে, একটি কাজ complete করার জন্য clear এবং ordered steps-ই হলো algorithm.

Example

Problem: দুইটা number add করা

  • Step 1: Start
  • Step 2: A এবং B input নাও
  • Step 3: Sum = A + B
  • Step 4: Sum print করো
  • Step 5: Stop
` }, { title: "Characteristics of Algorithm (অ্যালগরিদমের বৈশিষ্ট্য)", body: `

একটি good algorithm-এর কিছু important characteristics আছে:

  • Input: zero বা more input নিতে পারবে
  • Output: minimum একটি output দিবে
  • Definiteness: প্রতিটি step clear এবং unambiguous হতে হবে
  • Finiteness: finite সংখ্যক step-এর মধ্যে শেষ হতে হবে
  • Effectiveness: steps practical এবং executable হতে হবে

Example

দুইটি সংখ্যার মধ্যে বড়টি বের করা:

  • A এবং B input নাও
  • যদি A > B হয়, A print করো
  • নাহলে B print করো
  • Stop
` }, { title: "Recursive and Non-Recursive Algorithms", body: `

Recursive Algorithm: যে algorithm নিজেকেই call করে smaller subproblem solve করে.

Non-Recursive Algorithm: যে algorithm নিজেকে call না করে loop বা normal steps দিয়ে কাজ করে.

Example: Factorial

Recursive: fact(n) = n × fact(n-1)

Base case: n = 0 বা 1 হলে fact = 1

Non-Recursive:

  • fact = 1
  • 1 থেকে n পর্যন্ত loop চালাও
  • fact = fact × i
  • শেষে fact print করো
` }, { title: "Flowchart Representation (ফ্লোচার্ট দিয়ে উপস্থাপন)", body: `

Flowchart হলো algorithm-এর graphical representation.

এখানে different symbols ব্যবহার করে stepগুলো দেখানো হয়.

  • Oval: Start / Stop
  • Parallelogram: Input / Output
  • Rectangle: Process
  • Diamond: Decision

Example: Even or Odd check

  • Start
  • একটি number N input নাও
  • N % 2 == 0 কিনা check করো
  • True হলে “Even” print করো
  • False হলে “Odd” print করো
  • Stop
` }, { title: "Pseudocode Representation (ছদ্ম-কোড)", body: `

Pseudocode হলো algorithm লেখার একটি easy informal way.

এটা programming language না, কিন্তু program-এর logic clear করে.

Example

BEGIN
  INPUT A, B
  SUM = A + B
  PRINT SUM
END
` }, { title: "Efficiency of Algorithm (অ্যালগরিদমের দক্ষতা)", body: `

Algorithm efficiency বলতে বোঝায়, একটি algorithm কত কম time এবং কত কম memory use করে problem solve করতে পারে.

যে algorithm কম resource use করে, সেটি বেশি efficient.

Example

Sorted list-এ search করার জন্য:

  • Linear Search: one by one check করে
  • Binary Search: list-কে বারবার half করে search করে

এখানে Binary Search বেশি efficient.

` }, { title: "Space Complexity (মেমোরি জটিলতা)", body: `

Space Complexity হলো algorithm run করার সময় কত memory লাগে তার measure.

এতে input space এবং extra auxiliary space দুটোই consider করা হয়.

Example

একটি array-এর sum বের করতে যদি শুধু sum variable use করা হয়, তাহলে extra memory খুব কম লাগে.

তাই এর space complexity low.

` }, { title: "Time Complexity (সময় জটিলতা)", body: `

Time Complexity বোঝায় input size বাড়লে algorithm-এর running time কীভাবে বাড়ে.

এটি algorithm compare করার জন্য খুব important.

Example

যদি একটি loop n বার চলে, তাহলে time complexity সাধারণত O(n).

যদি two nested loops থাকে এবং দুটোই n বার চলে, তাহলে complexity হবে O(n²).

` }, { title: "Asymptotic Notation: Big O, Big Omega, Big Theta", body: `

Asymptotic Notation ব্যবহার করা হয় large input-এর জন্য algorithm-এর growth rate বোঝাতে.

মানে, exact time count না করে আমরা দেখি input বাড়লে algorithm কত দ্রুত slow হচ্ছে.

Main Idea

  • Big O - O(f(n)): worst case বা upper bound বোঝায়
  • Big Omega - Ω(f(n)): best case বা lower bound বোঝায়
  • Big Theta - Θ(f(n)): tight bound, অর্থাৎ exact growth range বোঝায়
Simple Visual Diagram

নীচের graph-এ X-axis = input size (n), Y-axis = running time.

Input size (n)
Time
Big Ω → Best case / lower bound Big Θ → Tight / exact growth Big O → Worst case / upper bound

Easy Understanding

ধরো, তুমি একটি classroom-এ একজন student-কে খুঁজছো.

  • Best case: first bench-এই পেয়ে গেলে → Ω(1)
  • Worst case: সব bench check করতে হলো → O(n)
  • Overall linear growth: average/tightভাবে → Θ(n)

Example 1: Linear Search

Linear search একটার পর একটা element check করে.

  • Best Case: item প্রথম position-এ → Ω(1)
  • Worst Case: item last-এ বা নেই → O(n)
  • Tight Bound: সাধারণ growth → Θ(n)

Example 2: Constant Time

Array-এর first element access করা:

print(arr[0])

এখানে input size যতই বড় হোক, time একই রকম থাকে.

তাই এটি O(1), Ω(1), এবং Θ(1).

Example 3: Nested Loop

for(i = 1; i <= n; i++)
  for(j = 1; j <= n; j++)
    print(i, j)

Outer loop n বার, inner loop n বার → total operation ≈ n × n = n²

তাই complexity Θ(n²) এবং worst case O(n²).

Common Complexity Table

Notation Meaning Example
O(1) Constant time array first element access
O(log n) Logarithmic Binary Search
O(n) Linear Linear Search
O(n log n) Efficient sorting Merge Sort
O(n²) Quadratic Bubble Sort

Final Summary

  • Big O বলে algorithm maximum কতটা grow করতে পারে
  • Big Ω বলে minimum কতটা time লাগতেই পারে
  • Big Θ বলে actual growth roughly কোন range-এ

Exam-এ short মনে রাখার trick:

O = Over limit, Ω = lower limit, Θ = exact limit

` } ]; let currentTopic = 0; const root = document.getElementById("algorithmNotesApp"); root.innerHTML = `

Algorithm Fundamentals

Mixed Bengali + English Notes

`; const topicNumber = root.querySelector("#topicNumber"); const topicTitle = root.querySelector("#topicTitle"); const topicBody = root.querySelector("#topicBody"); const prevBtn = root.querySelector("#prevBtn"); const nextBtn = root.querySelector("#nextBtn"); const footerText = root.querySelector("#footerText"); const topicList = root.querySelector("#topicList"); function renderSidebar() { topicList.innerHTML = ""; topics.forEach((topic, index) => { const li = document.createElement("li"); li.textContent = `${index + 1}. ${topic.title}`; if (index === currentTopic) li.classList.add("active"); li.addEventListener("click", () => { currentTopic = index; showTopic(currentTopic); }); topicList.appendChild(li); }); } function showTopic(index) { topicNumber.textContent = `Topic ${index + 1} of ${topics.length}`; topicTitle.innerHTML = topics[index].title; topicBody.innerHTML = topics[index].body; footerText.textContent = "Sidebar থেকে topic select করতে পারবে, অথবা Next / Previous button use করতে পারবে."; prevBtn.disabled = index === 0; nextBtn.disabled = index === topics.length - 1; renderSidebar(); } prevBtn.addEventListener("click", () => { if (currentTopic > 0) { currentTopic--; showTopic(currentTopic); } }); nextBtn.addEventListener("click", () => { if (currentTopic < topics.length - 1) { currentTopic++; showTopic(currentTopic); } }); showTopic(currentTopic); })();