Let n be a positive integer and f(n) = 0 if n = 1, and f(n) = f(⌊n/2⌋) + 1 if n > 1. What is f(25), and what does the function compute?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. 4, ⌊log₂ n⌋
Explanation
f(25) = f(12) + 1 = f(6) + 2 = f(3) + 3 = f(1) + 4 = 4. Halving until 1 counts the halvings, i.e. ⌊log₂ n⌋.
More Data Structures and Algorithms questions
- Given the FFT we can have ______ time procedure for multiplying two polynomials A(x) Q and B(x) of degree bound n where input and output re…
- Circuit satisfiability problem: given a Boolean combinational circuit of AND, OR and NOT gates, is it satisfiable (is there an input for wh…
- Given the expression (A + B * D)/(E − F) + G: 1. The prefix notation is + / + A * D B − E F G. 2. The prefix expression is the reverse of t…
- Match List I with List II
- Given the graph below one of the following edges cannot be added in that order to find a minimum spanning tree algorithm. Q I. a-b II. d-f…
- Statement 1: su Given a graph G=(V, E) in which each vertex v € V has an associated positive weight w(v), we can Q use linear programming t…