Question

In: Computer Science

What sort of evaluation involves the evaluation of expressions in each part of a compound, conditional...

What sort of evaluation involves the evaluation of expressions in each part of a compound, conditional Boolean expression only as much as necessary to determine whether the expression is false? a. sequence b. sequential c. short-circuit d. smart

Solutions

Expert Solution

The answer to this problem clearly, is the option c) short - circuit evaluation method.

But let me first clearly explain about each and every option and why the other ones are incorrect.

The other options provided are not exactly considered as types of evaluation methods for any Boolean expression.

They have more to do with various other domains than with being a form of evaluation procedure for the Boolean expressions.

For example, a) sequence has more to do with the arrangement of any abstract data type in a given manner (one after the other in a cascaded format)

Whereas, b) sequential evaluation may be referred to as the evaluation of a particularly specific given Boolean expression in a sequential manner i.e. from LHS to RHS traversing over the expression and simultaneously evaluating whatever we keep on encountering at the same time (i.e. the generic process that is normally followed in most cases by the compilers and IDE to evaluate a given Boolean conditional expression.

And, d) smart is generally used in the domains of managerial roles and project / program management techniques as a form of goal - setting criterion. It follows the order of Specific, Manageable, Achievable (Attainable), Relevant / Realistic, and Time-Bound (which basically signifies the characteristics of how the goal should ideally be). Therefore, does not have much to do with being a procedure to evaluate the Boolean conditional expressions.

Now, finally coming back to the actual answer to your problem which is option c) Short - circuit :-

Short - circuit evaluation basically refers to a method of evaluating the Boolean conditional expressions. This method is made to be followed by the compiler during specific use-cases (I've attached the examples for the same down below for a clearer understanding)

It is also generally referred to as Minimal evaluation or McCarthy evaluation method. In this method, the expression being evaluated from the LHS to the RHS gets abruptly stopped mid-way itself as soon as the current condition being evaluated returns false (or becomes untrue).

These are generally used when checking for multiple conditions within the same if() or while() or do-while() statements which are compounded together by logical AND (&&) / logical OR (||). And as and when any one of these conditions negates (returns false), the evaluation stops then and there itself and the further remaining expression is not even evaluated anymore.

So, here you can generally bring the fact that the order in which you choose to write the conditional statements can make a huge difference to your own advantage as well. This is said to be a good programming practice.

For examples :-

1)

*compounded by AND && -> anyone is False, others are not evaluated at all*

(q != 0) && (a / q > 75)     // this expression will run even when q == 0 (because as soon as the 1st condition q != 0 becomes false, then the 2nd condition (dividing by 0) is not even evaluated)

(a / q > 75) && (q != 0)     // this expression will lead to a runtime arithmetic exception when q == 0 (because we start by checking the 1st condition (which is division by 0) and that itself crashes the program and leads to a runtime exceptional case)

2)

*compounded by OR || -> anyone is True, others are not evaluated at all*

if (p == q || r == s || t == u)    
{
    // Do some tasks
}

If 1st condition (p == q) becomes true, then other 2 are never evaluated at all. However, if p != q then 2nd condition (r == s) is checked and if this is true, 3rd condition is never evaluated and if even the 2nd condition is false, then the 3rd condition (t == u) would solely determine whether the if() block gets executed or not based on its own result.

3)

*compounded by OR || -> anyone is True, others are not evaluated at all*

if (isValid() || areComplements() || isTrue())     
{
    // Do something
}

Again similarly, if isValid() method returns true, then the other 2 methods are never evaluated and their outcome would matter only if the preceding methods return false and so on..

So hope you get the concept behind Short - Circuit Evaluation methods thoroughly.

And hence, the answer to the given problem will be option c) short - circuit


Related Solutions

