The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
38 views

Consider the following program:

void A(int n){
    printf("*");
    if(n>1){
        A(n/4);
        A(n/4);
        A(n/4);
        A(n/4);
    }
}

Let $X$ be number of asterisks printed by above function when $n=1024.$ Then the value of $X$ will be ____________


How ans will be $\frac{4^{k+1}-1}{3}$ , where $k=5?$ .

asked in Programming by Veteran (111k points) | 38 views
+2

A(1024) = *, A(256), A(256), A(256), A(256) => A(N) = 4 * a(N / 4) +1 where A(1) = 1;

A(4) = 4*1 + 1 = 5, A(16) = 21, A(64) = 85, A(256) = 341, A(1024) = 1365 which is  (4^k+1 -1) /3 with k = 5

Please log in or register to answer this question.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,540 questions
54,099 answers
187,269 comments
71,006 users