Posts

Performance Analysis in Algorithms — Understanding Space Complexity

Image
When we study how good an algorithm is, we generally focus on performance analysis , which has two major components: Time Complexity – How long the algorithm takes to run. Space Complexity – How much extra memory the algorithm uses. In this post, we will concentrate entirely on space complexity , because memory usage becomes a key factor when working with large data, recursion-heavy algorithms, or memory-constrained environments. What Is Space Complexity? Space complexity refers to the total memory an algorithm needs during execution , including input, variables, data structures, recursion stack, and auxiliary storage. We calculate it using the formula: Space = C + Sp Where: C (Fixed Part) – Memory required for constants, simple variables, fixed-size arrays, and program code. This does not change with input size. Sp (Variable Part) – Memory that depends on the input size n , such as dynamic arrays, recursion stack frames, and temporary variables inside loops. ...

Types Of Problems

 Algorithms are everywhere — from searching your phone contacts to finding the fastest route on Google Maps. But before learning algorithms, it's important to understand what kind of problem you are solving . Here is a simple guide to the main categories of problems in algorithm design, with clear examples and when to use them. 1. Searching Problems Searching problems aim to find an element inside a collection. 🔍 Example Find whether the number 23 exists in a list. Common Algorithms Linear Search Binary Search Used In Search bars, phone contacts, database lookups. 2. Sorting Problems Sorting problems involve arranging data in ascending or descending order. 🔍Example Sort the list: [9, 4, 2, 7, 1] Common Algorithms Bubble Sort Selection Sort Insertion Sort Merge Sort Quick Sort Heap Sort Used In Ranking, scheduling, database indexing. 3. Optimization Problems These problems require finding the best possible solution under specifi...

Why Algorithms Matter: Understanding GCD Through Three Different Approaches

Image
 When we solve a problem in programming, there are always many ways to reach the same answer. But not all solutions are equal — some are slow, some are fast, and some are extremely efficient. This difference in how we solve a problem is exactly why algorithms matter. To understand this better, let’s look at a classic problem: 🧩 Problem: Find the GCD (Greatest Common Divisor) of two numbers We’ll solve it using three different techniques: Consecutive Integer Checking Algorithm Middle School Procedure (Prime Factorization) Euclid’s Algorithm By comparing them, you’ll clearly see why choosing the right algorithm matters .  Consecutive Integer Checking Algorithm (CICA) Idea: Start from the smallest of the two numbers and check downwards until you find a number that divides both. Example: Find GCD(56, 98) We start checking: 56? no 55? no 54? no ... 28? yes → it divides both. Final answer: 28 Algorithm: Let a and b be the two positive integers. ...

INTRODUCTION

Image
    What is an Algorithm? An algorithm is a clear and precise sequence of steps designed to solve a specific problem. It acts like a blueprint that tells the computer exactly what to do and in what order. Before writing any program in C, Python, or any language, you must first understand the algorithm you want to implement. Think of an algorithm as the “logic” behind a solution. The program is just the implementation of that logic. Understanding Algorithms Through Real Life Algorithms are not limited to computers.      We unknowingly use them in daily life. For example, consider the process of making tea : Boil water Add tea powder Add milk Add sugar Serve This is a perfect real-life algorithm — a sequence of steps that leads to a final outcome. Every step is clear, ordered, and must be followed correctly to get the desired result. A Simple Computer Example Imagine you are asked to find the largest number in a list of values. ...