blense.
HomeFrontendCodeAINewsGuidesCheatsheetsAbout

Technology decoded, always.

A curated read on AI, product, and the culture behind the code. No noise, no hype.

blense.

Technology with focus. Stories about what innovation really changes.

Sections

FrontendArtificial IntelligenceCode & DevTech News

Blense

AboutRSSPrivacy policyTermsCookies
© 2026 Blense · blense.fun
Code & Development

Algorithms and Programming Logic: Every Developer's Map

Learn to solve problems on paper before coding. Understand sequence, selection, repetition, sorting algorithms, and Big O complexity.

Gby Genildo SouzaJun 119 min read
Algorithms and Programming Logic: Every Developer's Map

You didn't get stuck because algorithms are hard. You got stuck because no one showed you the problem before handing you the solution. This article fixes that — from the simplest concept all the way to complexity analysis.

That feeling has a name — and it has a solution. It happens when you try to write code before thinking about the algorithm. It's like trying to build a house without a blueprint: you might even put up some walls, but soon you realize the bathroom ended up in the wrong place.

This article will show you the map every developer needs to master before typing the first line of code.

What Is an Algorithm, Really?

💡

Forget the academic definition for a second.

An algorithm is simply a finite, ordered sequence of steps to solve a problem. No ambiguity. No steps that rely on guessing. Each instruction needs to be clear enough for a machine — which doesn't think, it only executes — to follow.

Think about your grandmother's cake recipe. It has ingredients (input data), a preparation order (executable steps), and an expected result (output). If you skip a step or change the order, the cake won't turn out right. With algorithms, the logic is exactly the same.

ℹ️

The big mental shift that separates beginner programmers from solid programmers is: first you solve the problem on paper, then you write the code.

The Three Structures That Govern Everything

All programming logic — regardless of language — rests on just three control structures. Yes, just three.

1. Sequence

The simplest one. Steps are executed one after another, in the order they appear.

C
int x = 10;int y = 20;int soma = x + y;printf("Resultado: %d\n", soma);

No surprises. The computer reads line by line, from top to bottom.

2. Selection (Decision)

This is where the program gains intelligence. Depending on a condition, it chooses one path or another.

C
if (temperatura > 38) {    printf("Febre detectada. Consulte um médico.\n");} else {    printf("Temperatura normal.\n");}

There are three main forms of selection:

  • Simple: one or two alternative paths (if/else)

  • Chained: choice between multiple paths (if/else if/else)

  • Multiple: compare a variable against several fixed values (switch/case)

The switch/case is perfect when you have many well-defined options — like the days of the week or the options in a menu.

3. Repetition (Loops)

The heart of automation. Running the same block of code multiple times without having to rewrite it.

Counted repetition — when you know exactly how many times you will repeat:

C
for (int i = 1; i <= 10; i++) {    printf("%d\n", i);}

Repetition with pre-condition — when you test the condition before entering the loop:

C
while (saldo > 0) {    saldo -= parcela;}

Repetition with post-condition — when the block needs to execute at least once:

C
do {    printf("Digite um número positivo: ");    scanf("%d", &numero);} while (numero <= 0);
⚠️

Golden rule: avoid infinite loops interrupted by break. If you need a break to exit a loop, the stop condition was probably poorly defined.

Data Types: The Raw Material of the Program

Before processing any information, the computer needs to know what type of data it is dealing with. In C, the basic types are:

Type

What it stores

Example

int

Integer numbers

42, -7, 0

float

Numbers with decimal places

3.14, -0.5

char

A single character

'A', 'z'

char[]

Character string (text)

"Hello, world"

These data live as variables (values that change during execution) or constants (values that never change). Using constants for fixed values — such as PI = 3.14159 — makes the code more readable and safe.

Functions: The Secret of Clean Code

If you catch yourself repeating the same block of code in different places, it's a sign that that snippet deserves to become a function.

A function is a block of code with a specific purpose. It receives data (parameters), processes it, and returns a result.

C
float calcularMedia(float nota1, float nota2, float nota3) {    return (nota1 + nota2 + nota3) / 3;}

There are two fundamental types:

  • void: the function performs an action and returns nothing (like printing to the screen)

  • Typed (int, float...): the function performs a calculation and returns a result

💡

Good functions have names that describe exactly what they do. calcularMedia() is much better than func1(). Your future self — and your teammates — will thank you.

Best Practices That Make a Difference

Mastering the syntax is the easy part. What separates amateur code from professional code are the habits.

Plan before coding. Before opening the editor, define: what data goes in? What comes out? What is the sequence of steps? A sketch on paper is worth more than an hour of trial and error.

