0

No, This is not an assignment


Okay, so I got an exam about algorithm... it has 5 questions on it.

Here's one of the questions

"write an algorithm of the first set of Fibonacci sequence"

I wrote

Int x = 0, y = 1, temp = 0;
for(int i = 0; i < 9; i++)
{
temp = x;
x = y;
y = y + temp;
print(y);
}

Then I got a Zero Score

I asked my professor why and then he said

It's not an algorithm. Algorithm should be:

1. Independent on a programming language. it should be applicable to all programming language. What I did is not applicable to Visual Basic or .Net

2. Should not contain any data types. That means there is no Int or string

3. Does not contain any syntax


So the question is, is he right?? I thought algorithms can just be any kind of programming language or pseudo-code?? Or does it really matter???


It's soo unfair, I should have gotten a perfect score =/

10
Contributors
25
Replies
28
Views
5 Years
Discussion Span
Last Post by reactivated
Featured Replies
  • Well did he specify usage and give you an example of a this ambiguous pseudo-code, on the assignment or any time during the quarter? "It's soo unfair, I should have gotten a perfect score =/ " I read that in the voice of a pouting eight year old girl. Read More

2

Well did he specify usage and give you an example of a this ambiguous pseudo-code, on the assignment or any time during the quarter?

"It's soo unfair, I should have gotten a perfect score =/ "

I read that in the voice of a pouting eight year old girl.

Votes + Comments
good comment
0

The professor is right. An algorithm is a generic process. The line between pseudocode and real code can be a blurry one, but I think you crossed it. I doubt I would have given you a zero, but I wouldn't have given you full credit either. Presumably an algorithm would not even necessitate a computer program. A good litmus test might be to write up a set of instructions that someone who read it BEFORE computers were invented could understand and write it on paper. Think math/combinatorics rather than programming. That might be overkill. Just chalk it up as a learning experience and move on.

0

A pseudocode example of the QuickSort sorting algorithm.

function quicksort('array')
      create empty lists 'less' and 'greater'
      if length('array') ≤ 1
          return 'array'  // an array of zero or one elements is already sorted
      select and remove a pivot value 'pivot' from 'array'
      for each 'x' in 'array'
          if 'x' ≤ 'pivot' then append 'x' to 'less'
          else append 'x' to 'greater'
      return concatenate(quicksort('less'), 'pivot', quicksort('greater'))

1. The statement 'Independent of a programming language' doesn't mean that you should be able to paste the pseudocode into code for any langauge and it will compile without syntax errors. It simply means that it should convey the general ideas of the algorithm in a way that does not depend a particular programming language's syntax.

2. Notice that this example doesn't include any data types. Granted, some of these variables have assumed type. For example, it is assumed that x is a comparable data type, but it isn't explicitly stated whether it is an int, double, float etc. However, data structures like lists and trees can and usually must be used in an algorithm's pseudocode, but that data structure's implementation is left for the programmer to decide/discover.

3. The pseudocode example doesn't contain any syntax -- no brackets, parentheses or semicolons are present. This is an extension of requirement 1. An algorithm's psuedocode should never rely on a particular programming language's syntax or design philosophy.

I hope that helps!

0

OK thanks guys, I just thought I was right because he poorly explained to us what's the difference between algorithms and programming code.

0

The professor is right. An algorithm is a generic process. The line between pseudocode and real code can be a blurry one, but I think you crossed it. I doubt I would have given you a zero, but I wouldn't have given you full credit either. Presumably an algorithm would not even necessitate a computer program. A good litmus test might be to write up a set of instructions that someone who read it BEFORE computers were invented could understand and write it on paper. Think math/combinatorics rather than programming. That might be overkill. Just chalk it up as a learning experience and move on.

I even asked some of professor friends and they said it will never get a Zero because as long as the logic is correct, that will be fine

0

A pseudocode example of the QuickSort sorting algorithm.

function quicksort('array')
      create empty lists 'less' and 'greater'
      if length('array') ≤ 1
          return 'array'  // an array of zero or one elements is already sorted
      select and remove a pivot value 'pivot' from 'array'
      for each 'x' in 'array'
          if 'x' ≤ 'pivot' then append 'x' to 'less'
          else append 'x' to 'greater'
      return concatenate(quicksort('less'), 'pivot', quicksort('greater'))

