algorithm?

  • Thread starter Thread starter kathy
  • Start date Start date
if you want that to be recursive for 2^n then make s[0] = 1 otherwise its
2^(n+1)
 
s[n] is (2^n) + 1
series looks like: 2, 3, 5, 9, 17, 33, 65, 129, ...

What's the point?
 
GC said:
s[n]=2^(n+1)-1

No it doesn't.

s[0]=2
s[1]=3
s[2]=5
s[3]=9
s[4]=17
s[5]=33

Your sequence would go:
s[0]=1 // Disagreement even on the axioms!
s[1]=3
s[2]=7
s[3]=15
s[4]=31
s[5]=63
 
Ok, I am being dumb today. Tomorrow I will be smart again.


Jon Skeet said:
GC said:
s[n]=2^(n+1)-1

No it doesn't.

s[0]=2
s[1]=3
s[2]=5
s[3]=9
s[4]=17
s[5]=33

Your sequence would go:
s[0]=1 // Disagreement even on the axioms!
s[1]=3
s[2]=7
s[3]=15
s[4]=31
s[5]=63
 
Hi Kathy, Jon,

You've got me puzzled. My question is: What's this got to do with
<anything> ?

Regards,
Fergus
 
Hi,

s[n] = a big error 'cause when n=0, (n-1) will be an invalid index into s.
Unless of course you reorder your statements and correctly setup your loop.

Is this a programming group or what?

Pete
 
Given you say algorithm maybe your assignment expects an answer something
along the lines of,

function int S(int n)
{
if (n==0)
return 2;
else
return 2 * S(n - 1) - 1;
}

Why don't you just tell us exactly what the questions are and we'll get you
an A+.
 
s[n] = (2^n) + 1;
-----Original Message-----
Given you say algorithm maybe your assignment expects an answer something
along the lines of,

function int S(int n)
{
if (n==0)
return 2;
else
return 2 * S(n - 1) - 1;
}

Why don't you just tell us exactly what the questions are and we'll get you
an A+.


kathy said:
correction:
if:
1. s[n]=2*S[n-1]-1
2. s[0]=2
then:
s[n]=?


.
 
Back
Top