anonymous
  • anonymous
Hi! I am trying to work out efficiency in a program by adding a variable to each command which counts it. Does anyone know whether a command such as: while (x%2 == 0 or x%3 == 0 or x%5 ==): would count as 1 command or 3? (The language is Python but I imagine common semantics in all...)
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Owlfred
  • Owlfred
Hoot! You just asked your first question! Hang tight while I find people to answer it for you. You can thank people who give you good answers by clicking the 'Good Answer' button on the right!
rsmith6559
  • rsmith6559
That is a compound conditional. Although there are 3 evaluations, if would be one statement. Generally, efficiency in programming is done with "Big O notation".
anonymous
  • anonymous
I have no idea about big o notation, I'm still quite new. Just wanted to give it a go, as I just learnt about efficiency at all...

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
So, each evaluation would add, so I should consider it 3?
shadowfiend
  • shadowfiend
It really depends heh. Typically the way conditionals like this are implemented, it could be 1 to 3 operations. Traditionally, conditional logic `short circuits'. What that means is that if, above, x % 2 != 0, then the loop will quit without evaluating the other two conditions. This is also true in an if statement. If x % 2 == 0 but x % 3 != 0, then two evaluations will occur. It's fair to count it as 3 if you just want to count how many operations are happening, of course. Particularly in the body of the loop, if the loop has run, all three of the conditions have been checked. If the loop ends, one or two of the conditions may have been skipped.
anonymous
  • anonymous
Ah, yeah, thanks, the short circuit thing is good for efficiency but makes this evaluation more tricky :) I see... Thanks!

Looking for something else?

Not the answer you are looking for? Search for more explanations.