iExamWorld
Notes

PGT Computer Science: Key Topics and Formulas

English · Free on iExamWorld

PGT Computer Science: what to prepare

PGT Computer Science papers for KVS, NVS, DSSSB and EMRS follow the CBSE class 11–12 Computer Science syllabus (Python based), extended to graduate-level basics of data structures, DBMS, networking and digital logic. A large share of questions ask for the output of a short Python snippet, so knowing exact language behaviour is essential.

1. Python fundamentals

Operators

  • / always returns a float: 7/2 gives 3.5
  • // is floor division, rounding towards negative infinity: 7//2 is 3, −7//2 is −4
  • % takes the sign of the divisor: −7 % 2 is 1
  • ** is exponentiation and is right-associative: 2**3**2 is 2**9 = 512
  • and/or return one of their operands, not necessarily True or False: 0 or 5 gives 5

Mutable and immutable types

TypeMutable?Ordered?Example
int, float, strNostr is ordered"abc"
tupleNoYes(1, 2)
listYesYes[1, 2]
dictYesInsertion-ordered (Python 3.7+){"a": 1}
setYesNo{1, 2}

A tuple cannot be changed, but a mutable object stored inside it can: t = (1, [2]); t[1].append(3) works. Only immutable (hashable) objects can be dictionary keys or set members.

Aliasing and copying

Assignment never copies. After L2 = L, both names refer to the same list, so changes through one are seen through the other. L[:], list(L) and L.copy() make shallow copies; copy.deepcopy makes an independent copy of nested structures.

Strings and slicing

Slicing s[start:stop:step] excludes stop. A negative step walks backwards: s[::-1] reverses a string, and "Python"[::-2] gives "nhy". Useful methods: upper(), lower(), title(), strip(), split(), join(), find() (returns −1 if absent) and index() (raises ValueError if absent), count() and replace().

Functions

  • Default argument values are evaluated once, at definition time; a mutable default such as L=[] is shared between calls
  • Positional arguments must come before keyword arguments in a call
  • A function without a return statement returns None
  • The LEGB rule resolves names: Local, Enclosing, Global, Built-in; use global to rebind a global name inside a function

List and dictionary methods

append() adds one element at the end, extend() adds each element of an iterable, and insert(i, x) places x before index i. pop() removes and returns the last element (or the one at a given index), remove(x) deletes the first occurrence of a value, and sort() sorts in place and returns None, whereas sorted() returns a new list. For dictionaries, keys(), values() and items() return view objects; update() merges another dictionary; and d.get(k, default) returns the default instead of raising KeyError. List comprehensions such as [x**2 for x in range(5) if x % 2 == 0] give [0, 4, 16].

File handling and exceptions

Mode "r" reads (error if the file is missing), "w" creates or truncates, "a" appends, and adding "b" gives binary mode. read() returns the whole file as a string, readline() one line and readlines() a list of lines. The pickle module (dump and load) stores Python objects in binary files; the csv module provides reader and writer objects. In try–except–else–finally, the else block runs only if no exception occurred and finally always runs.

2. Data structures

Stack and queue

A stack is LIFO, implemented in Python with append() for push and pop() for pop. Stacks are used for function calls, undo operations, expression conversion and postfix evaluation. A queue is FIFO; collections.deque gives efficient insertion and removal at both ends.

Expression conversion

Operators of higher precedence are written first in postfix. A + B * C becomes A B C * +, and (A + B) * C becomes A B + C *. To evaluate postfix, scan left to right, push operands, and on each operator pop two values (the second popped is the left operand), apply the operator and push the result. For example 6 2 3 + * 4 − evaluates to 26.

Searching and sorting

AlgorithmBest caseWorst case
Linear searchO(1)O(n)
Binary search (sorted data)O(1)O(log n)
Bubble sortO(n) with early exitO(n²)
Insertion sortO(n)O(n²)
Selection sortO(n²)O(n²)
Merge sortO(n log n)O(n log n)

Binary search on n sorted items needs at most ⌊log₂ n⌋ + 1 comparisons, so 11 for 1024 items.

3. Database concepts and SQL

In the relational model a table is a relation, a row a tuple and a column an attribute. Degree is the number of attributes; cardinality is the number of tuples. A candidate key uniquely identifies tuples; the one chosen is the primary key and the rest are alternate keys. A foreign key refers to a key in another table and enforces referential integrity.

SQL command groups

  • DDL: CREATE, ALTER, DROP
  • DML: INSERT, UPDATE, DELETE, SELECT
  • DCL: GRANT, REVOKE; TCL: COMMIT, ROLLBACK, SAVEPOINT

Points that are tested repeatedly

  • WHERE filters rows before grouping; HAVING filters groups after GROUP BY
  • COUNT(*) counts all rows; COUNT(column) and the other aggregates ignore NULL values
  • NULL is tested with IS NULL, never with = NULL
  • LIKE uses % for any number of characters and _ for exactly one character
  • BETWEEN is inclusive of both limits
  • DELETE removes rows (structure remains); DROP removes the table itself
  • A Cartesian product of tables with m and n rows has m × n rows and the sum of their degrees as its degree
  • An equi-join compares columns with =; a natural join also removes the duplicate common column

Python connects to MySQL through a connector module: create a connection, obtain a cursor, call execute(), then fetchone(), fetchall() or fetchmany(), and commit() after changes.

4. Computer networks

OSI layerFunctionDevice / protocol
Physical (1)Transmission of raw bitsHub, repeater
Data link (2)Framing, MAC addressingSwitch, bridge
Network (3)Logical addressing, routingRouter, IP
Transport (4)End-to-end deliveryTCP, UDP
Application (7)User servicesHTTP, FTP, SMTP, DNS

IPv4 addresses are 32 bits; IPv6 addresses are 128 bits; a MAC address is 48 bits. A Class C network (default mask 255.255.255.0) has 254 usable host addresses. TCP is connection-oriented and reliable; UDP is connectionless and faster. Network topologies include bus, star, ring, mesh and tree; star is the most common in LANs. Common ports: HTTP 80, HTTPS 443, FTP 21, SMTP 25.

5. Boolean algebra and number systems

  • Absorption: A + AB = A and A(A + B) = A
  • A + A′B = A + B
  • De Morgan: (A + B)′ = A′B′ and (AB)′ = A′ + B′
  • NAND and NOR are universal gates; XOR gives 1 when the inputs differ
  • A K-map for n variables has 2ⁿ cells; groups must contain 1, 2, 4, 8 … cells

To convert to decimal, multiply each digit by the base raised to its position: (156)₈ = 64 + 40 + 6 = 110 and (101101)₂ = 45. Group binary digits in threes for octal and fours for hexadecimal. The 2's complement of a binary number is its 1's complement plus 1 and is used to represent negative integers.

Quick revision points

  • // floors towards negative infinity: −7//2 is −4.
  • Assignment creates an alias, not a copy.
  • Mutable default arguments are shared between calls.
  • Tuples are immutable, but their mutable elements can change.
  • dict.get(key, default) never raises KeyError.
  • Stack is LIFO, queue is FIFO.
  • A + B * C in postfix is A B C * +.
  • Binary search is O(log n) and needs sorted data.
  • Degree = columns; cardinality = rows.
  • HAVING filters groups; WHERE filters rows.
  • Aggregates other than COUNT(*) ignore NULL.
  • Routers work at the network layer.
  • IPv4 32 bits, IPv6 128 bits, MAC 48 bits.
  • A + A′B = A + B.
  • NAND and NOR are universal gates.

These notes were written with AI assistance for iExamWorld, based on the official syllabus. Spotted a mistake? Tell us.