1. The statement 'Independent of a programming language' doesn't mean that you should be able to paste the pseudocode into code for any langauge and it will compile without syntax errors. It simply means that it should convey the general ideas of the algorithm in a way that does not depend a particular programming language's syntax.


2. Notice that this example doesn't include any data types. Granted, some of these variables have assumed type. For example, it is assumed that x is a comparable data type, but it isn't explicitly stated whether it is an int, double, float etc. However, data structures like lists and trees can and usually must be used in an algorithm's pseudocode, but that data structure's implementation is left for the programmer to decide/discover.

3. The pseudocode example doesn't contain any syntax -- no brackets, parentheses or semicolons are present. This is an extension of requirement 1. An algorithm's psuedocode should never rely on a particular programming language's syntax or design philosophy.

I hope that helps!

Well the example you gave will still be wrong to him. Because you used a function. he said I should never use a function in an algorithm pseudocode. I can not also use some boolean return values thus, you said in number 2 that its for the programmer to discover it. that means using variable isn't incorrect.

0

It's not an algorithm. Algorithm should be:

1. Independent on a programming language. it should be applicable to all programming language. What I did is not applicable to Visual Basic or .Net

2. Should not contain any data types. That means there is no Int or string

3. Does not contain any syntax

Darn, so all of those algorithms I've written over the years haven't really been algorithms because they fit none of those requirements. :icon_rolleyes:

So the question is, is he right??

He's wrong in every way except being in a position to dictate terms, in which case he's right, because that position is dominant. What you need to do at this point is get him to spell out exactly what his idea for the representation of an algorithm is, with as many examples as possible, because his "rules" are both arbitrary and vague.

I thought algorithms can just be any kind of programming language or pseudo-code?? Or does it really matter???

An algorithm is a set of instructions for solving a problem, nothing more, nothing less. This is naturally an abstract concept, and there's no standard way of representing algorithms in a general way. Pseudocode is common, but there are no rules for pseudocode other than logical precision.

I should have gotten a perfect score =/

I don't know about perfect, but I would have given you a grade closer to perfect than to zero.

0

He's wrong in every way except being in a position to dictate terms, in which case he's right, because that position is dominant.

The crux of the matter. It's just like when you get harrassed by a cop who is in the wrong. You have to make a quick decision how to proceed. Right or wrong, you can only lose any fight you get into (in the LONG run, if there's an abuse of power and you can prove it), you might or might not win. You want the 'A', so find out what it takes for him to give you an 'A'. Whether he has stupid grading criteria is sort of irrelevant.


>> I just thought I was right because he poorly explained to us what's the difference between algorithms and programming code.

Well, if he poorly explained it, then HE'S wrong even if you are wrong. It's sort of an axiom that a professor who doesn't explain things well is wrong. But see the earlier point. You're the one with a zero, not him. :icon_cheesygrin: So find out what he wants and give it to him.

0

I guess you had so much confidence and maybe you already knew the code so you were fast to write. He asked for an algorithm and not the code. Am sure that any professor that asks a student for a code will also specify the language he wants it to be written in. In this case, there was no language specified.

0

You did not write an algorithm, you wrote a program. There is value in being able to write an algorithm that follows those axioms.

If you want to share your algorithm with other people who are not programmers or are not familiar with your preferred language then you will need to turn it into something much more clear and simple that program code. Since more and more work is collaborative and multi-disciplinary being able to communicate your work with non-experts.

I would have penalized your answer but not to the extent your professor did.

0

As a self-taught guy with a non-tech background, I found it difficult to grasp the difference between the code and algorithm to begin with.

Your saying that the algorithm has to be language-independent. I get that - that makes sense. It should be like a set of real-world instructions? Did I get that right?

If so, at what point do you allow abbreviations, general programming terms and technical (e.g. mathematical) terminology to be used. E.g. INT, ARRAY, loops using () or {}?

I understood the original code, although I'm not sure in which language (if any) it was written, but the suggested 'algorithm' (Purkinje - sorry no offence) confused the hell out of me.

2

To be fair Purkinje's example is a much more complicated problem than the original.

