Bit Manipulation - Power of FourWhat is the worst-case time complexity of repeatedly dividing a positive integer n by 4 until it becomes 1 or not divisible by 4?AO(log n base 2)BO(n)CO(1)DO(log n base 4)Check Answer
Step-by-Step SolutionSolution:Step 1: Understand the division processEach division reduces n by a factor of 4.Step 2: Calculate number of divisionsThe number of divisions until n becomes 1 is the exponent k such that n = 4^k, which is log base 4 of n.Final Answer:Option D -> Option DQuick Check:Repeated division by 4 reduces n exponentially [OK]Quick Trick: Repeated division by 4 takes O(log base 4 n) steps [OK]Common Mistakes:MISTAKESConfusing log base 4 with log base 2Assuming constant time due to divisionMistaking linear time complexityTrap Explanation:PITFALLOption D looks plausible because log base 2 is common, but division by 4 means log base 4.Interviewer Note:CONTEXTTests understanding of logarithmic time complexity in iterative division.
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