3 - Booleans and selection Flashcards

1
Q

How does the Conjunction operator work in the boolean ADT?

A

The Conjunction operator (AND) in the boolean ADT returns “true” if both operands are “true,” otherwise it returns “false.” It is left associative and has the second highest precedence among logical operators.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the behavior of the Disjunction operator in the boolean ADT?

A

The Disjunction operator (OR) in the boolean ADT returns “false” if both operands are “false,” otherwise it returns “true.” It is left associative and has the lowest precedence among logical operators.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does the Negation operator function in the boolean ADT?

A

The Negation operator (NOT) in the boolean ADT returns “false” if the operand is “true,” and it returns “true” if the operand is “false.” It is right associative and has the highest precedence among logical operators.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a decision problem, and how many possible outcomes does it typically have?

A

A decision problem is a type of problem that has only two possible outcomes, and it is best represented using a boolean data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What type of problem is a decision problem, and how is it related to classification?

A

A decision problem is a type of classification problem. It involves categorizing an input into one of two possible classes or outcomes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a problem definition in software development, and how is it typically written?

A

A problem definition in software development is the description of the problem that needs to be solved, usually written in plain English.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does a problem definition translate into a function definition in software development?

A

A problem definition translates into a function definition by specifying the function’s name, inputs, preconditions, outputs, and postconditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the key considerations when translating a problem description into a function definition?

A

When translating a problem description into a function definition, ensure that:

  • The function has a clear name.
  • All inputs mentioned in the problem description are accounted for as function inputs.
  • Outputs match the expected outcomes.
  • Postconditions clearly represent the desired conditions using boolean logic.
    • The postcondition may use brackets to explicitly convey the precedence remember in engish the precedence of conjunction and disjunction are opposite to boolean logic
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a problem instance in the context of software testing?

A

A problem instance in software testing is a specific, concrete problem or scenario that consists of input values satisfying the preconditions of a function definition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a test case, and how is it related to a problem instance?

A

A test case is a specific problem instance along with the expected output for that instance. It is usually represented as one row in a test table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is it important to consider edge cases when defining problem instances and test cases and what should we be testing?

A

It is important to consider edge cases because they represent extreme or boundary conditions of inputs. They include
* the lowest and highest possible values
* zero (boundary between negative and positive integers)
* 1 (lowest positive number)
* -1 (highest negative number)
* etc.,
*
* which can help uncover potential issues in the function’s behavior and off by one errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you calculate the total number of problem instances when you have multiple inputs with two possible values each?

A

To calculate the total number of problem instances when you have multiple inputs with two possible values each, you can use the formula:

Total Instances = (Number of Values for Input 1) x (Number of Values for Input 2) x (Number of Values for Input 3) x …

and so on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How is the complexity of an algorithm determined, and what is it based on?

A

The complexity of an algorithm is determined based on the English-written version of the algorithm. It involves analyzing the operations within the algorithm to understand its computational efficiency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are three key considerations when analyzing the complexity of an algorithm?

A

When analyzing the complexity of an algorithm, consider the following:

  • Identify and count the operations within the algorithm.
  • Assess the complexity of each operation (e.g., constant complexity).
  • Determine if the number of operations is fixed or variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the complexity of an algorithm that has constant complexity operations and a fixed number of operations?

A

An algorithm that has constant complexity operations and a fixed number of operations is considered to have constant complexity, denoted as Θ(1).

For this algorithm we would say:

The algorithm has complexity Θ(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the time complexity associated with comparison and logical operations?

A

Comparison and logical operations are considered to have constant time complexity, denoted as O(1).

17
Q

What is the precedence order of operators, from highest to lowest, including arithmetic, comparison, and logical operators?

A

The precedence order of operators, from highest to lowest, is as follows:

  1. Arithmetic operators
  2. Comparison operators
  3. Logical operators
18
Q

How are comparisons evaluated when they are on the same level, and what is this evaluation order called?

A

When comparisons are on the same level, they are evaluated from left to right. This evaluation order is called left-associative.

19
Q

What does a double inequality like “1 ≤ day ≤ 31” check for in a variable, and how can it be expressed differently?

A

A double inequality like “1 ≤ day ≤ 31” checks that the variable “day” lies within a certain interval. It can also be expressed as:

  • “1.1 ≤ day and day ≤ 31”
  • “0 < day < 32,”

although the latter may be less clear as it doesn’t explicitly express the bounds of the interval.

20
Q

What is a classification problem in the context of problem-solving?

A

A classification problem is a type of problem where all possible inputs can be categorized into distinct categories. The number of categories depends on the specific problem, and if there are only two categories, it is referred to as a decision problem.

21
Q

In the context of complexity analysis, what does “best-case complexity” refer to, and what does it indicate about an algorithm?

A

“Best-case complexity” refers to the minimum number of operations an algorithm performs under ideal conditions. It indicates the algorithm’s lower bound efficiency.

22
Q

What does “worst-case complexity” mean in complexity analysis, and what information does it provide about an algorithm?

A

“Worst-case complexity” represents the maximum number of operations an algorithm performs under the least favorable conditions. It provides insights into the algorithm’s upper bound efficiency and helps ensure it doesn’t perform exceptionally poorly for certain inputs.

23
Q

Why are best and worst case complexity analysis required and name a problem where we would likely need this

A

Best and worst case complexity is sometimes essential when we have an algorithm that can carry out a varying amount of operations

with best and worst we get a fuller understanding of the algorithms complexity for given inputs

a problem where we would likely require best and worst would be when the algorithm is a type of classification problem

24
Q

What conditions should be met for a sequence of selection statements in a classification algorithm to be considered correct?

A

For a classification algorithm to be correct, the conditions in the selection statements must be both:

  • mutually exclusive (non-overlapping)
  • comprehensive (covering all problem instances).

This ensures that each input falls into exactly one category

25
Q

What is the associativity of logical and comparison operators?

A

All logical and comparison operators are left-associative, except negation, which is right-associative.

26
Q

What is the precedence of operations, from highest to lowest

A

The precedence of operations, from highest to lowest, is:
1. arithmetic operations
2. comparisons
3. negations, conjunctions, disjunctions. (logic operations)