October 12th, 2009, 12:27 PM

Basic Algorithm help please ?
Hey guys,
I'm having some problems writing out basic algorithms and was hoping some of you could (please) give me a helping hand ?
We have been assigned this question :
"Write algorithms which return true or false for the following tasks:
(i) Given as input an object x and a set S, return true if x ∈ S, and false if x ∉S
(ii) Given as input a set S and another set T, return true if S ⊆ T, and false if S ⊆ T
You can assume a command getNextElement(S) which returns the next element of a set S (i.e. the first element of S that has not been given to you before). So you can have a line in your algorithm which says, for example, y ← getNextElement(S). So if you had a set S = {1,2,3}, and you had the following lines in your algorithm
y ← getNextElement(S)
z ← getNextElement(S)
then y would have the value 1, and z would have the value 2. If S has no more elements, then getNextElement(S) returns the special value NULL."
Now, for part one, I am thinking an answer could be :
Input : Object X and set S.
If x ∈ S
Return a value of true.
If x ∉ S
Return a value of false.
I have a feeling I'm missing out on some basic stuff, but my lecturer has decided to just blaze on ahead with giving us examples, rather than explaining. Which is fair enough, its probably the best way to learn, its just that the course is continuous assessment and in order to qualify for my doctorate, I need a first class honors ! Hence I need to buck up, and quickly !
I have absolutely no idea how to tackle the second problem either.
Can anyone please help me out ?
Thanks a lot.
October 12th, 2009, 02:42 PM

Originally Posted by Reapersoul
Input : Object X and set S.
If x ∈ S
Return a value of true.
If x ∉ S
Return a value of false.
That's... not an algorithm. An algorithm is a stepbystep process you can follow to do something: what you've given doesn't describe how to do a ∈ or ∉.
If I gave you a bag of marbles and asked you if there was a blue and green striped marble in the bag, how would you go about finding the answer?
For part two, imagine I gave you two bags of marbles and asked if the second bag had an identical copy of all the marbles in the first bag. Hint: you'll be using the answer to part (i).
Comments on this post
October 13th, 2009, 10:47 PM

Originally Posted by Reapersoul
the course is continuous assessment and in order to qualify for my doctorate, I need a first class honors ! Hence I need to buck up, and quickly !
Please tell me your not a graduate student. If you are working on a doctorate in information or computer science, this should already be old hat for you.
Look up Donald Knuth. Also try googling algorithm. The Wikipedia has some coverage as well.
Algorithm for getting to work on time:
1. Set alarm to 8am.
2. Sleep until alarm goes off.
3. Kill the bloody alarm!
4. Have a quicky (if she's in the mood).
5. If quicky, get dressed and run out the door, else have breakfast first.
6. Drive car to office, taking shortcuts and avoid traffic jams. Don't speed! Cops take forever to write tickets.
7. Don't chat up the cute secretary on the way in the door. Race to your office, fire up your computer and broadcast a "good morning" message to coworkers so everyone knows your their on time.
I no longer wish to be associated with this site.