Specification and Abstraction: book back answers
17 solved questions from the end of this chapter, Class 11 Computer Science, Tamil Nadu State Board. Each answer is checked against the textbook, and you can open the page that proves it.
← Notes and quiz for Specification and AbstractionSECTION – A Choose the correct answer
Which of the following activities is algorithmic in nature?
- (a) Assemble a bicycle.
- (b) Describe a bicycle.
- (c) Label the parts of a bicycle.
- (d) Explain how a bicycle works.
Try it, then show the answerAnswer
(a) Assemble a bicycle.
Assembling a bicycle involves carrying out a task through a sequence of instructions.
From the book: “An algorithm is a sequence of instructions to accomplish a task or solve a problem.”
Omitting details inessential to the task and representing only the essential features of the task is known as
- (a) specification
- (b) abstraction
- (c) composition
- (d) decomposition
Try it, then show the answerAnswer
(b) abstraction
Abstraction hides or ignores irrelevant details and models a problem using its essential features.
From the book: “Abstraction is the process of ignoring or hiding irrelevant details and modeling a problem only by its essential features.”
Stating the input property and the input-output relation a problem is known
- (a) specification
- (b) statement
- (c) algorithm
- (d) definition
Try it, then show the answerAnswer
(a) specification
The specification states the property of the inputs and the desired relation between input and output.
From the book: “An algorithm is specified by the properties of the given input and the relation between the input and the desired output.”
Ensuring the input-output relation is
- (a) the responsibility of the algorithm and the right of the user.
- (b) the responsibility of the user and the right of the algorithm.
- (c) the responsibility of the algorithm but not the right of the user.
- (d) the responsibility of both the user and the algorithm.
Try it, then show the answerAnswer
(a) the responsibility of the algorithm and the right of the user.
The designer is responsible for the desired input-output relation, and the user has the right to expect it.
From the book: “The desired input-output relation is the responsibility of the designer and the right of the user.”
If i = 5 before the assignment i := i-1 after the assignment, the value of i is
- (a) 5
- (b) 4
- (c) 3
- (d) 2
Try it, then show the answerAnswer
(b) 4
The assignment evaluates i − 1 using the current value 5 and stores 4 in i.
From the book: “The assignment m := m + 3 evaluates the expression m + 3 using the current value of m.”
SECTION-B
Define an algorithm.
Try it, then show the answerAnswer
An algorithm is a step-by-step sequence of statements intended to solve a problem.
When executed with input data, it generates a computational process and ends with output data satisfying the specified relation.
From the book: “An algorithm is a step by step sequence of statements intended to solve a problem.”
Distinguish between an algorithm and a process.
Try it, then show the answerAnswer
An algorithm is a sequence of instructions or statements intended to solve a problem. A process is what evolves when those instructions are executed.
The algorithm describes the steps; its execution produces the process that accomplishes the task.
From the book: “When the instructions are executed, a process evolves, which accomplishes the intended task or solves the given problem.”
Initially, farmer, goat, grass, wolf = L, L, L, L and the farmer crosses the river with goat. Model the action with an assignment statement.
Try it, then show the answerAnswer
farmer, goat, grass, wolf := R, R, L, L
The farmer and goat change to the right side, while the grass and wolf remain on the left side.
From the book: “A value of L means "at the left side". A value of R means "at the right side".”
Specify a function to find the minimum of two numbers.
Try it, then show the answerAnswer
minimum(a, b) -- inputs: a and b are real numbers. -- outputs: m is a real number such that m ≤ a and m ≤ b, and (m = a or m = b).
The output is specified as a number no greater than either input and equal to at least one of them.
From the book: “Specification format: We can write the specification in a standard three part format:”
If √2 = 1.414, and the square_root() function returns -1.414, does it violate the following specification? -- square_root (x) -- inputs: x is a real number , x ≥ 0 -- outputs: y is a real number such that y2=x
Try it, then show the answerAnswer
No. It does not violate the specification.
The specification requires y to be a real number whose square is x. It does not require the output to be the positive square root.
From the book: “The output could be the negative square root of the given number. The specification did not commit that the output is the positive square root.”
When do you say that a problem is algorithmic in nature?
Try it, then show the answerAnswer
A problem is algorithmic in nature when its solution involves the construction of an algorithm.
An algorithmic problem may require constructing an algorithm, or reasoning about properties of a provided algorithm.
From the book: “We usually say that a problem is algorithmic in nature when its solution involves the construction of an algorithm.”
What is the format of the specification of an algorithm?
Try it, then show the answerAnswer
The specification has three parts: the algorithm name and inputs, the property of the inputs, and the desired input-output relation.
The input property is written as a comment beginning with “inputs:” and the desired relation as a comment beginning with “outputs:”.
From the book: “The name of the algorithm and the inputs. Input: the property of the inputs. Output: the desired input-output relation.”
What is abstraction?
Try it, then show the answerAnswer
Abstraction is the process of ignoring or hiding irrelevant details and modeling a problem only by its essential features.
It reduces unnecessary complexity by retaining the details needed for the task.
From the book: “Abstraction is the process of ignoring or hiding irrelevant details and modeling a problem only by its essential features.”
How is state represented in algorithms?
Try it, then show the answerAnswer
The state of a process is represented by a set of variables in an algorithm. The state at any point is the values of those variables at that point.
Changes in variable values represent changes in the process state.
From the book: “The state of a process can be represented by a set of variables in an algorithm.”
What is the form and meaning of assignment statement?
Try it, then show the answerAnswer
An assignment statement has the form variable := value. It stores the value on the right side in the variable on the left side.
If the right side is an expression, it is evaluated first; assignment can replace the variable’s old value.
From the book: “variable := value When this assignment is executed, the value on the right side is stored in the variable on the left side.”
Explain in detail
Write the specification of an algorithm hypotenuse whose inputs are the lengths of the two shorter sides of a right angled triangle, and the output is the length of the third side.
Try it, then show the answerAnswer
The specification of an algorithm states its name and inputs, the properties required of the inputs, and the desired relation between the inputs and outputs.
- Algorithm name and inputs: Name the algorithm hypotenuse and take the lengths of the two shorter sides as inputs, say a and b.
- Output: Let c be the output, representing the length of the third side.
- Input-output relation: The output c must be related to the two input lengths by the right-triangle relation c² = a² + b².
- Specification format: Write the algorithm name with its inputs, followed by comments stating the input property and the desired output relation.
Example: hypotenuse(a, b) -- inputs: a and b are the lengths of the two shorter sides of a right angled triangle -- outputs: c is the length of the third side such that c² = a² + b²
This specification defines the required inputs and the relation that the output must satisfy.
From the book: “To design an algorithm for solving a problem, we should know the properties of the given input and the properties of the desired output.”
Exchange the contents: Given two glasses marked A and B. Glass A is full of apple drink and glass B is full of grape drink. For exchanging the contents of glasses A and B, represent the state by suitable variables, and write the specification of the algorithm.
Try it, then show the answerAnswer
The contents of the two glasses can be represented by variables. The specification states the initial contents and the desired contents after exchange.
- Variables: Let A and B represent the contents of glasses A and B, respectively.
- Initial state: Initially, glass A contains apple drink and glass B contains grape drink.
- Final state: After the exchange, glass A should contain grape drink and glass B should contain apple drink.
- Algorithm name and inputs: Name the algorithm exchange_contents, with A and B as its inputs.
- Input property: Specify that A initially contains apple drink and B initially contains grape drink.
- Output relation: Specify that the final contents are exchanged: A contains grape drink and B contains apple drink.
Example: exchange_contents(A, B) -- inputs: A = apple drink and B = grape drink -- outputs: A = grape drink and B = apple drink
Thus, the specification represents the initial and final states required to exchange the contents.
From the book: “The values of the variables when the algorithm starts is known as the initial state, and the values of the variables when the algorithm finishes is known as the final state.”