recategorized by
595 views
2 votes
2 votes

Consider the following pseudocode:

procedure HowManyDash(n)
 if n=0 then
  print '-'
 else if n=1 then
  print '-'
 else
  HowManyDash(n-1)
  HowManyDash(n-2)
 end if
end procedure

How many ‘-’ does HowManyDash$(10)$ print?

  1. $9$
  2. $10$
  3. $55$
  4. $89$
  5. $1024$
recategorized by

2 Answers

1 votes
1 votes

Answer $(D)$

Array index starts from $0$ and $A[i]$ stores the value of the function for index $i$ – 

1 1 2 3 5 8 13 21 34 55 89

$A[0] = A[1] = 1$

for rest of the table use, $A[i] = A[i-1] + A[i-2]$

Answer $= 89$

0 votes
0 votes
\[
    T(n)=
\begin{cases}
    1& \text{if } n= 0\\1& \text{if } n= 1\\
    T(n-1)+T(n-2),              & n\geq2, \text{otherwise}
\end{cases}
\]

$T(2)=T(1)+T(0)=1+1=2$

$T(3)=T(2)+T(1)=2+1=3$

$T(4)=T(3)+T(2)=3+2=5$

$T(5)=T(4)+T(3)=5+3=8$

$T(6)=T(5)+T(4)=8+5=13$

$T(7)=T(6)+T(5)=13+8=21$

$T(8)=T(7)+T(6)=21+13=34$

$T(9)=T(8)+T(7)=34+21=55$

$T(10)=T(9)+T(8)=55+34=89$

Option $(D)$ is correct.
Answer:

Related questions

844
views
1 answers
1 votes
soujanyareddy13 asked Mar 25, 2021
844 views
A matching in a graph is a set of edges such that no two edges in the set share a common vertex. Let $G$ be a graph on $n$ $\textit{vertices}$ in which there is a subset $M$ ... \right )^{m}$1-\left ( 1-p\left ( 1-p \right ) \right )^{m}$
961
views
2 answers
2 votes
soujanyareddy13 asked Mar 25, 2021
961 views
Consider the following statements about propositional formulas.$\left ( p\wedge q \right )\rightarrow r$ ... $\text{(ii)}$ is always false.
835
views
1 answers
1 votes
soujanyareddy13 asked Mar 25, 2021
835 views
Let $L$ be a singly-linked list $X$ and $Y$ be additional pointer variables such that $X$ points to the first element of $L$ and $Y$ points to the ... an element before the first element of $L$.Interchange the first two elements of $L$.
942
views
3 answers
2 votes
soujanyareddy13 asked Mar 25, 2021
942 views
What is the prefix expression corresponding to the expression:$\left ( \left ( 9+8 \right ) \ast 7+\left ( 6\ast \left ( 5+4 \right ) \right )\ast 3\right )+2?$You may assume ... \ast \: 6 + \:5432$+ \ast + \ast \: 987+ + \: 6 \ast \:5432$