P. 1
Exercise 1 Simple Algorithms

Exercise 1 Simple Algorithms

|Views: 439|Likes:
Published by Yeswandh Bharath

More info:

Published by: Yeswandh Bharath on Jun 21, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/21/2015

pdf

text

original

Date: 16.06.

2011

Write algorithms to accomplish the following tasks:

1. Given n Boolean variables x1, x2, …, and xn, we wish to print all possible combinations of truth values they can assume. For instance, if n=2, there are four possibilities: true, true; true, false; false, true: false, false. 2. Devise an algorithm that inputs three integers and outputs them in non decreasing order. 3. Present an algorithm that searches an unsorted array a[1:n] for the element ‘x’. If ‘x’ occurs, then return a position in the array; else return zero. 4. The factorial function n! has value 1 when n ≤ 1 and value n * (n-1)! when n > 1 . Write both a recursive and an iterative algorithm to compute n!. 5. The Fibonacci numbers are defined as f 0 = 0, f1 = 1, and fi = fi −1 + fi − 2 for i > 1. Write both a recursive and an iterative algorithm to compute f i .

s

m

h

t

i

r

o

g

l

A

e

l

p

m

i

S

-

1

e

s

i

c

r

e

x

E

then the powerset (S) = {(a). b. c). determine whether n is the sum of all of its divisors.c). (a. and t divides n. (b. that is whether n is the sum of all t such that 1 ≤ t ≤ n . (b). 7. (c). (a. If S is a set of n elements. if S= ( a. For example.6. (a. Give an algorithm to solve the following problem: Given n. b.c). the powerset of S is the set of all possible subs ets of S. } .b). c). a positive integer.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->