Loops Time Complexity - 7
Duration: 18 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 for loops where the iterator variable is updated by taking its root in each iteration. The instructor systematically derives the number of iterations required for the loop to terminate by tracing the mathematical reduction of the variable. The core concept involves transforming square root operations into fractional exponents and solving for the iteration count k using logarithms. The lecture demonstrates that loops with root-based decrements exhibit a time complexity of O(log log n), which is significantly faster than standard logarithmic or linear loops. The analysis covers two specific examples: one where the variable is square-rooted (i = sqrt(i)) and another where it is 5th-rooted (i = ^5√i). The instructor uses algebraic manipulation and logarithmic properties to establish the relationship between the input size n, the root operation, and the total number of iterations.
Chapters
0:00 – 2:00 00:00-02:00
The instructor introduces the first problem, a for loop defined as 'for(i = n; i >= 2; i = sqrt(i))'. He begins the analysis by identifying the initial state where 'i' equals 'n'. On the screen, he writes down the loop condition and draws a vertical line to separate the problem statement from the complexity calculation. He establishes the termination boundary by writing 'n >= 2' on the right side, indicating that the loop continues as long as the variable is greater than or equal to 2. This sets up the framework for calculating how many times the square root operation must be applied before 'i' drops below 2.
2:00 – 5:00 02:00-05:00
The instructor traces the evolution of variable 'i' through successive iterations. He writes out the sequence of values: starting at 'n', then becoming 'sqrt(n)' or 'n^(1/2)', and subsequently 'n^(1/4)'. He explicitly demonstrates the algebraic rule that taking the square root of 'n^(1/2)' results in '(n^(1/2))^(1/2)', which simplifies to 'n^(1/4)'. On the right side of the screen, he sets up a recurrence relation to find the number of iterations 'k', writing the condition 'n^(1/2^k) >= 2'. This step-by-step derivation shows how the exponent in the base 'n' is halved with each iteration, forming a geometric progression of exponents.
5:00 – 10:00 05:00-10:00
Continuing the analysis, the instructor extends the sequence of values to include 'n^(1/8)' and generalizes the pattern for the k-th iteration as 'n^(1/2^k)'. He lists specific conditions to check termination, such as 'n >= 2', 'n^(1/2) >= 2', and 'n^(1/4) >= 2'. The focus shifts to solving the inequality 'n^(1/2^k) >= 2' for 'k'. He applies logarithms to both sides of the equation, writing 'log n^(1/2^k) >= log 2'. Using logarithmic properties, he simplifies the exponent to '1/2^k * log n', eventually deriving a relationship that allows him to solve for the total number of iterations required for the loop to terminate.
10:00 – 15:00 10:00-15:00
The instructor transitions to a second example, changing the loop condition and update rule. The new code is 'for(i = n; i >= 5; i = ^5√i)'. He repeats the derivation process for this k-th root operation. He writes the sequence of values as 'n', 'n^(1/5)', and 'n^(1/25)', generalizing the k-th term as 'n^(1/5^k)'. He sets up the inequality 'n^(1/5^k) >= 5' to determine when the loop stops. By applying logarithms with base 5, he solves for 'k', showing that the number of iterations is proportional to the logarithm of the logarithm of n. The screen displays 'Time Complexity = [log_2 log_2 n] + 1' and concludes with the Big-O notation 'O(log log n)'.
15:00 – 17:55 15:00-17:55
In the final segment, the instructor solidifies the derivation for the 5th root loop. He writes out the algebraic step '(n^(1/5^k))^5 = n^(1/5^(k-1))' to verify the exponent reduction. He explicitly solves for 'k' using nested logarithms, writing 'log_5 log_5 n'. The analysis confirms that regardless of the root constant (whether square root or 5th root), the time complexity remains 'O(log log n)'. He points to the loop structure and the final complexity result on the screen, emphasizing that root-based decrements lead to doubly logarithmic time complexity. The lecture concludes with the general formula for this class of loops.
The lecture provides a rigorous mathematical derivation for determining the time complexity of loops with root-based iterator updates. The central method involves expressing the variable's value after k iterations as n^(1/r^k), where r is the root constant. By setting this expression greater than or equal to the termination threshold and applying logarithms, the instructor isolates k. The key takeaway is that taking roots repeatedly reduces the exponent exponentially, leading to a complexity of O(log log n). This is distinct from standard decrement loops (O(n)) or division-based loops (O(log n)). The visual evidence shows the instructor writing specific algebraic steps, such as '(n^(1/2))^(1/2) = n^(1/4)', and solving inequalities like 'n^(1/5^k) >= 5'. The consistent result across different root values confirms that the base of the logarithm does not affect the Big-O classification, only the constant factor.