You are on page 1of 17

COMPUTER SCIENCE (868)

Aims (Conceptual) (b) how they communicate with the outside


world.
(1) To understand algorithmic problem solving
using data abstractions, functional and (3) To create awareness of ethical problems and
procedural abstractions, and object based and issues related to computing.
object oriented abstractions.
Aims (Skills)
(2) To understand: (a) how computers represent,
To devise algorithmic solutions to problems and to
store and process data by studying the
be able to code, validate, document, execute and
architecture and machine language of a simple
debug the solution using the Java programming
microprocessor and the different levels of
system.
abstraction that mediate between the machine
and the algorithmic problem solving level and

CLASS XI

There will be two papers in the subject: algorithms are also good examples for defining
Paper I: Theory - 3 hours ….100 marks different functions in a class modelling numbers
(when programming is discussed). For addition
Paper II: Practical - 3 hours ….100 marks and subtraction use the analogy with decimal
numbers, emphasize how carry works (this will be
PAPER I -THEORY useful later when binary adders are discussed).
Paper 1 shall be of 3 hours duration and be divided 2. Encodings
into two parts.
(a) Binary encodings for integers and real
Part I (30 marks): This part will consist of numbers using a finite number of bits (sign-
compulsory short answer questions, testing magnitude, twos complement, mantissa-
knowledge, application and skills relating to the entire exponent notation). Basic operations on
syllabus.
integers and floating point numbers.
Part II (70 marks): This part will be divided into Limitations of finite representations.
three Sections, A, B and C. Candidates are required to
answer three questions out of four from Section A and Signed, unsigned numbers, least and most
two questions out of three in each of the Sections B significant bits. Sign-magnitude
and C. Each question in this part shall carry 10 representation and its shortcomings (two
marks. representations for 0, addition requires extra
SECTION A step); twos-complement representation.
Operations (arithmetic, logical, shift), discuss
Basic Computer Hardware and Software
the basic algorithms used for the arithmetic
1. Numbers operations. Floating point representation:
normalized scientific notation, mantissa-
Representation of numbers in different bases and
exponent representation, binary point (discuss
interconversion between them (e.g. binary, octal,
decimal, hexadecimal). Addition and subtraction trade-off between size of mantissa and
operations for numbers in different bases. exponent). Single and double precision.
Arithmetic operations with floating point
Introduce the positional system of representing
numbers. Properties of finite representation:
numbers and the concept of a base. Discuss the
overflow, underflow, lack of associativity
conversion of representations between different
bases using English or pseudo code. These (demonstrate this through actual programs).

217
(b) Characters and their encodings (e.g. ASCII, 5. Propositional logic, hardware implementation,
Unicode). arithmetic operations

Discuss the limitations of the ASCII code in (a) Propositional logic, well formed formulae,
truth values and interpretation of well formed
representing characters of other languages. formulae, truth tables.
Discuss the Unicode representation for the
local language. Java uses Unicode, so strings Propositional variables; the common logical
connectives (~ (not)(negation), ∧
in the local language can be used (they can (and)(conjunction), ∨ (or)(disjunction),
be displayed if fonts are available) – a simple ⇒ (implication),  (equivalence)); definition
table lookup for local language equivalents of a well-formed formula (wff); representation
for Latin (i.e. English) character strings may of simple word problems as wff (this can be
be done. More details on Unicode are used for motivation); the values true and
available at www.unicode.org. false; interpretation of a wff; truth tables;
satisfiable, unsatisfiable and valid formulae.
3. High level structure of computer (b) Logic and hardware, basic gates (AND, NOT,
OR) and their universality, other gates
Block diagram of a computer system with details (NAND, NOR, XOR); inverter, half adder,
of (i) function of each block and full adder.
(ii) interconnectivity and data and control flow Show how the logic in (a) above can be
between the various blocks realized in hardware in the form of gates.
These gates can then be combined to
Develop the diagram by successive refinement of
implement the basic operations for arithmetic.
blocks till all the following have been covered: Tie up with the arithmetic operations on
ALU, RAM, cache, the buses (modern computers integers discussed earlier in 2 (a).
have multiple buses), disk (disk controller and
what it does), input/output ports (serial, parallel, 6. Memory
USB, network, modem, line-in, line-out etc.), Memory organization and access; parity; memory
devices that can be attached to these ports hierarchy - cache, primary memory, secondary
(e.g keyboard, mouse, monitor, CDROM, DVD, memory.
audio input/output devices, printer, etc.). Clearly The access time differences between the different
describe the connectivity and the flow of data and kinds of memory; size differences; locality of
control signals. reference and cache memory.

4. Basic architecture of a simple processor and its 7. System and other software
instruction set Boot process. Operating system as resource
manager, command processing, files, directories
Simple Hypothetical Computer. and file system. Commonly available programs
The simple hypothetical computer abbreviated as (editors, compilers, interpreters, word processors,
spread sheets etc.).
(SHC) is meant to introduce the basic structure of
a processor in particular registers, basic Boot process step-by-step from power on till the
instruction set, structure of an instruction, prompt. In OS discuss: (i) all the resources
(processor, memory, i/o) that need to be managed
program counter addressing modes (immediate,
in a computer; (ii) what is meant by managing
direct, register, register-indirect). Simple these resources. Logical structure of data storage
programs should be written in the SHC on disk using logical disks, hierarchical
instruction set (e.g. max./min. of set of nos.) directories and files. Distinguish between
interpreters and compilers. In particular discuss
the javac and java programs.

