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