Loops Time Complexity - 7

Duration: 18 min

This video lesson is available to enrolled students.

Return to /learn/AMCAT-PREPARATION/algorithms/time-complexity-analysis/iterative-loops-code/asset-loops-time-complexity-7 after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. Quantitative Ability: Percentage, Profit and Loss, Ratio and Proportion (Ratios), Average, Time and Work, Speed Time and Distance, Simple Interest and Compound Interest, Age Problems, Number System, Divisibility Rules, HCF LCM, Algebra, Permutation and Combination, Probability, Data Interpretation, Logarithm, Sequence and Series (Series), Powers and Exponents (Surds and Indices), Speed Mathematics and Basic Mathematics
  2. Logical Reasoning: Seating Arrangements, Puzzle Solving (Puzzles), Data Arrangement, Coding Decoding, Blood Relations, Directions (Direction Test), Ranking, Order and Sequence, Data Sufficiency, Venn Diagram, Inequality, Series (Number and Letter Series) (Numerical Relations and Reasoning), Logical Sequence Of Words, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Selection Decision Table (Decision Making), Analogy, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning)
  3. Verbal Ability: Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Subject Verb Agreement (Verb Noun Agreement), Tenses, Articles, Preposition, Conjunction, Modals, Active Passive Voice (Voice), Direct and Indirect Speech, Vocabulary, Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Sentence Completion (Fill in the blanks), Sentence Correction (Error Correction), Cloze Test (Cloze Passage), Facts, Inference and Judgements
  4. Programming Fundamentals (Technical): C Fundamentals
  5. Data Structures (Technical): Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
  6. Algorithms (Technical): Algorithm Analysis, Sorting Algorithms, Greedy Algorithms, Dynamic Programming, Minimum Spanning Trees, Shortest Path Algos, Time Complexity Analysis, Advanced Algorithms
  7. OOPs (Technical): Object Oriented Programming (OOPS)
  8. DBMS (Technical): Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, Relational Calculus, Transaction Management, Concurrency Control, Database Recovery, ORDBMS, Database Security & Authorization, Query Processing & Optimization, Enhanced Data Models, Data Warehousing & Mining, Big Data Systems, NoSQL
  9. SQL (Technical): SQL
  10. Operating Systems (Technical): Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Deadlock, Threads & Process Creation, Memory Management, Virtual Memory, Disc Scheduling, File Management, Windows OS, Linux OS, Security, Distributed Systems, Virtual Machines
  11. Computer Networks (Technical): Introduction to CN, Data Communication, 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, Network Security, Mobile Technology, Cloud Computing and IoT, Cyber and Info Security
  12. Software Engineering (Technical): Fundamentals of Software Engineering, Software Requirements and Quality Assurance, Software Design, Estimation and Metrics, Software Testing, Software Maintenance and Configuration Management
  13. Coding/Automata Round: Coding Questions by Yash Sir, C Programming by Yash Sir, Programming in C++, Java, Python for Placements by Yash Sir, Pseudo Codes
  14. Personality / Behavioral Assessment: Behavioral Assessment (Behavioral Competency Profiling) (Psychometric Test)
  15. Writing Assessment: English Writing Ability
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

  1. 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. 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.

  3. 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.

  4. 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)'.

  5. 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.

Loading lesson…