What is a linear structure of an algorithm?
Short answer
A linear structure of an algorithm is the sequential execution of steps without branching or loops: operations follow one another along a single, predetermined path from start to finish.
Detailed answer
Definition
A linear (sequential) structure is one of the basic control constructs of algorithms, alongside branching (selection) and looping (iteration). In a linear structure, all instructions are executed strictly in order, without conditions or repetition.
Key properties
- One entry and one exit: execution begins at one point and ends at another without branches.
- No conditions or loops: there are no if/else, switch, for/while, or similar statements.
- Deterministic path: the same set of steps is always executed in the same order.
- Easy to understand and test: each step follows the previous one, with no branching of state.
When to use it
- Simple data transformation pipelines (string normalization, computing a final price, date formatting).
- Initialization and configuration, where steps are strictly ordered and do not depend on conditions.
- Build/Deploy steps that always run in the same order (for example, "build → minify → upload").
Not to be confused with the term "linear algorithm (O(n))"
"Linear structure" describes a type of control flow (a sequence of steps). "Linear complexity O(n)", on the other hand, is about how time/memory depends on the size of the input. A linear structure can have any asymptotic complexity (O(1), O(n), O(n log n), and so on) - it all depends on the operations inside the steps.
A simple example (JavaScript)
- Accept the source data: base price, tax rate, discount.
- Compute the tax.
- Add the tax to the price.
- Subtract the discount.
- Round and return the result.
function finalPrice(base, taxRate, discount) {
const tax = base * taxRate; // 1) compute the tax
const withTax = base + tax; // 2) add the tax
const withDiscount = withTax - discount; // 3) subtract the discount
return Math.max(0, Number(withDiscount.toFixed(2))); // 4) round and guard against < 0
}
console.log(finalPrice(100, 0.2, 5)); // 115.00Example of a linear string-processing pipeline (JavaScript)
function normalizeInput(input) {
let s = input.trim(); // 1) remove whitespace at the edges
s = s.toLowerCase(); // 2) convert to lowercase
s = s.replace(/\s+/g, ' '); // 3) collapse extra whitespace
s = s.normalize('NFKC'); // 4) normalize Unicode
return s; // 5) return the result
}
console.log(normalizeInput(' HéLLo WORLD ')); // "héllo world"Counterexample: not a linear structure
Here there is branching and a loop, so the structure is no longer linear:
function process(items) {
let sum = 0;
for (const x of items) { // loop → no longer a linear structure
if (x > 0) { // branching → no longer a linear structure
sum += x;
}
}
return sum;
}Typical mistakes and clarifications
- Confusion with asymptotics: "linear" in terms of structure is not the same as "linear in time O(n)".
- The presence of validity checks (if) makes the algorithm not strictly linear in a formal sense; in practice, checks are often factored into a separate step before the linear pipeline.
- Function calls can hide branching/loops inside; then externally sequential code is not linear in its actual execution structure.
Summary
A linear structure of an algorithm is a simple and predictable flow of sequential steps without branching or loops. It is convenient for transformation pipelines and initializations, and it makes reading and testing easier, but it does not describe complexity - only the shape of the execution control flow.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.