Comment what is not obvious. The compiler ignores comments, but your colleagues (and you yourself, six months from now) don't. Document the intent of the code, not just what it does.

C
// Calcula o índice de massa corporal conforme tabela da OMSfloat imc = peso / (altura * altura);

Write portable code. Avoid operating-system-specific functions when an alternative exists in the ISO C standard. Portable code runs on Windows, Linux, and Unix without modifications.

Use meaningful names. temperatura, contador, nomeUsuario are infinitely better than t, c, n. Clarity is not fussiness — it's respect for whoever reads your code next.

Best Practices
Plan first
Plan before coding

Sketch inputs, outputs, and steps on paper before opening the editor.

Document
Comment the non-obvious

Document the why for your future self and colleagues.

Portable
Write portable code

Prefer ISO C standard functions over OS-specific ones; runs on Windows, Linux, and Unix without modifications.

Clarity
Use meaningful names

Choose temperatura or nomeUsuario instead of t or n. Clarity is respect for whoever reads your code next.

Four habits that make code easier to read, maintain, and port across systems.

Classic Algorithms Every Programmer Should Know

Theory without practice is decoration. See how the concepts above materialize in real algorithms — the same ones used in databases, search systems, and everyday applications.

Linear Search vs. Binary Search: the difference that changes everything

Imagine you need to find the number 23 in a list of a thousand numbers.

Linear Search — checks one by one, from start to finish:

PYTHON
def busca_linear(lista, alvo):    for i in range(len(lista)):        if lista[i] == alvo:            return i  # retorna o índice onde encontrou    return -1  # não encontradonumeros = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91]print(busca_linear(numeros, 23))  # saída: 5

It works. But in the worst case, it goes through all elements. In a list of one million? One million comparisons.

Binary Search — splits the problem in half at each step. Requires a sorted list:

PYTHON
def busca_binaria(lista, alvo):    inicio = 0    fim = len(lista) - 1    while inicio <= fim:        meio = inicio + (fim - inicio) // 2        if lista[meio] == alvo:            return meio          # encontrou!        elif lista[meio] < alvo:            inicio = meio + 1    # descarta a metade esquerda        else:            fim = meio - 1       # descarta a metade direita    return -1  # não encontradonumeros = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91]print(busca_binaria(numeros, 23))  # saída: 5
ℹ️

In a list of one million elements, binary search finds any value in at most 20 comparisons. It's not magic — it's a logarithm.

Algorithm

Worst case (1 million items)

Requires sorting?

Linear Search

1,000,000 comparisons

No

Binary Search

~20 comparisons

Yes

Sorting Algorithms: putting the house in order

To use binary search, you need sorted data. And to sort data, you need a sorting algorithm.

Bubble Sort — the simplest to understand. It works like bubbles rising to the surface: at each pass, the largest element floats to the end:

PYTHON
def bubble_sort(lista):    n = len(lista)    for i in range(n):        for j in range(0, n - i - 1):            # se o elemento atual é maior que o próximo, troca            if lista[j] > lista[j + 1]:                lista[j], lista[j + 1] = lista[j + 1], lista[j]    return listanumeros = [64, 34, 25, 12, 22, 11, 90]print(bubble_sort(numeros))  # [11, 12, 22, 25, 34, 64, 90]

The same algorithm in C:

C
void bubble_sort(int arr[], int n) {    for (int i = 0; i < n - 1; i++) {        for (int j = 0; j < n - i - 1; j++) {            if (arr[j] > arr[j + 1]) {                int temp = arr[j];                arr[j] = arr[j + 1];                arr[j + 1] = temp;            }        }    }}
📝

Why learn Bubble Sort if it's slow? Because it teaches the fundamental sorting patterns: comparison, swapping, and multiple passes. After understanding Bubble Sort, algorithms like Merge Sort and Quick Sort make immediate sense.

Recursion: when a function calls itself

A concept that scares beginners but is elegant when you understand it: a function that solves a problem by calling itself with a smaller version of the same problem.

PYTHON
def fatorial(n):    # caso base: para a recursão    if n == 0 or n == 1:        return 1    # chamada recursiva com problema menor    return n * fatorial(n - 1)print(fatorial(5))  # 5 × 4 × 3 × 2 × 1 = 120

Every recursive function has two mandatory components:

  • Base case: the stopping condition (without it, infinite recursion)

  • Recursive call: the problem reduced to a smaller version of itself

Recursion is the foundation of powerful algorithms like Merge Sort, tree search, and graph traversal.

