Computer Modified
Computer Modified
in
GOVERNMENT OF TAMILNADU
HIGHER SECONDARY
SECOND YEAR
COMPUTER SCIENCE
Content Creation
The wise
possess all
II
HOW
his book does not require
T TO USE
prior knowledge in computer
Technology
THE BOOK?
ach unit comprises of simple
E
activities and demonstrations which can be done by
the teacher
and also students.
Technical terminologies are listed in glossary for easy understanding
he “ Do you know?” boxes enrich the knowledge of reader with
T
additional information
orkshops are introduced to solve the exercises using software
W
applications
QR codes are used to link supporting additional
materials in digital form
How to get connected to QR Code?
o
Download the QR code scanner from the google play store/
apple app store into your smartphone
o Open the QR code scanner application
o Once the scanner button in the application is clicked, camera opens
and then bring it closer to the QR code in the textbook.
o Once the camera detects the QR code, a URL appears in the screen.
Click the URL and go to the content page.
III
Centre ffor Development of Advanced Computing [Link] Artificial Intelligence Database Management
IV
Technical Diploma
Scholarships for graduate
Diploma in Engineering
D and post graduate courses
DST – INSPIRE
IN Fellowships (for Ph.D)
Professional Degree & Entrance Exams
P DST – INSPIRE Scholarships
(for UG and PG)
Hotel & Catering Institute [Link] JEE-Joint Entrance Examination [Link] In addition various fellowships for
AIEEE- All India Engineering Entrance Exam JEST- Joint Entrance Screening Test [Link] SC/ST/PWD,
B.E/[Link]/ [Link] (JEE, AIEEE in IITs and NITs) Law 5-Year Integrated Course [Link] Indira Gandhi Fellowship for
Fashion Technology & Design [Link] National Defence Academy [Link] Single girl child (for UG and PG)
GATE-Graduate Aptitude Test in Engineering NET- National Eligibility Test (CSIR and UGC) [Link] Moulana Azad Fellowship
www [Link] TamilNadu Dr. Ambedkar Law University [Link] for minorities (for Ph.D)
Indian Navy – 10+2 BTech Entry Scheme Technical Entry Scheme – Army/Navy/Airforce UGC National Fellowship (for Ph.D)
CAREER GUIDANCE AFTER 12TH
Institute of Chartered Accountants of India [Link] TIFR GS - Tata Institute of Fundamental International Olympiad: for getting stipend for
Institute of Company Secretary [Link] Research Graduate School [Link] Higher Education in Science and Mathematics
Institute of Cost Accountants of India [Link] Visual Arts Degree OBC etc are available.
Institute of Banking Personal Selection IBPS [Link] [Link]
Visit website of University Grants Commission
23-12-2022 13:19:00
After PG courses
A Competitive Exams for Govt. Jobs
MPhil –Computer Science | PhD – Computer Science Airforce Common Admission Test – AFCAT | Army Education Officer Entry- AEC
V
SCIENCE Computer Support Specialist | Computer System Analysts
Manipulators And Manipulation In High Dimensional Spaces
Data Mining Specialist | Database Administrator
New Algorithmic Tools for Distributed Similarity Search
Information Security Analysts | Market Research Analysts
Reproducible measurements of web security and privacy Network & Computer System Administrator | Research Assistant
The Security and Privacy of Web and Mobile Advertising Systems Software Developer | User Interface Designer | Web Developer
Towards More Practical Reinforcement Learning,
with Applications to Educational Games
Research Institutions in various areas of science
23-12-2022 13:19:01
Table of Contents
Computer Science-II Year
UNIT NO. CHAPTER COMPUTER SCIENCE PAGE NO MONTH
UNIT- I 1 Function 1 June
Problem 2 Data Abstraction 11 June
Solving 3 Scoping 21 June
Techniques 4 Algorithmic Strategies 31 June
5 Python -Variables and Operators 47 July
E - book Assessment
VI
After the completion of this chapter, the A function is a unit of code that is
student will be able to: often defined within a greater code structure.
Specifically, a function contains a set of
• Understand Function Specification.
code that works on many kinds of inputs,
• Parameters (and arguments). like variables, expressions and produces a
• Interface Vs Implementation. concrete output.
• Pure functions. 1.2.1 Function Specification
• Side - effects (impure functions). Let us consider the example a:= (24).
a:= (24) has an expression in it but (24)
1.1 Introduction is not itself an expression. Rather, it is a
The most important criteria in function definition. Definitions bind values
writing and evaluating the algorithm is the to names, in this case the value 24 being
time it takes to complete a task. The duration bound to the name ‘a’. Definitions are not
of computation time must be independent expressions, at the same time expressions are
of the programming language, compiler, also not treated as definitions. Definitions
and computer used. As you aware that are distinct syntactic blocks. Definitions can
algorithms are expressed using statements have expressions nested inside them, and
of a programming language. If a bulk of vice-versa.
statements to be repeated for many numbers 1.2.2 Parameters and arguments
of times then subroutines are used to finish
the task. Parameters are the variables in a
function definition and arguments are
Subroutines are the basic building the values which are passed to a function
blocks of computer programs. Subroutines definition.
are small sections of code that are used to
1. Parameter without Type
perform a particular task that can be used
repeatedly. In Programming languages these Let us see an example of a function
subroutines are called as Functions. definition:
The syntax for function types: The difference between interface and
implementation is
x→y
x1 → x2 → y Interface Implementation
x1 → ... → xn → y
Interface just Implementation
defines what carries out the
The ‘x’ and ‘y’ are variables indicating an object can instructions defined
types. The type x → y is the type of a function do, but won’t in the interface
that gets an input of type ‘x’ and returns an actually do it
output of type ‘y’. Whereas x1 → x2 → y is
a type of a function that takes two inputs, In object oriented programs classes are
the first input is of type ‘x1’ and the second the interface and how the object is processed
input of type ‘x2’, and returns an output of and executed is the implementation.
type ‘y’. Likewise x1 → … → xn → y has
type ‘x’ as input of n arguments and ‘y’ type 1.3.1 Characteristics of interface
as output. • The class template specifies the interfaces
to enable an object to be created and
Note operated properly.
All functions are static • An object's attributes and behaviour is
definitions. There is no dynamic controlled by sending functions to the
function definitions. object.
3 Function
Internally, the engine of the car is The above function square is a pure
doing all the things. It's where fuel, air, function because it will not give different
pressure, and electricity come together to results for same input.
create the power to move the vehicle. All of
There are various theoretical
these actions are separated from the driver,
advantages of having pure functions. One
who just wants to go faster. Thus we separate
advantage is that if a function is pure, then
interface from implementation.
if it is called several times with the same
Let us see a simple example, consider arguments, the compiler only needs to
the following implementation of a function actually call the function once. Let’s see an
that finds the minimum of its three example
arguments:
let length s:=
i: = 0
if i <strlen (s) then
-- Do something which doesn't affect s
++i
5 Function
monochromatize (a, b, c)
Now let’s see the example of a pure
function to determine the greatest common
-- inputs : a = A, b = B, c = C, a = b
divisor (gcd) of two positive integer numbers.
-- outputs : a = b = 0, c = A+B+C
let rec gcd a b :=
if b <> 0 then gcd b (a mod b) In each iterative step, two chameleons
else
of the two types (equal in number) meet and
return a
change their colors to the third one. For
output
example, if A, B, C = 4, 4, 6, then the series
gcd 13 27
1
of meeting will result in
gcd 20536 7826
2 iteration a b c
0 4 4 6
In the above example ‘gcd’ is the name
of the function which recursively called till 1 3 3 8
the variable ‘b’ becomes ‘0’. Remember b
and (a mod b) are two arguments passed to 2 2 2 10
‘a’ and ‘b’ of the gcd function. 3 1 1 12
4 0 0 14
Points to remember:
• Algorithms are expressed using statements of a programming language
• Subroutines are small sections of code that are used to perform a particular task that
can be used repeatedly
• A function is a unit of code that is often defined within a greater code structure
• A function contains a set of code that works on many kinds of inputs and produces a
concrete output
• Definitions are distinct syntactic blocks
• Parameters are the variables in a function definition and arguments are the values
which are passed to a function definition through the function definition.
• When you write the type annotations the parentheses are mandatory in the function
definition
• An interface is a set of action that an object can do
• Interface just defines what an object can do, but won’t actually do it
• Implementation carries out the instructions defined in the interface
• Pure functions are functions which will give exact result when the same arguments
are passed
• The variables used inside the function may cause side effects though the functions
which are not passed with any arguments. In such cases the function is called impure
function
7 Function
Evaluation
Part - I
Choose the best answer (1 Mark)
1. The small sections of code that are used to perform a particular task is called
(A) Subroutines (B) Files (C) Pseudo code (D) Modules
2. Which of the following is a unit of code that is often defined within a greater code
structure?
(A) Subroutines (B) Function (C) Files (D) Modules
3. Which of the following is a distinct syntactic block?
(A) Subroutines (B) Function (C) Definition (D) Modules
4. The variables in a function definition are called as
(A) Subroutines (B) Function (C) Definition (D) Parameters
5. The values which are passed to a function definition are called
(A) Arguments (B) Subroutines (C) Function (D) Definition
6. Which of the following are mandatory to write the type annotations in the function
definition?
(A) { } (B) ( ) (C) [ ] (D) < >
7. Which of the following defines what an object can do?
(A) Operating System (B) Compiler (C) Interface (D) Interpreter
8. Which of the following carries out the instructions defined in the interface?
(A) Operating System (B) Compiler (C) Implementation (D) Interpreter
9. The functions which will give exact result when same arguments are passed are called
(A) Impure functions (B) Partial Functions
(C) Dynamic Functions (D) Pure functions
Part - III
9 Function
REFERENCES
13 Data Abstraction
Any way of bundling two values Note the square bracket notation is
together into one can be considered as a used to access the data you stored in the pair.
pair. Lists are a common method to do so. To access the first element with nums[0] and
Therefore List can be called as Pairs. the second with nums[1].
Representing Rational Numbers Using
List
You can now represent a rational
number as a pair of two integers in pseudo
code : a numerator and a denominator.
15 Data Abstraction
List allow data abstraction in that but such a representation doesn't explicitly
you can give a name to a set of memory specify what each part represents.
cells. For instance, in the game Mastermind,
you must keep track of a list of four colors For this problem instead of using a
that the player guesses. Instead of using four list, you can use the structure construct (In
separate variables (color1, color2, color3, OOP languages it's called class construct)
and color4) you can use a single variable to represent multi-part objects where each
‘Predict’, e.g., part is named (given a name). Consider the
following pseudo code:
Predict:=['red', 'blue', 'green', 'green']
class Person:
What lists do not allow us to do
creation( )
is name the various parts of a multi- item
object. In the case of a Predict, you don't firstName := " "
really need to name the parts: lastName := " "
id := " "
using an index to get to each color suffices.
email := " "
But in the case of something more
complex, like a person, we have a multi- item The new data type Person is pictorially
object where each 'item' is a named thing: represented as
the firstName, the lastName, the id, and the
email. One could use a list to represent a
person:
creation ( )
function belonging to the new datatype
}
first Name
The class (structure) construct So far, you've seen how a class defines
defines the form for multi-part objects that a data abstraction by grouping related data
represent a person. Its definition adds a new items. A class is not just data, it has functions
data type, in this case a type named Person. defined within it. We say such functions are
Once defined, we can create new variables subordinate to the class because their job is
(instances) of the type. In this example to do things with the data of the class, e.g.,
Person is referred to as a class or a type, to modify or analyze the data of a Person
while p1 is referred to as an object or an object.
instance. You can think of class Person as a Therefore we can define a class as
cookie cutter, and p1 as a particular cookie. bundled data and the functions that work
Using the cookie cutter you can make many on that data. From All the above example
cookies. Same way using class you can create and explanation one can conclude the
many objects of that type. beauty of data abstraction is that we can
treat complex data in a very simple way.
Points to remember:
• Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by
a set of value 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.
• ADT does not specify how data will be organized in memory and what algorithms
will be used for implementing the operations
• Constructors are functions that build the abstract data type.
• Selectors are functions that retrieve information from the data type.
• 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.
17 Data Abstraction
Evaluation
Part - I
Part - II
Part - III
19 Data Abstraction
Reference Books
1. Data structure and algorithmic thinking with python by narasimha karumanchi
2. sign and analysis of algorithms by s sridhar
3. Data Structures and Algorithms in Python by Goodrich, Tamassia & Goldwasser
4. [Link]
21