CS Fundamentals Cheat Sheet

Everything the Zoho Round 2 MCQs keep coming back to, in six subjects. Read one subject, then do a 10-question set on it. The orange boxes are the traps that wrong options are built from.

Operating Systemsthe manager between programs and hardware

Basic words

TermMeaning
ProgramCode saved on disk, not running
ProcessA program while it runs. Has its own memory. Described by a PCB (Process Control Block: ID, state, registers, priority)
ThreadSmallest unit of CPU work, inside a process. Threads of one process share its memory
KernelCore of the OS; runs with full control of the hardware
System callHow a program asks the kernel for a service (e.g. fork(), read())
Context switchSaving one process's state and loading another's. Pure overhead
ShellThe command-line interface to the OS (bash, zsh)

Process states

New → Ready → Running → Waiting (Blocked) → Ready … → Terminated

CPU scheduling

AlgorithmRuleNote
FCFSFirst come, first servedNon-preemptive. Convoy effect (short jobs stuck behind a long one)
SJFShortest job firstMinimum average waiting time. Can starve long jobs
SRTFShortest remaining time firstPreemptive version of SJF
PriorityHighest priority firstStarvation, fixed by aging (raise priority over time)
Round RobinEach gets a fixed time quantum in turnPreemptive, fair, used in time-sharing systems

Deadlock

Two or more processes each waiting for a resource another holds, forever. All four conditions must hold together (Coffman):

  1. Mutual exclusion: a resource can be held by one process only
  2. Hold and wait: holding one, waiting for another
  3. No preemption: a resource can't be taken away
  4. Circular wait: P1 waits for P2, P2 waits for P1

Synchronization

Memory

TermMeaning
PagingMemory split into fixed-size pages (logical) and frames (physical). Causes internal fragmentation, no external
SegmentationVariable-size pieces by meaning (code, stack). Causes external fragmentation
Virtual memoryUses disk as extra RAM, so programs bigger than RAM can run
Page faultThe page needed is not in RAM; OS loads it from disk
ThrashingSo many page faults the CPU does almost no real work
TLBFast cache for page-table lookups