Algorithm Complexity: the cost of what you write

Every algorithm has a cost. The notation Big O describes how that cost grows as the input size increases.

Notation

Name

Example

O(1)

Constant

Accessing array element by index

O(log n)

Logarithmic

Binary Search

O(n)

Linear

Linear Search

O(n log n)

Linearithmic

Merge Sort, Quick Sort

O(n²)

Quadratic

Bubble Sort, Selection Sort

⚠️

The choice of algorithm directly impacts system performance. An O(n²) algorithm applied to one million records is catastrophic. The same problem with O(log n) runs in milliseconds.

The Most Common Mistake of Those Starting Out

Most beginners try to learn programming by learning a language.

They memorize the syntax of if, of for, of while — but when they hit a real problem, they freeze. Because the problem is never syntax. The problem is logic.

The language is just notation. The algorithm is the thought.

💡

Flip the order: first solve the problem on paper, then translate it to code. Draw the flow. Break the problem into smaller parts. Define the inputs and outputs of each part. Only then open the editor.

This habit — apparently simple — is what sets apart a programmer who moves forward from one who stays stuck forever in tutorials.

Conclusion

Algorithms and programming logic aren't college material. They're the foundation of everything you'll build as a developer.

The elite dev's arsenal.
Microfrontends with Angular and Nx: what nobody tells you15 minStop using forEach: 8 semantic array methods to make your JavaScript code readable8 minTanStack Query: How to Eliminate Manual Server State Management in React6 minAngular Micro-frontends: How to Scale Large Applications and Eliminate Monolithic Build Times with Module Federation10 min

Sequence, selection, and repetition. Data types. Well-named functions. Binary Search. Big O complexity. Planning before code.

These concepts don't go out of style. It doesn't matter if the language of the moment is C, Python, JavaScript, or whatever else emerges in the coming years — the logic behind all of them is the same.

What remains
  • 1Algorithm: finite, ordered sequence of steps to solve a problem.
  • 2Three control structures: sequence, selection, and repetition.
  • 3Data types: int, float, char — variables vs constants.
  • 4Functions: reusable blocks with a specific purpose.
  • 5Binary Search is O(log n) — exponentially faster than linear search.
  • 6Bubble Sort teaches the sorting patterns every advanced algorithm uses.
  • 7Recursion: base case + recursive call. Always.
  • 8Big O: the algorithm's cost determines whether the system scales or freezes.
  • 9First solve it on paper. Then open the editor.

Keep exploring
Want more content like this?

Check out other articles in the same vein and keep the momentum.

See more articles
#JavaScript#TypeScript

The elite dev's arsenal.

Microfrontends with Angular and Nx: what nobody tells you
Code & Development

Microfrontends with Angular and Nx: what nobody tells you

Most tutorials show how to build microfrontends in minutes, but few reveal the architectural debt that emerges after months of production deployments.

Genildo Souza · Jul 28 · 15 min
JavaScript Event Loop: The Heart of Non-Blocking Concurrency — Revisited in 2025
Code & Development

JavaScript Event Loop: The Heart of Non-Blocking Concurrency — Revisited in 2025

The Event Loop is not just a simple loop, but a sophisticated coordination mechanism between Call Stack, queues, and runtime. Essential for JS concurrency, it enables thousands of asynchronous operations without blocking the UI. This guide explores its structure, differences between Node.js and browsers, common bugs, advanced techniques, and 2025 trends like Structured Concurrency and scheduler.yield().

Genildo Souza · Jul 26 · 6 min
Next.js 16 PPR: Eliminate the static vs. dynamic tradeoff and achieve Edge TTFB with fresh data
Code & Development

Next.js 16 PPR: Eliminate the static vs. dynamic tradeoff and achieve Edge TTFB with fresh data

Partial Prerendering in Next.js 16 resolves the classic rendering tradeoff, delivering static speed with dynamic data in one seamless response.

Genildo Souza · Jul 13 · 14 min
In this article
  • What Is an Algorithm, Really?
  • The Three Structures That Govern Everything
  • 1. Sequence
  • 2. Selection (Decision)
  • 3. Repetition (Loops)
  • Data Types: The Raw Material of the Program
  • Functions: The Secret of Clean Code
  • Best Practices That Make a Difference
  • Classic Algorithms Every Programmer Should Know
  • Linear Search vs. Binary Search: the difference that changes everything
  • Sorting Algorithms: putting the house in order
  • Recursion: when a function calls itself
  • Algorithm Complexity: the cost of what you write
  • The Most Common Mistake of Those Starting Out
  • Conclusion