218
SECTION B 10. Primitive values, wrapper classes, types and
casting
The programming element in the syllabus is aimed at
Primitive values and types: int, short, long, float,
algorithmic problem solving and not merely rote double, boolean, char. Corresponding wrapper
learning of Java syntax. The Java version used should classes for each primitive type. Class as type of
be 1.5 or later. For programming, the students can use the object. Class as mechanism for user defined
any text editor and the javac and java programs or any types. Changing types through user defined
development environment: for example, BlueJ, casting and automatic type coercion for some
primitive types.
Eclipse, NetBeans etc. BlueJ is strongly recommended
for its simplicity, ease of use and because it is very Ideally, everything should be a class; primitive
well suited for an ‘objects first’ approach. types are defined for efficiency reasons; each
primitive type has a corresponding wrapper class.
Classes as user defined types. In some cases types
8. Introduction to algorithmic problem solving are changed by automatic coercion or casting –
using Java e.g. mixed type expressions. However, casting in
general is not a good idea and should be avoided,
Note that topics 9 to 13 will get introduced almost if possible.
simultaneously when classes and their definitions
are introduced. 11. Variables, expressions
Variables as names for values; expressions
9. Objects (arithmetic and logical) and their evaluation
(a) Objects as data (attributes) + behaviour (operators, associativity, precedence). Assignment
(methods or functions); object as an instance operation; difference between left hand side and
right hand side of assignment.
of a class. Constructors.
Variables denote values; variables are already
Difference between object and class should be defined as attributes in classes; variables have
made very clear. BlueJ (www.bluej.org) and types that constrain the values it can denote.
Greenfoot (www.greenfoot.org) can be used Difference between variables denoting primitive
for this purpose. Constructor as a special kind values and object values – variables denoting
of function; the new operator; multiple objects are references to those objects. The
assignment operator = is special. The variable on
constructors with different argument
the lhs of = denotes the memory location while the
structures; constructor returns a reference to same variable on the rhs denotes the contents of
the object. the location e.g. i=i+2.
(b) Analysis of some real world programming
12. Statements, scope
examples in terms of objects and classes.
Statements; conditional (if, if-then-else, switch-
Use simple examples like a calculator, date, break, ?: ternary operator), looping (for, while-do,
number etc. to illustrate how they can be do-while, continue, break); grouping statements in
treated as objects that behave in certain well- blocks, scope and visibility of variables.
defined ways and how the interface provides a Describe the semantics of the conditional and
way to access behaviour. Illustrate behaviour looping statements in detail. Evaluation of the
changes by adding new functions, deleting old condition in conditional statements (esp.
functions or modifying existing functions. difference between || and | and && and &).
Emphasize fall through in switch statement. Many
small examples should be done to illustrate
control structures. Printing different kinds of
219
patterns for looping is instructive. When number 14. Arrays, strings
of iterations are known in advance use the for (a) Structured data types – arrays (single and
loop otherwise the while-do or do-while loop. multi-dimensional), strings. Example
Express one loop construct using the others. For algorithms that use structured data types (e.g.
e.g.: searching, finding maximum/minimum,
for (<init>; <test>; <inc>) <stmt>; is equivalent sorting techniques, solving systems of linear
to: equations, substring, concatenation, length,
access to char in string, etc.).
(i) Using while
Storing many data elements of the same type
<init>; while <test> {<stmt>; <inc> } requires structured data types – like arrays.
(ii) Using do-while Access in arrays is constant time and does not
depend on the number of elements. Sorting
<init>; if !<test> do <stmt>; <inc> while
techniques (bubble, selection, insertion),
<test>; Structured data types can be defined by
Nesting of blocks. Variables with block scope, classes – String. Introduce the Java library
function scope, class scope. Visibility rules when String class and the basic operations on
variables with the same name are defined in strings (accessing individual characters,
different scopes. various substring operations, concatenation,
replacement, index of operations).
13. Functions
(b) Basic concept of a virtual machine; Java
Functions/methods (as abstractions for complex virtual machine; compilation and execution of
user defined operations on objects), functions as Java programs (the javac and java programs).
mechanisms for side effects; formal arguments
The JVM is a machine but built as a program
and actual arguments in functions; different
and not through hardware. Therefore it is
behaviour of primitive and object arguments.
called a virtual machine. To run, JVM
Static functions and variables. The this variable.
machine language programs require an
Examples of algorithmic problem solving using
interpreter (the java program). The advantage
functions (various number theoretic problems,
is that such JVM machine language programs
finding roots of algebraic equations).
(.class files) are portable and can run on any
Functions are like complex operations where the machine that has the java program.
object is implicitly the first argument. Variable (c) Compile time and run time errors; basic
this denotes the current object. Functions concept of an exception, the Exception class,
typically return values, they may also cause side- catch and throw.
effects (e.g. change attribute values of objects) – Differentiate between compile time and run
typically functions that are only supposed to cause time errors. Run time errors crash the
side-effects return void (e.g. Set functions). Java program. Recovery is possible by the use of
passes argument by value. Illustrate the difference exceptions. Explain how an exception object
between primitive values and object values as is created and passed up until a matching
arguments (changes made inside functions persist catch is found. This behaviour is different
after the call for object values). Static definitions from the one where a value is returned by a
as class variables and class functions visible and deeply nested function call. It is enough to
shared by all instances. Need for static functions discuss the Exception class. Sub-classes of
Exception can be discussed after inheritance
and variables. Introduce the main method –
has been done in Class XII.
needed to begin execution.

