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 Find Two Missing Numbers - Find Two Missing Numbers - Quiz 14medium Maximum XOR of Two Numbers - Maximum XOR of Two Numbers - Quiz 8hard Reverse Bits - Reverse Bits - Quiz 7medium Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 13medium Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 4medium Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 15hard Single Number (XOR Self-Cancellation) - Single Number (XOR Self-Cancellation) - Quiz 10hard Single Number II (Three Copies) - Single Number II (Three Copies) - Quiz 7medium Single Number III (Two Singles) - Single Number III (Two Singles) - Quiz 12easy UTF-8 Validation - UTF-8 Validation - Quiz 3easy