A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
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...)
anonymous
 5 years ago
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...)

This Question is Closed

Owlfred
 5 years ago
Best ResponseYou've already chosen the best response.0Hoot! 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
 5 years ago
Best ResponseYou've already chosen the best response.0That 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
 5 years ago
Best ResponseYou've already chosen the best response.0I 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...

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0So, each evaluation would add, so I should consider it 3?

shadowfiend
 5 years ago
Best ResponseYou've already chosen the best response.2It 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
 5 years ago
Best ResponseYou've already chosen the best response.0Ah, yeah, thanks, the short circuit thing is good for efficiency but makes this evaluation more tricky :) I see... Thanks!
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.