220
SECTION C Object pop()
15. Elementary data structures and associated boolean isEmpty()
algorithms, basic input/output Object top()
(a) Class as a contract; separating implementation Then, for example the LIFO property can be
from interface; encapsulation; private and expressed by (assume s is a stack):
public.
if s.push(o); o1=pop() then o ≡ o1
Class is the basic reusable unit. Its function
What the rule says is: if o is pushed on the
prototypes (i.e. the interface) work as a visible
stack s and then it is popped and o1 is the
contract with the outside world since others
object obtained then o, o1 are identical.
will use these functions in their programs.
This leads to encapsulation (i.e. hiding Another useful property is:
implementation information) which in turn if s.isEmpty() == true then s.pop() = ERROR
leads to the use of private and public for
realizing encapsulation. It says that popping an empty stack gives
ERROR.
(b) Interfaces in Java; implementing interfaces
through a class; interfaces for user defined Similarly, several other properties can also be
implementation of behaviour. specified. It is important to emphasize the
behavioural rules or properties of a data
Motivation for interface: often when creating structure since any implementation must
reusable classes some parts of the exact guarantee that the rules hold.
implementation can only be provided by the
final end user. For example in a class that Some simple algorithms that use the data
sorts records of different types the exact structures:
comparison operation can only be provided i) For stack: parentheses matching, tower of
by the end user. Since only he/she knows Hanoi, nested function calls; solving a
which field(s) will be used for doing the maze.
comparison and whether sorting should be in
ascending or descending order be given by ii) For queue: scheduling processes, printers,
the user of the class. jobs in a machine shop.
Emphasize the difference between the Java (d) Basic input/output using Scanner and Printer
language construct interface and the word classes from JDK; files and their
interface often used to describe the set of representation using the File class, file
function prototypes of a class. input/output; input/output exceptions. Tokens
in an input stream, concept of whitespace,
(c) Basic data structures (stack, queue, dequeue); extracting tokens from an input stream
implementation directly through classes; (StringTokenizer class).
definition through an interface and multiple
implementations by implementing the The Scanner class can be used for input of
interface. Basic algorithms and programs various types of data (e.g. int, float, char etc.)
using the above data structures. from the standard input stream or a file input
stream. The File class is used model file
A data structure is a data collection with well objects in the underlying system in an OS
defined operations and behaviour or independent manner. Similarly, the Printer
properties. The behaviour or properties can class handles output. Only basic input and
usually be expressed formally using equations output using these classes should be covered.
or some kind of logical formulae. Consider
for e.g. a stack with operations defined as Discuss the concept of a token (a delimited
follows: continuous stream of characters that is
meaningful in the application program – e.g.
void push(Object o)
words in a sentence where the delimiter is the
221
blank character). This naturally leads to the (f) Concrete computational complexity; concept
idea of delimiters and in particular of input size; estimating complexity in terms
whitespace and user defined characters as of functions; importance of dominant term;
delimiters. As an example show how the best, average and worst case.
StringTokenizer class allows one to extract a Points to be given particular emphasis:
sequence of tokens from a string with user
defined delimiters. (i) Algorithms are usually compared along
two dimensions – amount of space (that is
(e) Concept of recursion, simple recursive memory) used and the time taken. Of the
functions (e.g. factorial, GCD, binary search, two the time taken is usually considered
conversion of representations of numbers the more important. The motivation to
between different bases). study time complexity is to compare
Many problems can be solved very elegantly different algorithms and use the one that is
by observing that the solution can be the most efficient in a particular situation.
composed of solutions to ‘smaller’ versions of (ii) Actual run time on a particular computer
the same problem with the base version is not a good basis for comparison since it
having a known simple solution. Recursion depends heavily on the speed of the
can be initially motivated by using recursive computer, the total amount of RAM in the
equations to define certain functions. These computer, the OS running on the system
definitions are fairly obvious and are easy to and the quality of the compiler used. So
understand. The definitions can be directly we need a more abstract way to compare
converted to a program. Emphasize that any the time complexity of algorithms.
recursion must have a base case. Otherwise, (iii) This is done by trying to approximate the
the computation can go into an infinite loop. number of operations done by each
Illustrate this by removing the base case and algorithm as a function of the size of the
running the program. Examples: input. In most programs the loops are
(i) Definition of factorial: important in deciding the complexity. For
example in bubble sort there are two
factorial(0) = 1 //base case nested loops and in the worst case the time
factorial(n) = n * factorial(n-1) taken will be proportional to n(n-1) where
n is the number of elements to be sorted.
(ii) Definition of GCD: Similarly, in linear search in the worst
gcd(m, n) = case the target has to be compared with
all the elements so time taken will be
if (m==n) then n //base case
proportional to n where n is the number of
else if (m>n) then gcd(m-n, n) elements in the search set.
else gcd(m, n-m) (iv) In most algorithms the actual complexity
for a particular input can vary. For
(iii) Definition of Fibonacci numbers: example in search the number of
fib(0) = 1 //base case comparisons can vary from 1 to n. This
means we need to study the best, worst
fib(1) = 1 //base case and average cases. Comparisons are
fib(n) = fib(n-1)+ fib(n-2) usually made taking the worst case.
Average cases are harder to estimate
The tower of Hanoi is a very good example of
since it depends on how the data is
how recursion gives a very simple and elegant
distributed. For example in search, if the
solution where as non-recursive solutions are
elements are uniformly distributed it will
quite complex. Discuss the use of a stack to
take on the average n/2 comparisons when
keep track of function calls. The stack can
the average is taken over a statistically
also be used to solve the tower of Hanoi
significant number of instances.
problem non-recursively.
222
(v) Comparisons are normally made for large PAPER II - PRACTICAL
values of the input size. This means that
the dominant term in the function is the This paper of three hours duration will be evaluated
important term. For example if we are internally by the school.
looking at bubble sort and see that time The paper shall consist of three programming
taken can be estimated as: a*n2 +b*n + c problems from which a candidate has to attempt any
where n is the number of elements to be one. The practical consists of the two parts:
sorted and a, b, c are constants then for
large n the dominant term is clearly n2 and (1) Planning Session
we can in effect ignore the other two (2) Examination Session
terms.
The total time to be spent on the Planning session and
16. Implementation of algorithms to solve the Examination session is three hours. After
problems completing the Planning session the candidates may
The students are required to do lab assignments in begin with the Examination session. A maximum of
the computer lab concurrently with the lectures. 90 minutes is permitted for the Planning session.
Programming assignments should be done such However, if the candidates finish earlier, they are to
that each major topic is covered in at least one be permitted to begin with the Examination session.
assignment. Assignment problems should be Planning Session
designed so that they are non-trivial and make the
student do algorithm design, address correctness The candidates will be required to prepare an
issues, implement and execute the algorithm in algorithm and a hand written Java program to solve
Java and debug where necessary. the problem.