Identify each of the following COMPOUND sentences as a conjunction, disjunction, conditional, or negation by writing...
Identify each of the following COMPOUND sentences as a conjunction, disjunction, conditional, or negation by writing the name on your answer sheet. 1. If it rains, Kellogg will not flood. 2. Either the legislature will pass the finance bill or they will run out of time, and they won’t run out of time. 3. Software is either reliable or cheap, but not both. 4. If one goes to the concert, one had better take earplugs and water. 5. It’s not...
Explain the results of the following expressions (you may want to show each step of evaluation):...
Explain the results of the following expressions (you may want to show each step of evaluation): • 4 + 5 * 6 + 7 / 8 • 4 + 5 * 6 < 7 / 8 • 4 + 5 > 6 && 7 < 8 • 1 && 0
Evaluation of an engineering project involves the following constraints ?
Evaluation of an engineering project involves the following constraints ?A) financial, environmental, social and political constraints.B) technical and financial constraints.C) technological and social constraints.D) time and money constraints. E) budget and time constraints.
Developing a critical perspective involves five stages: description, analysis, interpretation, evaluation, and engagement. Taking each of...
Developing a critical perspective involves five stages: description, analysis, interpretation, evaluation, and engagement. Taking each of these steps, describe briefly how they might inform a close viewing of myfavorite television show- HGTV.
use quick sort to sort the following array. show each pass and what the pivot is...
use quick sort to sort the following array. show each pass and what the pivot is during the pass. please explain why you are swapping positions. do not use a compiler. 30 5 40 11 20 9 15 2 60 25 80 3 73 35 4 75 20 6
Exercise 6: SOP & Pos Expressions Part 1: For each of the following functions, find all...
Exercise 6: SOP & Pos Expressions Part 1: For each of the following functions, find all of the minimum product of sums expressions: a. f(W,X,Y,Z) = SUMM(2,4,5,6,7,10,11,15) b. f(A,B,C,D) = SUMm(1,5,6,7,8,9,10,12,13,14,15) (1 SOP and 2 POS solutions) Part 2: Find a minimum two-level circuit (corresponding to sum of products expressions) using AND and one OR gate per function foreach of the following sets of functions. a. f(a,b,c,d) = SUMm(0, 1, 2, 3, 4, 5, 8, 10, 13) g(a,b,c,d) = SUMm(0,...
Part 1 For each of the following compound names, determine if the name is correct according...
Part 1 For each of the following compound names, determine if the name is correct according to the rules of naming outlined in Chapter 8. If the name is correct, state "correct". If the name is incorrect, state why it is incorrect and make an appropriate correction without adding or subtracting any atoms from the structure. Misspellings are not to be considered. 1. 5-methylheptane 2. 1-methylpentane 3. ethoxybutane or butyl ethyl ether (the longest carbon branch of the structure contains...
Write a python programA3) Lambda Expressions. Use lambda expression to sort the list ["democratic", "republican", "equal",...
Write a python programA3) Lambda Expressions. Use lambda expression to sort the list ["democratic", "republican", "equal", "python", "break", "two", "ruby"] by: a) the last 2 characters of each list item in reverse order b) create new list from list above where each item has only 3 characters and first one is capitalized. For example, the list item = "democratic" will transform into "Dem". Apply alphabetically sorting to the new list.  
Part 2: T-tests and Correlation For each question, conduct the appropriate statistical analysis. If some sort...
Part 2: T-tests and Correlation For each question, conduct the appropriate statistical analysis. If some sort of t-test is appropriate for the question, determine which type of t-test is appropriate. If you are going to conduct an independent samples t-test, determine whether you need to do the version of the test for equal variances or the version for unequal variances. For each test, state the null hypothesis, state the alternative hypothesis, state the type of test that you conducted, and...
java code Question 2: What are the type and value of each of the expressions below?...
java code Question 2: What are the type and value of each of the expressions below? int [] numbers = { 3, 6, 15, 22, 100, 0 }; double [] decimals = { 3.5, 4.5, 2.0, 2.0, 2.0 }; String [] words = {"alpha", "beta", "gamma"}; numbers[3] + numbers[2] decimals[2] - decimals[0] + numbers[4] words[1].charAt( numbers [0] ) numbers[4] * decimals[1] <= numbers[5] * numbers[0]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT