Loops Time Complexity - 3
Duration: 17 min
This video lesson is available to enrolled students.
Inside: a video lesson and guided study material.
Module outline
- Discrete Mathematics: Set Theory, Relations, Functions, Graph Theory, Group Theory, Propositional and Predicate Logic
- DataBase Management System/DBMS: Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, SQL, Relational Calculus, Transaction Management, Concurrency Control
- Digital Electronics: Digital Systems & Boolean Basics, Logic Gates & Hardware, Boolean Expression, Boolean Minimization, Combinational Circuit, Sequential Circuits, Number System, Number Representation
- Computer Architecture: Floating Point Rep, Cache Memory Organization, Input Output Organisation, Pipelining, Instr Formats & Modes, Control Unit Design
- Operating System: Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Threads & Process Creation, Deadlock, Memory Management, Virtual Memory, Disc Scheduling, File Management
- C Language: C Fundamentals, Control Flow, Functions, Arrays & Pointers, Storage Classes, Structures & Enums, DMA, Macros, Scoping & File Handling
- Data Structures: Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
- Algorithms: Algorithm Analysis, Time Complexity Analysis, Sorting Algorithms, Greedy Algorithms, Dynamic Programming, Minimum Spanning Trees, Shortest Path Algos
- Computer Networks: Introduction to CN, DLL: Access Control, DLL: Flow Control, DLL: Error Control, DLL: Framing, Data Link Layer - Ethernet, Net Layer: IPv4 & Proto, Net Layer: IP Addressing, Net Layer:Routing Protocol, Transport Layer Services, TL: Congestion & UDP, Application Layer, Hardware Basics
- Theory Of Computation/Automata Theory: Introduction to TOC, Deterministic FA (DFA), Non-Deterministic FA, Regular Expressions, Grammar, Regular Language Properties, Moore & Mealy Machines, Pushdown Automata & CFG, Turing Machines, Complexity Theory
- Compiler Design: Intro to Compilers, Lexical Analysis, Grammar & CFG, Syntax Analysis: Top-Down, Syntax Analysis: Bottom-Up, Semantic Analysis & SDT, Intermediate Code Gen, Code Optimization, Run Time Environment
- Engineering Mathematics: Permutation and Combination, Linear Algebra, Calculus, Probability, Statistics
- General Aptitude: Ratio and Proportion (Ratios), Divisibility Rules, Data Interpretation, Logarithm, Number System, HCF LCM, Sequence and Series (Series), Speed Time and Distance, Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Percentage, Mensuration and Geometry, Mental Ability, Arithmetic, Profit and Loss, Powers and Exponents (Surds and Indices), Average, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Syllogisms, Venn Diagram, Seating Arrangements, Blood Relations, Directions (Direction Test), Analogy, Algebra, Time and Work, Analytical Reasoning (Counting Figures Reasoning), Puzzle Solving (Puzzles), Cubes & Dices, Ranking, Order and Sequence, Mixture and Alligation, Age Problems, Clock, Selection Decision Table (Decision Making), Data Arrangement
- English (Verbal Aptitude): Vocabulary, Noun, Subject Verb Agreement (Verb Noun Agreement), Adjectives, Tenses, Pronoun, Preposition, Direct and Indirect Speech, Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Sentence Completion (Fill in the blanks), Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Sentence Correction (Error Correction), Verbal Analogy (Word Based Analogy), Conjunction, Interjection, Verb, Articles, Adverb, Modals, Sentence Construction
- Live Classes Recordings(Earlier Batch): GATE 2026 Live Class
- Full Mock Test:
- Previous Year Papers:
- GATE 2026 Counselling: Counselling and Guidance Sessions
AI summary & chapters
AI Summary
An AI-generated summary of this video lecture.
This lecture segment focuses on analyzing the time complexity of nested loop structures, specifically examining how the inner loop's increment logic affects overall computational cost. The instructor systematically breaks down various nested loop patterns, starting with basic arithmetic progressions and progressing to more complex harmonic series. Key concepts include identifying loop initialization, termination conditions, and update statements to determine iteration counts. The analysis demonstrates how different increment strategies—such as constant addition, doubling, or variable-based increments—lead to distinct complexity classes ranging from linear to logarithmic. The instructor uses mathematical derivations, including arithmetic progressions and summation formulas, to rigorously prove the time complexity of each structure. The final conclusion establishes that when the inner loop increments by the outer loop variable, the resulting complexity is O(n log n) due to the harmonic series pattern.
Chapters
0:00 – 2:00 00:00-02:00
The instructor introduces the analysis of a nested loop structure with code visible on screen: 'for(i = 1; i <= n; i++)' and 'for(j = 1; j <= n; j = j + i)'. He underlines the initialization 'i = 1' and condition 'i <= n' of the outer loop, establishing the range for variable i from 1 to n. The focus shifts to the inner loop's update statement 'j = j + i', which he circles to emphasize that j increments by the current value of i rather than a constant. He begins writing down iteration conditions, noting 'i=1 | 1 <= n' and 'j=1 | 1 <= n', setting the stage for calculating total operations based on how j evolves relative to n.
2:00 – 5:00 02:00-05:00
The analysis continues with the instructor exploring variations in inner loop increment logic. He examines a case where 'j = j + j', writing out the sequence of values 1, 2, 4, 8... to demonstrate geometric progression. The termination condition is analyzed as 'j <= n', showing how the loop runs logarithmically relative to n. He then transitions back to 'j = j + i', writing down iteration counts for specific values like 'i=1 | 1 <= n' and 'i=2 | 2 <= n-1'. He introduces a function notation 'f(x)' to represent the iteration count, beginning the derivation of a formula that connects the outer loop variable i to the number of inner loop executions.
5:00 – 10:00 05:00-10:00
The instructor derives the number of iterations for an inner loop incrementing by a constant value, specifically 'j = j + 2'. He sets up an arithmetic progression equation showing values like 'j = 1 | 1 <= n - 1' and 'j = 1 + 2*2 | 1 + 2*2 <= n - 3'. This demonstrates how to calculate iterations using the formula (last_term - first_term) / step + 1. He then moves to a more complex condition where the inner loop bound depends on i, writing 'for(j = 1; j <= n + 5*i)'. He substitutes values for i, such as 'i=1 | j=1 | 1 <= n+5(1)' and 'i=2 | j=1 | 1+5*2 <= n', illustrating how the upper bound shifts with each outer iteration.
10:00 – 15:00 10:00-15:00
Returning to the primary example 'for(j = 1; j <= n; j = j + i)', the instructor breaks down execution counts for specific values of i. He writes 'i=1 | 1 <= n' and 'j=1+0*i | 1<=n', then analyzes cases for i=2 and i=3. He derives the general formula for iterations as n/i, showing that when i=1, there are n iterations; when i=2, there are n/2 iterations. He sets up the final case 'i=n | n<=n' to complete the analysis of all possible outer loop values. The visible calculations show 'j=i | 1 <= n' and 'j=2i | 2i <= n', establishing the pattern that determines how many times j increments before exceeding n.
15:00 – 16:54 15:00-16:54
The instructor concludes the analysis by summing the total operations across all outer loop iterations. He writes the summation 'n + n/2 + n/3 + n/4 ... + n/n', factoring out n to reveal the harmonic series 'n(1 + 1/2 + 1/3 + 1/4 ... + 1/n)'. He identifies this series as approximately log n, leading to the final conclusion written on the board: 'Time Complexity = O(n log n)'. This derivation connects the code structure directly to Big O notation, demonstrating how variable-based increments in nested loops produce logarithmic growth factors.
The lecture systematically builds understanding of nested loop complexity through progressive mathematical derivation. The instructor begins by isolating loop components—initialization, condition, and update—to establish iteration bounds. He then explores how different increment strategies alter complexity: constant increments yield linear or quadratic behavior, while variable-based increments introduce logarithmic factors. The core insight emerges in the final segment where summing n/i for i from 1 to n produces a harmonic series. This pattern is critical because it appears frequently in algorithms like QuickSort or certain divide-and-conquer approaches. The visual evidence of writing 'n(1 + 1/2 + 1/3 ...)' confirms the mathematical rigor applied to algorithm analysis. Students should note that recognizing these patterns allows for quick complexity estimation without full derivation in exam settings.