Tamilnadu State Board New Syllabus Samacheer Kalvi 12th Computer Science Guide Pdf Chapter 2 Data Abstraction Text Book Back Questions and Answers, Notes.
Tamilnadu Samacheer Kalvi 12th Computer Science Solutions Chapter 2 Data Abstraction
12th Computer Science Guide Data Abstraction Text Book Questions and Answers
I. Choose the best answer (1 Marks)
Question 1.
Which of the following functions build the abstract data type?
a) Constructors
b) Destructors
c) recursive
d) Nested
Answer:
a) Constructors
Question 2.
Which of the following functions retrieve information from the data type?
a) Constructors
b) Selectors
c) recursive
d) Nested
Answer:
b) Selectors
Question 3.
The data structure which is a mutable ordered sequence of elements is called
a) Built-in
b) List
c) Tuple
d) Derived data
Answer:
b) List
Question 4.
A sequence of immutable objects is called
a) Built-in
b) List
c) Tuple
d) Derived data
Answer:
c) Tuple
Question 5.
The data type whose representation is known is called
a) Built-in data type
b) Derived data type
c) Concrete data type
d) Abstract data type
Answer:
c) Concrete data type
Question 6.
The data type whose representation is unknown are called
a) Built-in data type
b) Derived data type
c) Concrete data type
d) Abstract data type
Answer:
d) Abstract data type
Question 7.
Which of the following is a compound structure?
a) Pair
b) Triplet
c) single
d) quadrat
Answer:
a) Pair
Question 8.
Bundling two values together into one can be considered as
a) Pair
b) Triplet
c) single
d) quadrat
Answer:
a) Pair
Question 9.
Which of the following allows to name the various parts of a multi-item object?
a) Tuples
b) Lists
c) Classes
d) quadrats
Answer:
c) Classes
Question 10.
Which of the following is constructed by placing expressions within square brackets?
a) Tuples
b) Lists
c) Classes
d) quadrats
Answer:
b) Lists
II. Answer the following questions (2 Marks)
Question 1.
What is abstract data type?
Answer:
Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of values and a set of operations. The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented.
Question 2.
Differentiate constructors and selectors.
Answer:
Constructors | Selectors |
Constructors are functions that build the abstract data type. | Selectors are functions that retrieve information from the data type. |
Question 3.
What is a Pair? Give an example.
Answer:
- Pair is a compound structure which is made up of a list of Tuple
- The way of bundling two values together into one can be considered as a Pair.
- Example: Pr = [10,20]
a,b :=Pr
In the above example ‘a’ becomes 10,’ b’ becomes 20.
Question 4.
What is a List? Give an example.
Answer:
The list is constructed by placing expressions within square brackets separated by commas.
An example for List is [10, 20].
Question 5.
What is a Tuple? Give an example.
Answer:
- A tuple is a comma-separated sequence of values surrounded by parentheses.
- Example: colour^ (‘red’, ‘blue’, ‘Green’)
III. Answer the following questions (3 Marks)
Question 1.
Differentiate Concrete Data Type and Abstract Data Type
Answer:
Concrete Data Type | Abstract Data Type | |
1 | Concrete data types or structures (CDT’s) are direct implementations of a relatively simple concept | Abstract Data types (ADT’s) offer a high-level view (and use) of a concept independent of its implementation |
2 | In Concrete Data Type is a data type whose representation is known | In Abstract Data Type the representation of a data type is unknown |
Question 2.
Which strategy is used for program designing? Define that Strategy.
Answer:
We are using here a powerful strategy for designing programs: ‘wishful thinking’.
Wishful Thinking is the formation of beliefs and making decisions according to what might be pleasing to imagine instead of by . appealing to reality.
Question 3.
Identify Which of the following are constructors and selectors?
(a) N1=number()
(b) accetnum(n1)
(c) displaynum(n1)
(d) eval(a/b)
(e) x,y= makeslope (m), makeslope(n)
(f) display()
Answer:
a | N1=number() | a | Constructors |
b | accetnum(n1) | b | Selector |
c | displaynum(n1) | c | Selector |
d | eval(a/b) | d | Selector |
e | x,y= makeslope (m), makeslope(n) | e | Constructors |
f | display() | f | Selector |
Question 4.
What are the different ways to access the elements of a list. Give example
Answer:
List is constructed by placing expressions within square brackets separated by commas. An example for List is [10, 20].
The elements of a list can be accessed in two ways. The first way is via our familiar method of multiple assignments, which unpacks a list into its elements and binds each element to a different name.
1st: = [10, 20]
x, y: = 1st
In the above example, x will become 10 and y will become 20.
A second method for accessing the elements in a list is by the element selection operator, also expressed using square brackets. Unlike a list literal, a square – bracket expression directly following another expression does not evaluate to a list value but instead selects an element from the value of the preceding expression.
1st [0]
10
1st [1]
20
Question 5.
Identify Which of the following are List, Tuple and class ?
(a) arr [1, 2, 34]
(b) arr (1, 2, 34)
(c) student [rno, name, mark]
(d) day= (‘sun’, ‘mon’, ‘tue’, ‘wed’)
(e) x= [2, 5, 6.5, [5, 6], 8.2]
(f) employee [eno, ename, esal, eaddress]
Answer:
a | arr [1, 2, 34] | a | List |
b | arr (1, 2, 34) | b | Tuple |
c | student [rno, name, mark] | c | Class |
d | day= (‘sun’, ‘mon’, ‘tue’, ‘wed’) | d | Tuple |
e | x= [2, 5, 6.5, [5, 6], 8.2] | e | List |
f | employee [eno, ename, esal, eaddress] | f | Class |
IV. Answer the following questions (5Marks)
Question 1.
How will you facilitate data abstraction? Explain it with a suitable example.
Answer:
To facilitate data abstraction we need to create two types of functions namely
- Constructors
- Selectors
Constructors:
Constructors are functions that build the abstract data type.
Selectors:
Selectors are functions that retrieve information from the data type.
Example:
- We have an abstract data type called a city.
- This city object will hold the city’s name, and its latitude and longitude.
- To create a city object, you’d use a function like
city =makecity (name, lat, Ion) - Here makecity (name, lat, Ion) is the constructor which creates the object city.
- To extract the information of a city object, we would use functions(Selectors) like getname( city)
getlat( city)
getlon(city) - In the above example, makecity (name, lat, Ion) is the constructor and getname(city),getlat( city) and getlon(city) are the selectors.
- Because the above functions extract the information of the city object.
Question 2.
What is a List? Why List can be called as Pairs. Explain with suitable example
Answer:
- Some languages like Python provides a compound structure called Pair which is made up of List or Tuple.
The first way to implement pairs is with the List construct.
List:
- The list is constructed by placing expressions within square brackets separated by commas.
- Such an expression is called a list literal. The list can store multiple values.
- Each value can be of any type and can even be another list.
- Example :List := [10,20],
The elements of a list can be accessed in two ways. - The first way is via our familiar method of multiple assignments, which unpacks a list into its elements and binds each element to a different name.
1st := [10,20]
x, y := 1st
In the above example, x will become x and y will become 20. - A second method for accessing the elements in a list is by the element selection operator, also expressed using square brackets.
- Unlike a list literal, a square-brackets expression directly following another expression does not evaluate a list value but instead selects an element from the value of the preceding expression.
1st[0]
10
Ist[l]
20 - In both the example mentioned above mathematically we can represent list similar to a set as 1st[(0,10),(l,20)]
List [(0,10), (1,20)] – Where
- Any way of bundling two values together into one can be considered as a pair.
- Lists are a common method to do so. Therefore List can be called as Pairs.
Example: Representing rational numbers using list:
- We can now represent a rational number as a pair of two integers in pseudo-code: a numerator and a denominator.
rational(n, d):
return [n, d]
numer(x):
return x[0]
denom(x):
return x[l]
Question 3.
How will you access the multi-item? Explain with example.
Answer:
We can use the structure construct (In OOP languages it’s called class construct) to represent multi-part objects where each part is named (given a name).
Consider the following pseudo-code:
class Person:
creation()
firstName :=””
lastName :=””
id :=””
email :=””
The new data type Person is pictorially represented as
Let main() contains | |
p1:=Person() | statement creates the object |
firstN ame:=” Padmashri” | setting a field called first Name with value Padamashri |
lastName:=”Basker” | setting a field called last Name with value Baskar |
id:=”994-222-1234″ | setting a field called id value 994-222-1234 |
email=”[email protected]“ | setting a field called email with value [email protected] |
— output of first Name: Padmashri |
The class (structure) construct defines the form for multi-part objects that represent a person.
- Its definition adds a new data type, in this case, a type named Person.
- Once defined, we can create new variables (instances) of the type.
- In this example, Person is referred to as a class or a type, while pi is referred to as an object or an instance.
12th Computer Science Guide Data Abstraction Additional Questions and Answers
I. Choose the best answer (1 Mark)
Question 1.
How many types of functions are needed to facilitate abstraction?
(a) 1
(b) 2
(c) 3
(d) 4
Answer:
(b) 2
Question 2.
Expansion of CDT is ………….
a) Collective Data Type
b) Class Data Type
c) Concrete Data Type
d) Central Data Type
Answer:
c) Concrete Data Type
Question 3.
To facilitate data abstraction we need to create types of functions
a) 2
b) 3
c) 4
d) 5
Answer:
a) 2
Question 4.
……………………………. is the representation for ADT.
(a) List
(b) Classes
(c) Int
(d) Float
Answer:
(b) Classes
Question 5.
Which of the following is contracted by placing expressions within square brackets separated by commas?
a) Tuple
b) List
c) Set
d) Dictionary
Answer:
b) List
Question 6.
The list is constructed by using …………….. and …………….
a) ();
b) [ ],
c) < >.;
d) [ ]
Answer:
b) [ ],
Question 7.
Identify the constructor from the following
(a) City = makecity(name, lat, lon)
(b) getname(city)
(c) getlat(city)
(d) getlon(city)
Answer:
(a) City = makecity(name, lat, lon)
Question 8.
Which of the following extract the information of the object?
a) Constructors
b) Selectors
c) Functions
d) Destructors
Answer:
b) Selectors
Question 9.
Which of the following is used to build the abstract data type?
a) Destructors
b) Constructors
c) Selectors
d) All of these
Answer:
b) Constructors
Question 10.
How many ways of representing pair data types are there?
(a) 1
(b) 2
(c) 3
(d) 4
Answer:
(b) 2
Question 11.
The process of providing only the essentials and hiding the details is known as …………….
a) Functions
b) Encapsulation
c) Abstraction
d) Pairs
Answer:
c) Abstraction
Question 12.
A D T expansion is …………….
a) Abstract Data Type
b) Absolute Data Type
c) Abstract Data Template
d) Application Development Template
Answer:
a) Abstract Data Type
Question 13.
How many objects can be created from a class?
(a) 0
(b) 1
(c) 2
(d) many
Answer:
(d) many
Question 14.
A powerful concept that allows programmers to treat codes as objects?
a) Encapsulation
b) Inheritance
c) Data Abstraction
d) Polymorphism
Answer:
c) Data Abstraction
II. Answer the following questions (2 and 3 Marks)
Question 1.
What are the two parts of a program?
Answer:
The two parts of a program are, the part that operates on abstract data and the part that defines a concrete representation.
III. Answer the following questions (5 Marks)
Question 1.
Explain the representation of Abstract data type using rational numbers.
Answer:
- Any program consists of two parts – the part that operates on abstract data and the part that defines a concrete representation, which is connected by a small set of functions that implement abstract data in terms of the concrete representation.
- To illustrate this technique, let us consider an example to design a set of functions for manipulating rational numbers.
Example:
- A rational number is a ratio of integers, and rational numbers constitute an important sub-class of real numbers.
- A rational number such as 8/3 or 19/23 is typically written as : < numerator > /< denominator > where both the < numerator > and < denominator > are placeholders for integer values.
- Both parts are needed to exactly characterize the value of the rational number.
- Actually dividing integers produces a float approximation, losing the exact precision of integers.
- However, you can create an exact representation for rational numbers by combining together the numerator and denominator.
– – constructor
– – constructs a rational number with numerator n, denominator d
rational (n, d)
– – selector
numer(x) → returns the numerator of rational number x
denom(y) → returns the denominator of rational number y. - We have the operations on rational numbers defined in terms of the selector functions numer and denom, and the constructor function rational, but you haven’t yet defined these functions.
- We have to glue together a numerator and a denominator into a compound value
- The pseudo-code for the representation of the rational number using the above constructor and selector is
x,y:=8,3
rational (n,d)
numer(x)/numer(y)
– – output: 2.6666666666666665