An algorithm for the Fibonacci sequence could be something like:

last_term = 0
current_term = 1
For each term
next_term = current_term + last_term
last_term = current_term
current_term = next_term

Votes + Comments
clarified :)
0

Cheers, Agilemind, that was more along the lines of what I was expecting.
Sorry, don't want to go off-piste and it might sound like a terribly naïve question but:

How important are algorithms for everyday programmers? Are they for deciding which languages would best suit the particular remit, or for explaining a process to a group of programmers (laymen aside)? Are they mainly for quickly sketching out ideas or for educational purposes, e.g. for explaining particular approaches to a problem?

0

IMO, If the problem is big and complicated an algorithm can be a useful first step to figure out an approach that will work before worrying about how to turn it into program code. In which case the algorithm can start out very rough and become more and more detailed until all that is left is turning it into code, no thinking/decision making required.

Also if you have a hierarchy of programmers with more/less experience you might have more senior programmers working out algorithms and giving them to less experienced programmers to turn into code.

0

I understood the original code, although I'm not sure in which language (if any) it was written, but the suggested 'algorithm' (Purkinje - sorry no offence) confused the hell out of me.

I didn't mean to confuse anyone by posting that, and it probably wasn't a good idea to post psuedocode I found on Wikipeida for a moderately complex sorting algorithm. So, for that, I apologize.

Edited by Purkinje: n/a

0

The Algorithm:
Given the first two terms are 0 then 1, each successive term is the sum of the previous two terms.

0

How important are algorithms for everyday programmers?

Algorithms are very important actually. They are more like a blueprint for a house. Without them, you keep writing and deleting codes as you would with building and destroying structures

0

How important are algorithms for everyday programmers?

Let's see, without algorithms we wouldn't be able to write programs, so I'd say they're critically important. If you throw out all of the mumbo jumbo, programming is the craft of manipulating data structures with algorithms.

IMO, If the problem is big and complicated an algorithm can be a useful first step to figure out an approach that will work before worrying about how to turn it into program code. In which case the algorithm can start out very rough and become more and more detailed until all that is left is turning it into code, no thinking/decision making required.

You're talking about pseudocode. That's not the same thing as an algorithm. Yikes, I can only imagine what you folks are learning in school these days. :icon_rolleyes:

0

You're talking about pseudocode. That's not the same thing as an algorithm. Yikes, I can only imagine what you folks are learning in school these days.

Maybe this would help out:
Algorithm is a set of instructions or steps applied to a problem with a view to solve it. In simple words we can say that algorithm is method of solving a problem. Pseudo code describes algorithm itself. Pseudo code makes no use of syntax of a specified programming language. So, it cannot be executed in a computer. But it contains almost the same detail as a programming language does and has the same structure.

0

Thanks guys, I seem to have opened a can of worms, though...
So an algorithm describes an 'approach' or a 'process', would that be close to a layman's (my) understanding of it?

0

OKAY, SO SERIOUSLY GUYS I'M CONFUSED.


But I know now that what I've done is not an algorithm. But it still not clear to me what is an Algorithm O_O

0

As I said

The Algorithm:
Given the first two terms are 0 then 1, each successive term is the sum of the previous two terms.

That fits the definition and has none of the stuff the instructor claims doesn't belong. And you can use it to program the series.

0

In mathematics and computer science, an algorithm is
> an effective method expressed as a finite list
> of well-defined instructions
> for calculating a function.

In simple words an algorithm is a step-by-step procedure for calculations.

0

Darn, so all of those algorithms I've written over the years haven't really been algorithms because they fit none of those requirements. :icon_rolleyes:

He's wrong in every way except being in a position to dictate terms, in which case he's right, because that position is dominant. What you need to do at this point is get him to spell out exactly what his idea for the representation of an algorithm is, with as many examples as possible, because his "rules" are both arbitrary and vague.

Think of him as your boss. You did not deliver what the boss wanted, thus you did not get 'paid.'

An algorithm is a set of instructions for solving a problem, nothing more, nothing less. This is naturally an abstract concept, and there's no standard way of representing algorithms in a general way. Pseudocode is common, but there are no rules for pseudocode other than logical precision.

Amke it language independant, use the example above.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.