Loops Time Complexity - 4

Duration: 16 min

This video lesson is available to enrolled students.

Return to /learn/GATE-GUIDANCE-BY-SANCHIT-SIR/algorithms/time-complexity-analysis/iterative-loops-code/asset-loops-time-complexity-4 after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. Discrete Mathematics: Set Theory, Relations, Functions, Graph Theory, Group Theory, Propositional and Predicate Logic
  2. 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
  3. Digital Electronics: Digital Systems & Boolean Basics, Logic Gates & Hardware, Boolean Expression, Boolean Minimization, Combinational Circuit, Sequential Circuits, Number System, Number Representation
  4. Computer Architecture: Floating Point Rep, Cache Memory Organization, Input Output Organisation, Pipelining, Instr Formats & Modes, Control Unit Design
  5. Operating System: Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Threads & Process Creation, Deadlock, Memory Management, Virtual Memory, Disc Scheduling, File Management
  6. C Language: C Fundamentals, Control Flow, Functions, Arrays & Pointers, Storage Classes, Structures & Enums, DMA, Macros, Scoping & File Handling
  7. Data Structures: Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
  8. Algorithms: Algorithm Analysis, Time Complexity Analysis, Sorting Algorithms, Greedy Algorithms, Dynamic Programming, Minimum Spanning Trees, Shortest Path Algos
  9. 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
  10. 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
  11. 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
  12. Engineering Mathematics: Permutation and Combination, Linear Algebra, Calculus, Probability, Statistics
  13. 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
  14. 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
  15. Live Classes Recordings(Earlier Batch): GATE 2026 Live Class
  16. Full Mock Test:
  17. Previous Year Papers:
  18. 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 for loops where the iterator variable is multiplied by a constant factor in each iteration, resulting in logarithmic time complexity. The instructor systematically breaks down the execution flow of loops with multiplicative increments, such as i = i * 2 and i = i * 7. By tracing the values of the iterator variable as powers of the multiplier (e.g., 1, 2, 4, 8... or 1, 7, 49...), the instructor establishes a geometric progression. The core method involves setting up an inequality where the final value of i is less than or equal to n (e.g., 2^k <= n), solving for the number of iterations k using logarithms, and concluding that the time complexity is O(log n). The lecture emphasizes the mathematical derivation of loop termination conditions and demonstrates how different multipliers affect the base of the logarithm while maintaining the same asymptotic complexity class.

Chapters

  1. 0:00 – 2:00 00:00-02:00

    The instructor introduces the analysis of a for loop with multiplicative increment, specifically i = i * 2. Visible on screen is the code snippet '7. for(i = 1; i <= n; i = i * 2)'. The instructor initializes the variable i to 1 and writes down the loop condition '1 <= n' to begin determining the number of executions. This initial setup establishes the foundation for analyzing how the iterator grows exponentially rather than linearly, marking the start of a derivation that will lead to logarithmic complexity.

  2. 2:00 – 5:00 02:00-05:00

    The instructor traces the execution steps of the loop, writing out the values of i as powers of 2: 'i = 1', 'i = 2', 'i = 2^2', and 'i = 2^3'. The whiteboard shows a sequence of boolean checks against n, such as '1 <= n ? True -> 1' and '2 <= n ? True -> 3'. This visual mapping demonstrates the geometric progression of the iterator variable, illustrating how each iteration doubles the previous value. The instructor marks 'True' conditions to count iterations, reinforcing the concept that the loop continues as long as the current power of 2 remains less than or equal to n.

  3. 5:00 – 10:00 05:00-10:00

    The instructor formalizes the termination condition by setting '2^k <= n' and solving for k using logarithms. The derivation shows steps like '$\log_2 i^k \le \log_2 n$' leading to 'k <= log2 n'. The instructor notes that the loop runs '(k+1) Times', accounting for the initial iteration. This section transitions from tracing specific values to a general algebraic proof, demonstrating that the number of iterations is proportional to the logarithm of n. The visual evidence includes the inequality setup and the final conclusion that the complexity is O(log n).

  4. 10:00 – 15:00 10:00-15:00

    The lecture shifts to a new example with the loop '8. for(i = 1; i <= n; i = i * 7)'. The instructor writes the sequence of values 'i = 7^0', 'i = 7^1', 'i = 7^2' to show the geometric progression with a base of 7. The derivation follows the same pattern as before, setting up '7^k <= n' and applying logarithms to solve for k. The instructor highlights that the number of iterations is determined by 'floor(log_7(n)) + 1'. This comparison reinforces that while the base of the logarithm changes with the multiplier, the asymptotic complexity remains O(log n).

  5. 15:00 – 16:03 15:00-16:03

    The instructor concludes the analysis of the i = i * 7 loop by finalizing the inequality '7^k <= n' and solving for k. The whiteboard displays the final complexity result as 'Time = floor(log_7(n)) + 1' which simplifies to '= O(log n)'. This final step confirms that loops with multiplicative increments always exhibit logarithmic time complexity regardless of the specific multiplier used. The instructor emphasizes that the base of the logarithm is determined by the multiplication factor, but Big-O notation abstracts away constant factors.

The lecture provides a rigorous mathematical derivation for determining the time complexity of loops with multiplicative increments. The central concept is that when an iterator variable i starts at 1 and is multiplied by a constant c in each iteration (i = i * c), the value of i grows exponentially as c^0, c^1, c^2... The loop terminates when c^k > n. By solving the inequality c^k <= n for k, we find that k is proportional to log_c(n). Since Big-O notation ignores constant factors and base changes in logarithms, the time complexity is universally O(log n). The instructor uses two distinct examples (c=2 and c=7) to demonstrate that the specific multiplier only changes the base of the logarithm, not the asymptotic growth rate. This method of tracing values to powers and solving inequalities is a standard technique for analyzing non-linear loop progressions.

Loading lesson…