[XoL]
2013-09-16 01:07:24
Hey guys writing some psuedocode for a few algorithms and I appear to be stuck this is the assignment sheet

Here is what I got so far, mind you these may not be correct (Please help correct them if that is the case)

Here is what I got so far, mind you these may not be correct (Please help correct them if that is the case)
1)
theArray[n] ? A[j] + A[i]
for : ?0 to n-1 do
for j ?0 to i do
if j =/= i
then return theArray[n]
return n
end if
end for
end for
2) .
For int I ?0 j I<A.length i++
For j?0 J<B.length i++
For i?0 k<c.length j k++
If A[i] + B[i] + C[i] ?0
Return true
Else if A[i] + B[i] + C[j] ? 0
Return true
Else if A[i] + B[i] + C[k] ?0
Return true
Else if A[i] + B[j] + C[i] ?0
Return true
Else if A[i] + B[j] + C[j] ?0
Return true
Else if A[i] + B[j] + C[k] ?0
Return true
Else if A[i] + B[k] + C[i] ?0
Return true
Else if A[i] + B[k] + C[j] ?0
Return true
Else if A[i] + B[k] + C[k] ?0
Return true
Else if A[i] + B[i] + C[k] ?0
Return true
Else if A[i] + B[i] + C[k] ?0
Return true
Else if A[i] + B[i] + C[k] ?0
Return true
Etc. (Follows this pattern of checking EVERY possible combination)
Else if =/=0 then
End for
End for
End for
3)
lowerBound ? 0
upperBound ? n – 1
while(true)
line <- (lowerBound + upperBound)/2
if A[line] = searchKey then
return line
else if lowerBound > upperBound then
return n
else
if A[line] > searchKey then
upperBound ? line – 1
else
lowerBound ? line + 1
end if
end if
end while
4)
The Hailstone Series one
(No idea what to do here, something along these lines not in pseudo yet)
static int hailstone(int x){
int steps = 1;
highest = x ;
while (x!=1){
if (x>highest) highest = x;
if (x%2==0) x/=2;
else x=x*3+1;
steps++;
}
return steps;
}