TN State Board 11th Computer Science Important Questions Chapter 6 Specification and Abstraction
Question 1.
What is a process?
Answer:
A process evolves, which accpmplishes the intended task or solves the given problem.
Question 2.
What are variables?
Answer:
Variables are named boxes for storing data. When we do operations on data, we need to store the results in variables. The data stored in a variable is also known as the value of the variable. We can store a value in a variable or change the value of variable, using an assignment statement.
Question 3.
Define function.
Answer:
A function is like a sub algorithm. It takes an input and produces an output, satisfying a desired input output relation.
Question 4.
What is meant by composition?
Answer:
An algorithm is composed of assignment and control flow statements. A control flow statement tests a condition of the state and depending on the value of the condition, decides the next statement to be executed.
Question 5.
How will you abstracts the specification of the problem?
Answer:
Specification abstracts a problem by the properties of the inputs and the desired input-output relation. We recognize the properties essential for solving the problem, and ignore the unnecessary details.
Question 6.
Write the specification of an algorithm to find the square root of a number.
Answer:
square_root(n)
— inputs: n is a real number, n ≥ 0.
— outputs : y is a real number such that y2 = n.
Question 7.
What are the basic building blocks of an algorithm?
Answer:
Algorithms are constructed using basic building blocks such as
- Data
- Variables
- Control flow
- Functions.
Question 8.
Write the control flow statements to alter the control flow depending on the state.
Answer:
There are three important control flow statements to alter the control flow depending on the state.
- In sequential control flow, a sequence of statements are executed one after another in the same order as they are written.
- In alternative control flow, a condition of the state is tested, and if the condition is true, one statement is executed; if the condition is false, an alternative statement is executed.
- In iterative control flow, a condition of the state is tested, and if the condition is true, a statement is executed. The two steps of testing the condition and executing the statement are repeated until the condition becomes false.
Question 9.
Write a note on Decomposition.
Answer:
We divide the main algorithm into functions. We construct each function independently of the main algorithm and other functions. Finally, we construct the main algorithm using the functions. When we use the functions, it is enough to know the specification of the function. It is not necessary to know how the function is implemented.
Question 10.
Write the specification in the initial state, all four variables farmer, goat, grass wolf have the variable L. In the final state all four variables should have the value R.
Answer:
cross_river
— inputs: farmer, goat, grass, wolf = L, L, L, L
— outputs: farmer, goat, grass, wolf = R, R, R, R
Question 11.
Explain the Algorithm Design Techniques.
Answer:
There are a few basic principles and techniques for designing algorithms.
(i) Specification:
The first step in problem solving is to state the problem precisely. A problem is specified in terms of the input given and the output desired. The specification must also state the properties of the given input, and the relation between the input and the output.
(ii) Abstraction:
A problem can involve a lot of details. Several of these details are unnecessary for solving the problem. Only a few details are essential. Ignoring or hiding unnecessary details and modeling an entity only by its essential properties is known as abstraction. For example, when we represent the state of a process, we select only the variables essential to the problem and ignore inessential details.
(iii) Composition:
An algorithm is composed ofassignmentandcontrolflowstatements. A control flow statement tests a condition of the state and depending on the value of the condition, decides the next statement to be executed.
(iv) Decomposition:
We divide the main algorithm into functions. We construct each function independently of the main algorithm and other functions. Finally, we construct the main algorithm using the functions. When we use the functions, it is enough to know the specification of the function. It is not necessary to know how the function is implemented.
Question 12.
Write the specification of an algorithm to compute the quotient and remainder after dividing an integer A by another integer B.
Answer:
Let A and B be the input variables. We will store the quotient in a variable q and the remainder in a variable r. So q and r are the output variables.
What are the properties of the inputs A and B?
Answer:
(i) A should be an integer. Remainder is meaningful only for integer division and ^
(ii) B should not be 0, since division by 0 is not allowed. We will specify the properties of the inputs as
— inputs: A is an integer and B ≠ 0
What is the desired relation between the inputs A and B, and the outputs q and r?
Answer:
(i) The two outputs q (quotient) and r (remainder) should satisfy the property
A = q × B + r, and
(ii) The remainder r should be less than the divisor B, 0 < r < B
Combining these requirements, we will specify the desired input-output relation as
— outputs: A = q × B + r and 0 < r < B.
The comment that starts with — inputs: actually is the property of the given inputs.
The comment that starts with — outputs: is the desired relation between the inputs and the outputs. The specification of the algorithm is
1. divide (A,B)
2. — inputs: A is an integer and B ≠ 0
3. — outputs : A = q × B + r and 0 < r < B
Question 13.
Define an algorithm.
Answer:
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 between the input data and the output data.
Question 14.
Distinguish between an algorithm and a process.
Answer:
Algorithm |
Process |
An algorithm is a sequence of instructions to accomplish a task or solve a problem. | A process evolves, which accomplishes the intended task or solve the given problem. |
Question 15.
Initially, farmer, goat, grass, wolf = L, L, L, L and the farmer crosses the river with goat. Model the action with an assignment statement.
Answer:
Farmer, goat: = R, R.
Question 16. Specify a function to find the minimum of two numbers.
Answer:
–min(a, b)
–inputs: a, b
–outputs:result = a↓b
Question 17.
If √2 = 1.414, and the square_root( ) function returns -1.414, does it violate the following specification?
Answer:
– square_root (x) – inputs: x is a real number, x > 0
– outputs: y is a real number such that y2 = x.
There is no real root of negative numbers. This is because there is no negative square number. When we square a positive number, we multiply positive by positive. When we square a negative number, we multiply negative by negative. In both cases the results are positive, i.e., there is no negative square involved. So there can’t “be a square root of negative numbers.
Question 18.
When do you say that a problem is algorithmic in nature?
Answer:
A problem is algorithmic in nature when its solution involves the construction of an algorithm. Some types of problems can be immediately recognized as algorithmic.
Question 19.
What is the format of the specification of an algorithm?
Answer:
The specification in a standard three part format:
- The name of the algorithm and the inputs.
- Input: the property of the inputs.
- Output: the desired input-output relation.
Question 20.
What is abstraction?
Answer:
Abstraction is the process of ignoring or hiding irrelevant details and modeling a problem only by its essential features. Abstractions are used unconsciously to handle complexity. It is the most effective mental tool used for managing complexity. If we do not abstract a problem adequately, we may deal with unnecessary details and complicate the solution.
Question 21.
How is state represented in algorithms?
Answer:
State is a basic and important abstraction. Computational processes have state. A computational process starts with an initial state. As actions are performed, its state changes. It ends with a final state. State of a process is abstracted by a set of variables in the algorithm. The state at any point of execution is simply the values of the variables at that point.
Question 22.
What is the form and meaning of assignment statement?
Answer:
Assignment statement is used to store a value in a variable. The variable is written on the left side of the assignment Operator and a value on the right side.
variable := value
When this assignment is executed, the value on the right side is stored in the variable on the left side. The assignment is m := 2
stores value 2 in variable m.
Question 23.
What is the difference between assignment operator and equality operator?
Answer:
Assignment Operator |
Equality Operator |
The ‘:=’ is the so – called assignment operator and is used to assign the result of the expression on the right side of the operator to the variable on the left side. | The ‘= =’ is the so – called equality comparison operator and is used to check whether the two expressions on both sides are equal or not. It returns true if they are equal and false if they are not equal. |
Question 24.
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.
Answer:
hypotenuse (a,b)
–inputs: (a,b)
–outputs: c where
c = (a2 + b2)1/2
Question 25.
Suppose you want to solve the quadratic equation ax2 + bx + c = 0 by an algorithm.
Answer:
quadratic_solve (a, b, c)
— inputs : ?
– outputs: ?
You intend to use the formula and you are prepared to handle only real number roots. Write a suitable specification.
x = \(\frac{-b \pm \sqrt{b^{2}-4 a c}}{2 a}\)
quadratic – solve (a, b, c)
–inputs: a, b, c are real numbers and a ≠ 0
–outputs: x1, x2 such that
d = (b x b) – (4 x a x c)
x1 = – b + (d)1/2 × a
x2 = – b – (d)1/2 × a
Question 26.
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.
Answer:
drinks(A, B)
— inputs: A, B where A and B are not empty
— outputs: B, A such that
t := A
A := B
B := t
Choose the correct answer:
Question 1.
An _________ is a sequence of instructions to accomplish a task or solve a problem.
(a) algorithm
(b) program
(c) instruction
(d) data
Answer:
(a) algorithm
Question 2.
_________ changes the values of variables and hence the state.
(a) Selection statement
(b) Assignment statement
(c) Control statement
(d) Functions
Answer:
(b) Assignment statement
Question 3.
_________ are named boxes for storing data.
(a) Variables
(b) Process
(c) Functions
(d) Procedure
Answer:
(a) Variables
Question 4.
The parts of an algorithm are known as:
(a) procedure
(b) decomposition
(c) abstraction
(d) functions
Answer:
(d) functions
Question 5.
________ indicates that the rest of the line is a comment in C++.
(a) –
(b) – –
(c) / /
(d) – /
Answer:
(c) / /
Question 6.
The specification of an algorithm can be _____ part.
(a) four
(b) three
(c) five
(d) two
Answer:
(b) three
Question 7.
Which symbol is used in algorithmic notation to start a comment line?
(a) –
(b) – –
(c) //
(d) *
Answer:
(b) – –
Question 8.
A computation is abstracted by a set of variables in:
(a) State
(b) Function
(c) Abstract
(d) Composition
Answer:
(a) State
Question 9.
Which statement is used to store a value in a variable?
(a) Control
(b) Input
(c) Assignment
(d) Branch
Answer:
(c) Assignment
Question 10.
Which is known as assignment operator?
(a) :=
(b) + =
(c) + + =
(d) = =
Answer:
(a) :=
Question 11.
Match the following:
(a) Relation between the input and the output | (i) Decomposition |
(b) Ignoring or hiding unnecessary details | (ii) Composition |
(c) Assignment and control flow statements | (iii) Abstractions |
(d) Functions | (iv) Specification |
(a) (iv), (iii), (ii), (i)
(b) (iii), (iv), (i), (ii)
(c) (iv), (ii), (i), (iii)
(d) (iv), (iii), (i), (ii)
Answer:
(a) (iv), (iii), (ii), (i)
Question 12.
Match the following:
(i) Functions | (a) Ignoring or hiding unnecessary details |
(ii) Abstraction | (b) Composed of assignment and control flow statements |
(iii) Composition | (c) Parts of an algorithm |
(iv) Decomposition | (d) Divide the main algorithm into functions |
(a) (i) – (d); (ii) – (b); (iii) – (c); (iv) – (a)
(b) (i) – (b); (ii) – (a); (iii) – (c); (iv) – (d)
(c) (i) – (c); (ii) – (a); (iii) – (b); (iv) – (d)
(d) (i) – (a); (ii) – (b); (iii) – (d); (iv) – (c)
Answer:
(c) (i) – (c); (ii) – (a); (iii) – (b); (iv) – (d)
Question 13.
Assertion (A):
An algorithm is a sequence of instructions to accomplish a task or solve a problem.
Reason (R):
An instruction describes an action.
(a) Both A and R are true, and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(a) Both A and R are true, and R is the correct explanation for A.
Question 14.
Assertion (A):
Specification cannot abstract a problem by the properties of the inputs and the desired input-output relation.
Reason (R):
We can recognize the properties essential for solving the problem and ignore the unnecessary details.
(a) Both A and R are true, and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(d) A is false, but R is true.
Question 15.
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
Answer:
(a) Assemble a bicycle
Question 16.
Which of the following activities is not algorithmic in nature?
(a) Multiply two numbers
(b) Draw a kolam
(c) Walk in the park
(d) Swaping of two numbers
Answer:
(a) Multiply two numbers
Question 17.
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
Answer:
(b) abstraction
Question 18.
Stating the input property and the input- output relation a problem is known:
(a) specification
(b) statement
(c) algorithm
(d) definition
Answer:
(a) specification
Question 19.
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.
Answer:
(a) the responsibility of the algorithm and the right of the user.
Question 20.
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
Answer:
(b) 4
Question 21.
If 0 < i before the assignment i := i – 1 after the assignment, we can conclude that:
(a) 0 < i
(b) 0 ≤ i
(c) i = 0
(d) 0 ≥ i
Answer:
(b) 0 ≤ i