Is any semantically correct and syntactically correct C program an algorithm? -
" algorithm defined finite sequence of operations whn executed accomplish specific task" definition. can syntactically , semantically right c programme algorithm?
my reply true, professor said reply false, did blockmate. counter illustration used was
while(1) { }
and
printf("%s","blahblah");
the infinite loop isn't semantically correct, while printf() accomplishes task algorithm. because can utilize loop , putchar() instead of printf();
so guys think right?
you tell professor improve stops splitting hair if doesn't know right terminology (so point, question doesn't create sense, anyway...).
an "algorithm" conceptually different program. reply to
is semantically right , syntactically right c programme algorithm?
is no, since programme not same algorithm - programme is... program. algorithm specific manifestation of solution of problem language-agnostic (i. e. can worded in quite generic way). programme language-dependent concrete implementation of algorithm (which is, in c, due "as-if" rule , compiler optimizations, need not same algorithm, it's required emulate it).
one more comment:
the infinite loop isn't semantically correct
well, is. of course of study 1 not solve halting problem, doesn't mean infinite loop "semantically incorrect". programme semantically wrong when else expect. unless expect programme else hanging when write while (1) { }
, there's no problem.
whether concept of infinite loop considered algorithm question. generally, instruction sequence never terminates not considered algorithm, , that's professor talking about. according wikipedia:
more precisely, algorithm effective method expressed finite list of well-defined instructions calculating function.
(emphasis mine)
c algorithm data-structures
No comments:
Post a Comment