Self explanatory. Examination Session


The program handed in at the end of the Planning
17. Social context of computing and ethical issues session shall be returned to the candidates. The
candidates will be required to key-in and execute the
(a) Intellectual property and corresponding laws Java program on seen and unseen inputs individually
and rights, software as intellectual property. on the Computer and show execution to the examiner.
(b) Software copyright and patents and the A printout of the program listing, including output
difference between the two; trademarks; results should be attached to the answer script
software licensing and piracy. containing the algorithm and handwritten program.
This should be returned to the examiner. The program
(c) Free software foundation and its position on should be sufficiently documented so that the
software, open source software, various types algorithm, representation and development process is
of licensing (e.g. GPL, BSD). clear from reading the program. Large differences
(d) Privacy, email etiquette, spam, security issues, between the planned program and the printout will
phising. result in loss of marks.
Social impact and ethical issues should be Teachers should maintain a record of all the
discussed and debated in class. The important assignments done as part of the practical work through
thing is for students to realise that these are the year and give it due credit at the time of
complex issues and there are multiple points of cumulative evaluation at the end of the year. Students
view on many of them and there is no single are expected to do a minimum of twenty assignments
‘correct’ or ‘right’ view. for the year.
Marks (out of a total of 100) should be distributed as
given below:

223
Continuous Evaluation (Marks should be given for choice of algorithm and
implementation strategy, documentation, correct output
Candidates will be required to submit a work file
on known inputs mentioned in the question paper,
containing the practical work related to programming
correct output for unknown inputs available only to the
assignments done during the year.
examiner.)
Programming assignments done throughout the year Viva-voce - 20 marks
(Internal evaluation) - 20 marks (Viva-voce includes questions on the following
aspects of the problem attempted by the student: the
Terminal Evaluation algorithm and implementation strategy,
Solution to programming problem on the computer documentation, correctness, alternative algorithms or
implementations. Questions should be confined largely
- 60 marks to the problem the student has attempted).

224
CLASS XII

