Tamil Nadu HSE Second Year Computer Science cheat sheet
Tamil Nadu HSE Second Year Computer Science · Keep the key ideas within reach.
Fundamentals of Computers and Number Systems
Decimal to binary: divide repeatedly by 2, collect remainders bottom-to-top; binary to decimal: sum bit × 2^position, positions counted from 0 at the right.
Octal groups 3 binary bits, hexadecimal groups 4 binary bits; 1 hex digit = 4 bits, so 2 hex digits = 1 byte.
Binary addition rules: 0+0=0, 0+1=1, 1+1=10 (write 0, carry 1), 1+1+1=11 (write 1, carry 1).
1's complement = flip all bits; 2's complement = 1's complement + 1. Subtraction A−B is done as A + 2's complement of B, discarding the final carry.
An n-bit 2's complement range is −2^(n−1) to +2^(n−1) − 1; for 8 bits that is −128 to +127.
Memory units ascend by 1024: 1 KB = 1024 B, 1 MB = 1024 KB, 1 GB = 1024 MB, 1 TB = 1024 GB.
Logic gate outputs: AND = 1 only if all inputs 1; OR = 1 if any input 1; NOT inverts; NAND and NOR are the inverted forms of AND and OR; XOR = 1 when inputs differ.
Von Neumann architecture: CPU (ALU + control unit + registers), memory, input and output units, joined by a bus; instructions and data share the same memory.
Data Structures: Lists, Stacks and Queues
Stack is LIFO: push adds at the top, pop removes from the top, peek/top reads the top without removing it; all three are O(1).
Queue is FIFO: enqueue adds at the rear, dequeue removes from the front; a circular queue avoids the false-full condition of a linear array queue.
Stack overflow occurs on push to a full stack; stack underflow occurs on pop or peek from an empty stack.
Infix to postfix uses a stack for operators: operand goes straight to output, higher precedence is popped before lower, and parentheses are matched explicitly.
Postfix evaluation uses an operand stack: push numbers, and on an operator pop two operands, apply, and push the result.
Python list operations and costs: append is amortised O(1), insert at position i is O(n), pop() from the end is O(1), pop(0) is O(n).
Linked list versus array: a linked list gives O(1) insertion and deletion at a known node but O(n) access by index; an array gives O(1) index access but O(n) shifting on insert or delete.
Queue applications include printer job scheduling, CPU round-robin scheduling and breadth-first search; stack applications include function call frames, undo history and bracket matching.
Object-Oriented Programming in Python
A class is a blueprint; an object is an instance. init runs automatically when an instance is created, and self refers to that instance.
Instance attributes are set through self.name inside methods; class attributes are defined in the class body and are shared by all instances.
Encapsulation hides state: a name with two leading underscores (__x) is name-mangled to _ClassName__x, which is Python's privacy convention, not true enforcement.
Inheritance: class Child(Parent) reuses the parent's methods; super().init(...) calls the parent constructor; the MRO (method resolution order) decides which method wins.
Polymorphism means the same method name behaves differently per class; overriding redefines a parent method in the child, while overloading by argument count is not native to Python.
A constructor is init and a destructor is del; del is not guaranteed to run at a predictable time because garbage collection decides.
Dunder methods customise behaviour: str for print, len for len(), eq for ==, add for +.
Abstraction is achieved with the abc module: a class inheriting ABC with an @abstractmethod cannot be instantiated until the method is overridden.
Database Management Systems and SQL
A relation is a table, a tuple is a row, an attribute is a column, and the degree is the number of attributes while cardinality is the number of tuples.
A primary key is unique and NOT NULL; a foreign key references a primary key in another table and enforces referential integrity.
Candidate key: any minimal set of attributes that uniquely identifies a row; one candidate is chosen as the primary key.
SQL command groups: DDL (CREATE, ALTER, DROP), DML (INSERT, UPDATE, DELETE), DQL (SELECT), DCL (GRANT, REVOKE), TCL (COMMIT, ROLLBACK, SAVEPOINT).
SELECT clause order is written SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY, but executes FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY.
WHERE filters rows before grouping; HAVING filters groups after GROUP BY and may contain aggregate functions such as COUNT, SUM, AVG, MIN, MAX.
Joins: INNER returns matching rows only, LEFT returns all left rows plus matches, RIGHT mirrors it, FULL returns all rows from both sides.
Normalisation: 1NF removes repeating groups (atomic values), 2NF removes partial dependency on part of a composite key, 3NF removes transitive dependency on non-key attributes.
Computer Networks and Internet Concepts
OSI has 7 layers bottom-up: Physical, Data Link, Network, Transport, Session, Presentation, Application; TCP/IP collapses these into 4 layers.
Protocol-to-layer mapping: IP is Network layer, TCP and UDP are Transport, HTTP, FTP, SMTP and DNS are Application layer.
TCP is connection-oriented and reliable (handshake, acknowledgements, retransmission); UDP is connectionless and faster but unreliable.
IPv4 addresses are 32 bits written as four dotted decimal octets; IPv6 is 128 bits written in hexadecimal groups.
Private IPv4 ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16; a subnet mask separates the network and host portions.
DNS maps domain names to IP addresses; DHCP assigns IP addresses dynamically; ARP maps an IP address to a MAC address.
Topologies: star fails gracefully per node but depends on the central hub; bus shares one backbone; ring passes data in one direction; mesh gives redundant paths at high cabling cost.
Switching versus routing: a switch forwards frames by MAC address at layer 2; a router forwards packets by IP address at layer 3.
Web Technologies: HTML, CSS and JavaScript
HTML document skeleton: , , (title, meta, link) and (visible content).
Block elements (div, p, h1-h6, ul, table) start on a new line; inline elements (span, a, img, strong, em) do not.
Ordered list is
- , unordered is
- , description list is with term and definition; text creates a link.
- , unordered is
CSS specificity order, low to high: element selector < class selector < id selector < inline style; !important overrides all normal declarations.
CSS box model from inside out: content, padding, border, margin; box-sizing: border-box makes width include padding and border.
JavaScript variable declarations: var is function-scoped and hoisted, let is block-scoped and reassignable, const is block-scoped and not reassignable.
DOM access and events: document.getElementById, querySelector, addEventListener('click', fn); == compares after type coercion while === compares value and type.
Python Programming and File Handling
Mutable versus immutable: list, dict and set are mutable; int, float, str and tuple are immutable, so string methods return a new string.
Slicing s[start:stop:step] excludes stop; a negative index counts from the end, so s[-1] is the last character.
File open modes: 'r' read, 'w' write (truncates), 'a' append, 'x' create, 'r+' read and write, 'rb' binary; the with statement closes the file automatically.
Reading methods: read() returns the whole content, readline() returns one line, readlines() returns a list of lines; write() writes a string, writelines() writes an iterable of strings.
Exception handling: try runs code, except catches a named exception, else runs when no exception occurs, finally always runs.
Common exceptions: ZeroDivisionError, ValueError, TypeError, IndexError, KeyError, FileNotFoundError.
String formatting: f"{name} scored {marks}" and "{}".format(x) both substitute values; int(), float() and str() perform explicit type conversion.
Functions: def name(params): with return; default arguments follow non-default ones; *args collects extra positional arguments and **kwargs collects keyword arguments.
Problem Solving, Algorithms and Ethics in Computing
Algorithm properties: finiteness, definiteness, input, output and effectiveness; a flowchart uses oval for start/end, parallelogram for input/output, diamond for decision, rectangle for process.
Searching: linear search is O(n) and needs no ordering; binary search is O(log n) but requires a sorted array.
Sorting costs: bubble, selection and insertion sort are O(n^2); merge sort and quick sort average O(n log n), with quick sort worst case O(n^2).
Recursion needs a base case to stop and a recursive case that moves toward it; each call adds a frame to the call stack.
Time complexity counts dominant operations as input grows; constants are dropped, so 3n + 5 is O(n) and n^2 + n is O(n^2).
Ethics in computing: do not plagiarise code, respect software licences (proprietary versus open source), protect user data, avoid unauthorised access, and report vulnerabilities responsibly.
Cyber offences under Indian law include unauthorised access, data theft and identity fraud, addressed by the Information Technology Act, 2000; intellectual property is protected by copyright and patents.
Digital divide and accessibility: inclusive design (contrast, alt text, keyboard navigation) and awareness of unequal access to technology are part of ethical practice.