Bit Manipulation - Power of FourWhat is the time complexity of the brute force iterative division approach to check if a number n is a power of four?AO(1) because division is constant timeBO(n) because it checks every number up to nCO(log log n) because division by 4 reduces n faster than by 2DO(log n) because the number is divided by 4 each iterationCheck Answer
Step-by-Step SolutionSolution:Step 1: Analyze the loop iterationsEach iteration divides n by 4, so the number of iterations is proportional to log base 4 of n.Step 2: Express complexity in Big-O notationSince log base 4 of n is O(log n), the time complexity is O(log n).Final Answer:Option D -> Option DQuick Check:Loop runs ~log4(n) times, which is O(log n) [OK]Quick Trick: Dividing by 4 reduces n logarithmically -> O(log n)Common Mistakes:MISTAKESConfusing division steps as O(1)Mistaking log log n complexityTrap Explanation:PITFALLOption D looks plausible since dividing by 4 is faster than 2, but log base change is constant factor, so complexity remains O(log n).Interviewer Note:CONTEXTTests understanding of logarithmic time complexity and common misconceptions about division steps.
Master "Power of Four" in Bit Manipulation3 interactive learning modes - each teaches the same concept differentlyTry ItSolutionTrace
More Bit Manipulation Quizzes Counting Bits (0 to N) - Counting Bits (0 to N) - Quiz 15hard Counting Bits (0 to N) - Counting Bits (0 to N) - Quiz 14medium Generate All Permutations Using Bitmask DP - Generate All Permutations Using Bitmask DP - Quiz 5medium Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 15hard Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 6medium Number of 1 Bits (Hamming Weight) - Number of 1 Bits (Hamming Weight) - Quiz 3easy Reverse Bits - Reverse Bits - Quiz 14medium Single Number II (Three Copies) - Single Number II (Three Copies) - Quiz 13medium Subsets Using Bitmask - Subsets Using Bitmask - Quiz 5medium Sum of Two Integers Without + Operator - Sum of Two Integers Without + Operator - Quiz 10hard