Suggest an editImprove this articleRefine the answer for “What is a linear structure of an algorithm?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)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. **Key point:** 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, and it should not be confused with "linear complexity O(n)".Shown above the full answer for quick recall.Answer (EN)Image## 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) 1. Accept the source data: base price, tax rate, discount. 2. Compute the tax. 3. Add the tax to the price. 4. Subtract the discount. 5. Round and return the result. ```js 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.00 ``` ### Example of a linear string-processing pipeline (JavaScript) ```js 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: ```js 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.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.