There will be two papers in the subject: simplification rules for ∧, ∨. Converse,
Paper I: Theory- 3 hours …100 marks inverse and contra positive. Chain
rule(Modus ponen).
Paper II: Practical- 3 hours …100 marks
p∨p≡p p∧p≡p
PAPER I-THEORY
p ∨ true ≡ true p ∧ true ≡ p
Paper 1 shall be of 3 hours duration and be divided
into two parts. p ∨ false ≡ p p ∧ false ≡ false
Part I (30 marks): This part will consist of
compulsory short answer questions, testing p ∨ (p ∧ q) ≡ p p ∧ (p ∨ q) ≡ p
knowledge, application and skills relating to the entire The equivalence rules can be used to simplify
syllabus. propositional wffs, for example:
Part II (70 marks): This part will be divided into
three Sections, A, B and C. Candidates are required to 1) (p ⇒ q) ∧ (p ⇒ r) to p ⇒ (q ∧ r)
answer three questions out of four from Section A and
two questions out of three in each of the Sections 2) ((p ⇒ q) ∧ p) ⇒ q to true
B and C. Each question in this part shall carry etc.
10 marks.
(b) Binary valued quantities; basic postulates of
SECTION A Boolean algebra; operations AND, OR and
1. Boolean Algebra NOT; truth tables.
(a) Propositional logic, well formed formulae, (c) Basic theorems of Boolean algebra
truth values and interpretation of well formed (e.g. Duality, idempotence, commutativity,
formulae (wff), truth tables, satisfiable, associativity, distributivity, operations with 0
unsatisfiable and valid formulae. Equivalence and 1, complements, absorption, involution);
laws and their use in simplifying wffs. De Morgan’s theorem and its applications;
reducing Boolean expressions to sum of
Propositional variables; the common logical products and product of sums forms;
connectives (~ (not)(negation), ∧ Karnaugh maps (up to four variables).
(and)(conjunction), ∨ (or)(disjunction), ⇒ Verify the laws of boolean algebra using truth
(implication), ⇔ (biconditional); definition of tables. Inputs, outputs for circuits like half and
a well-formed formula (wff); representation of full adders, majority circuit etc., SOP and POS
simple word problems as wff (this can be used representation; Maxterms & Minterms, Canonical
for motivation); the values true and false; and Cardinal representation, reduction using
Karnaugh maps and boolean algebra.
interpretation of a wff; truth tables;
satisfiable, unsatisfiable and valid formulae. 2. Computer Hardware

Equivalence laws: commutativity of ∧, ∨; (a) Elementary logic gates (NOT, AND, OR,
NAND, NOR, XOR, XNOR) and their use in
associativity of ∧, ∨; distributivity; de
circuits.
Morgan’s laws; law of implication (p ⇒ q ≡
~p ∨ q); law of biconditional ((p ⇔ q) ≡ (b) Applications of Boolean algebra and logic
(p ⇒ q) ∧ (q ⇒ p)); identity (p ≡ p); law of gates to half adders, full adders, encoders,
negation (~ (~p) ≡ p); law of excluded middle decoders, multiplexers, NAND, NOR as
universal gates.
(p ∨~p ≡ true); law of contradiction (p∧~p ≡
false); tautology and contingency
225
Show the correspondence between boolean (b) Analysis of some real world programming
functions and the corresponding switching examples in terms of objects and classes.
circuits or gates. Show that NAND and NOR gates
are universal by converting some circuits to Use simple examples like a calculator, date,
purely NAND or NOR gates. number, etc. to illustrate how they can be
treated as objects that behave in certain well-
SECTION B
defined ways and how the interface provides a
The programming element in the syllabus (Sections B way to access behaviour. Illustrate behaviour
and C) is aimed at algorithmic problem solving and
changes by adding new functions, deleting old
not merely rote learning of Java syntax. The Java
version used should be 1.5 or later. For programming, functions or modifying existing functions.
the students can use any text editor and the javac and
java programs or any development environment: for 6. Primitive values, wrapper classes, types and
example, BlueJ, Eclipse, NetBeans etc. BlueJ is casting
strongly recommended for its simplicity, ease of use
and because it is very well suited for an ‘objects first’ Primitive values and types: int, short, long, float,
approach. double, boolean, char. Corresponding wrapper
classes for each primitive type. Class as type of
3. Implementation of algorithms to solve the object. Class as mechanism for user defined
problems types. Changing types through user defined
The students are required to do lab assignments in casting and automatic type coercion for some
the computer lab concurrently with the lectures. primitive types.
Programming assignments should be done such
Ideally, everything should be a class; primitive
that each major topic is covered in at least one
assignment. Assignment problems should be types are defined for efficiency reasons; each
designed so that they are non-trivial and make the primitive type has a corresponding wrapper class.
student do algorithm design, address correctness Classes as user defined types. In some cases types
issues, implement and execute the algorithm in are changed by automatic coercion or casting –
Java and debug where necessary. e.g. mixed type expressions. However, casting in
Self explanatory. general is not a good idea and should be avoided,
if possible.
4. Programming in Java (Review of Class XI
Sections B and C) 7. Variables, expressions
Note that items 4 to 8 will get introduced almost
Variables as names for values; expressions
simultaneously when classes and their definitions
are introduced. (arithmetic and logical) and their evaluation
(operators, associativity, precedence). Assignment
5. Objects operation; difference between left hand side and
right hand side of assignment.
(a) Objects as data (attributes) + behaviour
(methods or functions); object as an instance Variables denote values; variables are already
of a class. Constructors. defined as attributes in classes; variables have
Difference between object and class should be types that constrain the values it can denote.
made very clear. BlueJ (www.bluej.org) and Difference between variables denoting primitive
Greenfoot (www.greenfoot.org) can be values and object values – variables denoting
profitably used for this purpose. Constructor objects are references to those objects. The
as a special kind of function; the new
assignment operator = is special. The variable on
operator; multiple constructors with different
argument structures; constructor returns a the lhs of = denotes the memory location while the
reference to the object. same variable on the rhs denotes the contents of
the location e.g. i=i+2.
226
8. Statements, scope between primitive values and object values as
arguments (changes made inside functions persist
Statements; conditional (if, if-then-else, switch- after the call for object values). Static definitions
break, ?: ternary operator), looping (for, while-do, as class variables and class functions visible and
do-while, continue, break); grouping statements in shared by all instances. Need for static functions
blocks, scope and visibility of variables. and variables. Introduce the main method –
Describe the semantics of the conditional and needed to begin execution.
looping statements in detail. Evaluation of the
condition in conditional statements (esp. 10. Arrays, strings
difference between || and | and && and &). (a) Structured data types – arrays (single and
Emphasize fall through in switch statement. Many multi-dimensional), strings. Example
small examples should be done to illustrate algorithms that use structured data types (e.g.
control structures. Printing different kinds of searching, finding maximum/minimum,
patterns for looping is instructive. When number sorting techniques, solving systems of linear
of iterations are known in advance use the for equations, substring, concatenation, length,
loop otherwise the while-do or do-while loop. access to char in string, etc.).
Express one loop construct using the others. For Storing many data elements of the same type
e.g.: requires structured data types – like arrays.
for (<init>; <test>; <inc>) <stmt>; is equivalent Access in arrays is constant time and does not
to: depend on the number of elements. Sorting
techniques (bubble, selection, insertion).
Using while Structured data types can be defined by
<init>; while <test> {<stmt>; <inc> } classes – String. Introduce the Java library
String class and the basic operations on
Using do-while strings (accessing individual characters,
<init>; if !<test> do <stmt>; <inc> while <test>; various substring operations, concatenation,
replacement, index of operations). The Class
Nesting of blocks. Variables with block scope, StringBuffer should be introduced for those
function scope, class scope. Visibility rules when applications that involve heavy manipulation
variables with the same name are defined in of strings.
different scopes. (b) Basic concept of a virtual machine; Java
virtual machine; compilation and execution of
9. Functions Java programs (the javac and java programs).
Functions/methods (as abstractions for complex The JVM is a machine but built as a program
user defined operations on objects), functions as and not through hardware. Therefore it is
mechanisms for side effects; formal arguments called a virtual machine. To run, JVM
and actual arguments in functions; different machine language programs require an
behaviour of primitive and object arguments. interpreter (the java program). The advantage
Static functions and variables. The this variable. is that such JVM machine language programs
Examples of algorithmic problem solving using (.class files) are portable and can run on any
functions (various number theoretic problems, machine that has the java program.
finding roots of algebraic equations). (c) Compile time and run time errors; basic
Functions are like complex operations where the concept of an exception, the Exception class,
object is implicitly the first argument. Variable catch and throw.
this denotes the current object. Functions Differentiate between compile time and run
typically return values, they may also cause side- time errors. Run time errors crash the
effects (e.g. change attribute values of objects) – program. Recovery is possible by the use of
typically functions that are only supposed to cause exceptions. Explain how an exception object
side-effects return void (e.g. Set functions). Java is created and passed up until a matching
passes argument by value. Illustrate the difference catch is found. This behaviour is different
227
from the one where a value is returned by a meaningful in the application program – e.g.
deeply nested function call. It is enough to words in a sentence where the delimiter is the
discuss the Exception class. Sub-classes of blank character). This naturally leads to the
Exception can be discussed after inheritance idea of delimiters and in particular
has been done in Class XII. whitespace and user defined characters as
(d) Class as a contract; separating implementation delimiters. As an example show how the
from interface; encapsulation; private and StringTokenizer class allows one to extract a
public. sequence of tokens from a string with user
defined delimiters.
Class is the basic reusable unit. Its function
prototypes (i.e. the interface) work as a visible (g) Concept of recursion, simple recursive
contract with the outside world since others functions (e.g. factorial, GCD, binary search,
will use these functions in their programs. conversion of representations of numbers
This leads to encapsulation (i.e. hiding between different bases). Recursive sorting
implementation information) which in turn techniques.
leads to the use of private and public for Many problems can be solved very elegantly
realizing encapsulation. by observing that the solution can be
(e) Interfaces in Java; implementing interfaces composed of solutions to ‘smaller’ versions of
through a class; interfaces for user defined the same problem with the base version
implementation of behaviour. having a known simple solution. Recursion
can be initially motivated by using recursive
Motivation for interface: often when creating equations to define certain functions. These
reusable classes, some parts of the exact definitions are fairly obvious and are easy to
implementation can only be provided by the understand. The definitions can be directly
final end user. For example, in a class that converted to a program. Emphasize that any
sorts records of different types the exact recursion must have a base case. Otherwise,
comparison operation can only be provided the computation can go into an infinite loop.
by the end user. Since only he/she knows Illustrate this by removing the base case and
which field(s) will be used for doing the running the program. Examples:
comparison and whether sorting should be in
ascending or descending order be given by (i) Definition of factorial:
the user of the class. factorial(0) = 1 //base case
Emphasize the difference between the Java factorial(n) = n * factorial(n-1)
language construct interface and the word (ii) Definition of GCD:
interface often used to describe the set of
function prototypes of a class. gcd(m, n) =
(e) Basic input/output using Scanner and Printer if (m==n) then n //base case
classes from JDK; files and their else if (m>n) then gcd(m-n, n)
representation using the File class, file else gcd(m, n-m)
input/output; input/output exceptions. Tokens
in an input stream, concept of whitespace, (iii) Definition of Fibonacci numbers:
extracting tokens from an input stream fib(0) = 1 //base case
(StringTokenizer class). fib(1) = 1 //base case
The Scanner class can be used for input of fib(n) = fib(n-1)+ fib(n-2)
various types of data (e.g. int, float, char etc.)
from the standard input stream or a file input The tower of Hanoi is a very good example of
stream. The File class is used model file how recursion gives a very simple and elegant
objects in the underlying system in an OS solution where as non-recursive solutions are
independent manner. Similarly, the Printer quite complex. Discuss the use of a stack to
class handles output. Only basic input and keep track of function calls. A stack can also
output using these classes should be covered. be used to solve the tower of Hanoi problem
Discuss the concept of a token (a delimited non-recursively. Merge sort and Quick sort on
continuous stream of characters that is arrays.
228
SECTION C 12. Data structures
Inheritance, polymorphism, data structures, (a) Basic data structures (stack, queue, dequeue);
computational complexity implementation directly through classes;
definition through an interface and multiple
11. Inheritance and polymorphism
implementations by implementing the
Inheritance; base and derived classes; member interface. Basic algorithms and programs
access in derived classes; redefinition of variables using the above data structures.
and functions in subclasses; abstract classes; class
A data structure is a data collection with well
Object; protected visibility. Subclass
defined operations and behaviour or
polymorphism and dynamic binding.
properties. The behaviour or properties can
Emphasize the following: usually be expressed formally using equations
- inheritance as a mechanism to reuse a class or some kind of logical formulae. Consider
by extending it. for e.g. a stack with operations defined as
follows:
- inheritance should not normally be used just
to reuse some functions defined in a class but void push(Object o)
only when there is a genuine specialization Object pop()
(or subclass) relationship between objects of
boolean isEmpty()
the base class and that of the derived class.
Object top()
- Allows one to implement operations at the
highest relevant level of abstraction. Then, for example the LIFO property can be
expressed by (assume s is a stack):
- Freezes the interface in the form of abstract
if s.push(o); o1=pop() then o ≡ o1
classes with abstract functions that can be
extended by the concrete implementing What the rule says is: if o is pushed on the
classes. For example, an abstract class Shape stack s and then it is popped and o1 is the
can have an abstract function draw that is object obtained then o, o1 are identical.
implemented differently in the sub-classes like Another useful property is:
Circle, Quadrilateral etc.
if s.isEmpty() == true then s.pop() = ERROR
- how the exact function call at run time It says that popping an empty stack gives
depends on the type of the object referenced ERROR.
by the variable. This gives sub-class
polymorphism. For example in the code Similarly, several other properties can also be
fragment: specified. It is important to emphasize the
behavioural rules or properties of a data
Shape s1=new Circle(), s2=new structure since any implementation must
Quadrilateral(); guarantee that the rules hold.
s1.draw(); //the draw is the draw in Circle Some simple algorithms that use the data
structures:
s2.draw(); //the draw is the draw in
Quadrilateral (i) For stack: parentheses matching, tower of
Hanoi, nested function calls; solving a
the two draw function invocations on s1, s2 maze.
invoke different draw functions depending on
the type of objects referenced by s1 and s2 (ii) For queue: scheduling processes,
respectively. printers, jobs in a machine shop.

229
(b) Recursive data structures: single linked (iii) This is done by trying to approximate the
list (Algorithm and programming), binary number of operations done by each algorithm
trees, tree traversals (Conceptual) as a function of the size of the input. In most
programs the loops are important in deciding
Data structures should be defined as
the complexity. For example in bubble sort
abstract data types with a well defined
there are two nested loops and in the worst
interface (it is instructive to define them
case the time taken will be proportional to
using the Java interface construct) – see the
n(n-1) where n is the number of elements to be
comments in (a) above. Emphasize that
sorted. Similarly, in linear search in the worst
algorithms for recursive data structures are
case the target has to be compared with all
themselves recursive and that algorithms are
the elements so time taken will be
usually the simplest and most elegant. The
proportional to n where n is the number of
following should be covered for each data
elements in the search set.
structure:
(iv) In most algorithms the actual complexity for a
Linked List (single): insertion, deletion,
particular input can vary. For example in
reversal, extracting an element or a sublist,
search the number of comparisons can vary
checking emptiness.
from 1 to n. This means we need to study the
Binary trees: apart from the definition the best, worst and average cases. Comparisons
following concepts should be covered: are usually made taking the worst case.
external and internal nodes, height, level, Average cases are harder to estimate since it
size, degree, completeness, balancing, depends on how the data is distributed. For
Traversals (pre, post and in-order). example in search, if the elements are
uniformly distributed it will take on the
13. Complexity and big O notation average n/2 comparisons when the average is
Concrete computational complexity; concept of taken over a statistically significant number of
input size; estimating complexity in terms of instances.
functions; importance of dominant term; best, (v) Comparisons are normally made for large
average and worst case. Big O notation for values of the input size. This means that the
computational complexity; analysis of complexity dominant term in the function is the important
of example algorithms using the big O notation term. For example if we are looking at bubble
(e.g. Various searching and sorting algorithms, sort and see that time taken can be estimated
algorithm for solution of linear equations etc.). as: a*n2 +b*n + c where n is the number of
Points to be given particular emphasis: elements to be sorted and a, b, c are constants
then for large n the dominant term is clearly
(i) Algorithms are usually compared along two n2 and we can, in effect, ignore the other two
dimensions – amount of space (that is terms.
memory) used and the time taken. Of the two
the time taken is usually considered the more All the above motivates the big O notation. Let
important. The motivation to study time f(n), g(n) be positive functions, then f(n) is said to
complexity is to compare different algorithms be O(g(n)) if there exists constants c, n0 such that
and use the one that is the most efficient in a f(x)≤ c*g(n) whenever n>n0. What this means is
particular situation. that g(n) asymptotically dominates f(n).
Expressing time complexity using the big O
(ii) Actual run time on a particular computer is notation gives us an abstract basis for comparison
not a good basis for comparison since it and frees us from bothering about constants. So
depends heavily on the speed of the computer, the estimated time complexity a*n2+b*n+c is
the total amount of RAM in the computer, the O(n2).
OS running on the system and the quality of
the compiler used. So we need a more Analyse the big O complexity of the algorithms
abstract way to compare the time complexity pertaining to the data structures in 11 (a) and (b)
of algorithms. above.
230
PAPER II - PRACTICAL Marks (out of a total of 100) should be distributed as
given below:
This paper of three hours duration will be evaluated
by the Visiting Examiner appointed locally and
Continuous Evaluation
approved by the Council.
Candidates will be required to submit a work file
The paper shall consist of three programming containing the practical work related to programming
problems from which a candidate has to attempt any assignments done during the year.
one. The practical consists of the two parts:
Programming assignments done throughout the year
1. Planning Session (Internal evaluation) - 10 marks
2. Examination Session Programming assignments done throughout the year
The total time to be spent on the Planning session and (Visiting Examiner) - 10 marks
the Examination session is three hours. After
completing the Planning session the candidates may Terminal Evaluation
begin with the Examination session. A maximum of Solution to programming problem on the computer
90 minutes is permitted for the Planning session. - 60 marks
However, if the candidates finish earlier, they are to
(Marks should be given for choice of algorithm and
be permitted to begin with the Examination session.
implementation strategy, documentation, correct output
on known inputs mentioned in the question paper,
Planning Session correct output for unknown inputs available only to the
The candidates will be required to prepare an examiner.)
algorithm and a hand written Java program to solve Viva-voce - 20 marks
the problem.
(Viva-voce includes questions on the following
Examination Session aspects of the problem attempted by the student: the
algorithm and implementation strategy,
The program handed in at the end of the Planning documentation, correctness, alternative algorithms or
session shall be returned to the candidates. The implementations. Questions should be confined
candidates will be required to key-in and execute the largely to the problem the student has attempted).
Java program on seen and unseen inputs individually
NOTE:
on the Computer and show execution to the Visiting
Examiner. A printout of the program listing including Algorithm should be expressed clearly using any
output results should be attached to the answer script standard scheme such as a pseudo code.
containing the algorithm and handwritten program.
This should be returned to the examiner. The program EQUIPMENT
should be sufficiently documented so that the
algorithm, representation and development process is There should be enough computers to provide for a
clear from reading the program. Large differences teaching schedule where at least three-fourths of the
between the planned program and the printout will time available is used for programming.
result in loss of marks. Schools should have equipment/platforms such that all
Teachers should maintain a record of all the the software required for practical work runs properly,
assignments done as part of the practical work through i.e. it should run at acceptable speeds.
the year and give it due credit at the time of Since hardware and software evolve and change very
cumulative evaluation at the end of the year. Students rapidly, the schools may have to upgrade them as
are expected to do a minimum of twenty assignments required. Following are the recommended
for the year. specifications as of now:

231
The Facilities: run the operating system and Java programming
system (Java compiler, Java runtime environment,
 A lecture cum demonstration room with a
Java development environment) at acceptable
MULTIMEDIA PROJECTOR/ an LCD and
speeds.
O.H.P. attached to the computer.
 Good Quality printers.
 A white board with white board markers should
be available. Software:
 A fully equipped Computer Laboratory that  Any suitable Operating System can be used.
allows one computer per student.  JDK 6 or later.
 Internet connection for accessing the World Wide  Documentation for the JDK version being used.
Web and email facility.
 A suitable text editor. A development
 The computers should have a minimum of 512 environment with a debugger is preferred (e.g.
MB (1 GB preferred) RAM and a PIV or higher BlueJ, Eclipse, NetBeans). BlueJ is recommended
processor. The basic requirement is that it should for its ease of use and simplicity.

232
SAMPLE TABLE FOR PRACTICAL WORK
Assessment of Practical Assessment of the Practical Examination TOTAL
File (To be evaluated by the Visiting Examiner only) MARKS (Total
Unique Internal Visiting Algorithm Java Documentation Hard Output Viva- Marks are to be
Identification Evaluation Examiner Program Copy Voce added and
S. Number (printout) entered by the
No. (Unique ID)/ Visiting
Index Number Examiner)
of the candidate
10 20 100 Marks
10 Marks 10 Marks 10 Marks 20 Marks 10 Marks 10 Marks Marks Marks
1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Name of the Visiting Examiner:_________________________________

Signature: _______________________________

Date:___________________________________

233

You might also like