Page replacement: FIFO (oldest out; suffers Belady's anomaly: more frames can give more faults), LRU (least recently used out), Optimal (replace the page used furthest in future; best but impossible in practice, used as a benchmark).

Allocation: First fit (first hole big enough), Best fit (smallest hole that fits), Worst fit (largest hole).

Disk scheduling

FCFS, SSTF (nearest track first), SCAN (elevator, goes end to end), C-SCAN (one direction, jumps back), LOOK / C-LOOK (like SCAN but turns at the last request).

Traps
  • Threads share memory; processes don't.
  • Minimum average waiting time = SJF, not Round Robin.
  • Belady's anomaly belongs to FIFO only.
  • Banker's = avoidance, not prevention.
  • Paging → internal fragmentation. Segmentation → external.
  • fork() called n times creates 2ⁿ processes in total (2ⁿ − 1 children).

Computer Networksalso your DevOps interview round

OSI model (7 layers), bottom to top

"Please Do Not Throw Sausage Pizza Away"

#LayerJobUnitDevice / protocol
1PhysicalBits on wire / radioBitHub, repeater, cable
2Data LinkDelivery on the same network, error detectionFrameSwitch, bridge, MAC address, Ethernet
3NetworkRouting between networksPacketRouter, IP, ICMP (ping)
4TransportEnd-to-end delivery, portsSegmentTCP, UDP
5SessionOpen / manage / close sessionsDataRPC
6PresentationEncryption, compression, formatDataSSL/TLS, JPEG
7ApplicationWhat the user's app speaksDataHTTP, FTP, DNS, SMTP

TCP/IP model has 4 layers: Network Access (Link), Internet, Transport, Application.

TCP vs UDP

TCPUDP
ConnectionConnection-oriented (3-way handshake: SYN → SYN-ACK → ACK)Connectionless
Reliable?Yes: ordering, retransmission, flow + congestion controlNo guarantee
SpeedSlowerFaster, lower overhead
Used byHTTP/HTTPS, FTP, SMTP, SSHDNS queries, video calls, streaming, gaming, DHCP

Ports to memorise

PortServicePortService
20/21FTP53DNS
22SSH67/68DHCP
23Telnet80HTTP
25SMTP (send mail)110 / 143POP3 / IMAP (receive mail)
443HTTPS3306MySQL

Addresses

Key protocols

ProtocolDoes
DNSName → IP address (google.com → 142.x.x.x)
ARPIP → MAC address (RARP: MAC → IP)
DHCPGives a device an IP address automatically
NATMany private IPs share one public IP
ICMPError / diagnostic messages (ping, traceroute)
HTTP vs HTTPSHTTPS = HTTP + TLS encryption. HTTP is stateless

HTTP methods: GET (read), POST (create), PUT (replace), PATCH (partial update), DELETE. Status codes: 2xx success (200 OK, 201 Created), 3xx redirect (301), 4xx client error (400, 401 unauthorised, 403 forbidden, 404 not found), 5xx server error (500, 502 bad gateway, 503 unavailable).

Devices and topologies

Traps
  • IPv4 is 32 bits, IPv6 is 128, MAC is 48.
  • Switch is Layer 2; router is Layer 3.
  • DNS mostly uses UDP port 53.
  • ARP finds the MAC from an IP, not the other way round.
  • TCP handshake has 3 steps; closing a connection takes 4.

OOPSobject-oriented programming

Class and object

The 4 pillars

PillarMeaningExample
EncapsulationBundle data + methods together and hide the data (private fields, getters/setters)Bank balance only changed through deposit()
AbstractionShow what it does, hide howYou press brake; you don't see the hydraulics. Abstract classes, interfaces
InheritanceA child class reuses a parent class ("is-a")Dog extends Animal
PolymorphismOne name, many forms+ adds numbers and joins strings

Polymorphism types

Compile-time (static)Run-time (dynamic)
Overloading: same method name, different parameters, same classOverriding: child class redefines the parent's method with the same signature
Also operator overloadingUses virtual functions (C++), decided at run time

Inheritance types

Single (A→B), Multilevel (A→B→C), Hierarchical (A→B, A→C), Multiple (A,B→C), Hybrid. Java does not allow multiple inheritance of classes (only through interfaces) because of the diamond problem. C++ and Python allow it.

Access specifiers

SpecifierVisible to
privateOnly the same class
protectedSame class + child classes
publicEveryone

Default in C++ class = private; in struct = public.

Other terms

Traps
  • Overloading = compile time; overriding = run time.
  • Constructors can be overloaded but not inherited, and (in C++) can't be virtual. Destructors can be virtual.
  • Return type alone can't overload a method.
  • Data hiding is encapsulation; hiding implementation is abstraction.

DBMSdatabases and SQL

Keys

KeyMeaning
Super keyAny set of columns that uniquely identifies a row
Candidate keyA minimal super key (no extra columns)
Primary keyThe candidate key chosen. Unique + NOT NULL, one per table
Alternate keyCandidate keys not chosen as primary
Foreign keyColumn that refers to another table's primary key (links tables)
Unique keyUnique, but can be NULL; many per table
Composite keyKey made of 2+ columns

ACID (transactions)

Normalization (remove redundancy)

FormRule
1NFAtomic values: one value per cell, no repeating groups
2NF1NF + no partial dependency (non-key column depends on the whole key)
3NF2NF + no transitive dependency (non-key → non-key)
BCNFEvery determinant is a candidate key (stricter 3NF)

SQL command groups

GroupCommands
DDL (structure)CREATE, ALTER, DROP, TRUNCATE, RENAME
DML (data)SELECT, INSERT, UPDATE, DELETE
DCL (permissions)GRANT, REVOKE
TCL (transactions)COMMIT, ROLLBACK, SAVEPOINT

DELETE vs TRUNCATE vs DROP

DELETETRUNCATEDROP
RemovesChosen rows (WHERE)All rowsWhole table + structure
TypeDMLDDLDDL
RollbackYesUsually noNo

Queries and joins

Order you write: SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY …

Other terms

Traps
  • Primary key: no NULLs. Unique key: allows NULL.
  • TRUNCATE is DDL even though it removes data.
  • HAVING works on groups; WHERE can't use aggregate functions.
  • 2NF is about partial dependency; 3NF is about transitive.

Microprocessors8085 and 8086

80858086
Data bus8-bit16-bit
Address bus16-bit → 2¹⁶ = 64 KB memory20-bit → 2²⁰ = 1 MB memory
Pins4040
Supply+5 V+5 V
Flags59 (6 status + 3 control)
SpecialAddress/data lines multiplexed (AD0–AD7), ALE separates themPipelining via 6-byte instruction queue; BIU + EU; segmented memory

8085 registers

8085 flags (5)

FlagSet (1) when
S SignResult's bit 7 is 1 (negative)
Z ZeroResult is 0
AC Auxiliary carryCarry from bit 3 to bit 4 (used for BCD)
P ParityResult has an even number of 1s
CY CarryCarry/borrow out of bit 7

8085 interrupts

Priority high → low: TRAP (non-maskable, highest), RST 7.5, RST 6.5, RST 5.5, INTR (lowest, non-vectored). TRAP vector = 0024H.

Common instructions

InstructionDoes
MVI A, 05HMove immediate 05H into A
MOV B, ACopy A into B (destination first)
LDA 2050H / STA 2050HLoad A from / store A to memory address
ADD B / SUB BA = A + B / A = A − B
INR A / DCR AIncrement / decrement
JMP, JZ, JNZ, JCJump always / if zero / if not zero / if carry
CALL / RETCall subroutine / return (uses the stack)
PUSH / POPStack operations on register pairs
HLTHalt

Addressing modes

Immediate (data in instruction: MVI A,05H), Register (MOV A,B), Direct (address in instruction: LDA 2050H), Register indirect (address in a register pair: MOV A,M with HL), Implied (CMA).

8086 segments

CS (code), DS (data), SS (stack), ES (extra). Physical address = segment × 10H + offset (shift segment left by 4 bits, then add).

Traps
  • 8085 = 8-bit data, but 16-bit address (64 KB).
  • 8086 = 16-bit data, 20-bit address (1 MB).
  • TRAP is the only non-maskable interrupt in 8085.
  • Parity flag = 1 for even parity.
  • In MOV B, A the destination comes first.

Digital Principles & COAgates, numbers, the computer inside

Logic gates

GateOutput 1 whenExpression
ANDall inputs 1A·B
ORany input 1A+B
NOTinput is 0A'
NANDNOT all 1 (output 0 only when all inputs 1)(A·B)'
NORall inputs 0(A+B)'
XORinputs differentA⊕B
XNORinputs same(A⊕B)'

NAND and NOR are universal gates: any circuit can be built from only NANDs (or only NORs).

Boolean rules

Number systems

SystemBaseExample
Binary21101₂ = 8+4+0+1 = 13
Octal8group binary in 3s: 101 011 = 53₈
Decimal1043
Hexadecimal16group binary in 4s: 0010 1011 = 2B₁₆ (A=10 … F=15)

Combinational vs sequential

Combinational (no memory)Sequential (has memory, uses a clock)
Half adder (Sum = A⊕B, Carry = A·B), full adder, MUX, DEMUX, encoder, decoderFlip-flops, registers, counters

Flip-flops

TypeBehaviour
SRSet / Reset. S = R = 1 is invalid
JKLike SR, but J = K = 1 toggles (fixes the invalid state)
DOutput = input D (delay / data). Used in registers
TT = 1 toggles, T = 0 holds. Used in counters

A flip-flop stores 1 bit. An n-bit register = n flip-flops. A mod-N counter needs ⌈log₂N⌉ flip-flops.

Computer organization

Traps
  • XOR = different, XNOR = same.
  • Universal gates: NAND and NOR (not XOR).
  • Half adder carry is AND; sum is XOR.
  • JK with J = K = 1 toggles; SR with S = R = 1 is invalid.
  • Flip-flops make circuits sequential; MUX/decoder are combinational.
  • Address bus is one-way; data bus is two-way.