Making a basic algorithm - the more interesting version
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Crafting algorithms is at the heart of computer science and software development. Algorithms are the step-by-step procedures for solving problems or performing tasks. While complex algorithms can be daunting, creating a basic algorithm involves understanding the problem, breaking it down into manageable parts, and accurately translating it into a sequence of operations. This article delves into creating a more intriguing basic algorithm, explaining the technical nuances and offering illustrative examples.
What is an Algorithm?
An algorithm can be defined as a finite sequence of well-defined instructions, typically to solve a class of problems or to perform a computation. Algorithms are independent of programming languages and serve as a blueprint of logic.
Key Characteristics
- Input: Zero or more quantities are supplied externally.
- Output: At least one quantity is produced.
- Definiteness: Clear and unambiguous instructions.
- Finiteness: The algorithm must terminate after a finite number of steps.
- Effectiveness: Each step should be basic enough to be executed.
Steps to Create a Basic Algorithm
Creating a basic algorithm involves several key steps:
Step 1: Understanding the Problem
Before jumping into coding, meticulously comprehend the problem. Define the inputs and expected outputs clearly.
› Example: Say we need an algorithm that sorts an array of numbers. Inputs are the array of unsorted numbers, and outputs are the sorted sequence.
Step 2: Breaking Down the Problem
Decompose the problem into smaller, more manageable sub-problems.
- Divide: Split the main problem into smaller segments.
- Conquer: Solve each segment independently.
- Combine: Integrate the solutions of the subproblems to get the final result.
Step 3: Designing the Algorithm
Draft a pseudo-code or flowchart outlining the steps of the algorithm.
› Example: A simple pseudo-code for Bubble Sort:
- Time Complexity: Analyze how the computing time increases with input size. In the case of Bubble Sort, the time complexity is .
- Space Complexity: Determine the amount of extra memory or storage required by the algorithm.
- Recursion: Some problems are naturally recursive, and recursion can simplify algorithm design.
- Dynamic Programming: Used for optimization problems where a problem is solved by combining solutions to subproblems.
Related reading
- Making Fibonacci faster
- making generic algorithms in go
- Manacher's algorithm algorithm to find longest palindrome substring in linear time
- Map Clustering Algorithm
- Map incrementing integer range to six-digit base 26 max, but unpredictably
- Map Tiling Algorithm
- Mapping N-dimensional value to a point on Hilbert curve
- Markov decision process value iteration, how does it work?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.