Chapter 7
Big-O (O) = upper bound / worst case (e.g., O(nΒ²) means at most nΒ² operations). Big-Omega (Ξ©) = lower bound / best case. Big-Theta (Ξ) = tight bound / exact growth rate (both upper and lower).push (add to top), pop (remove from top), peek (view top). Uses: function call stack, undo operations, infix-to-postfix conversion, postfix evaluation, recursion, backtracking. One end (top) is active.enqueue (add to rear), dequeue (remove from front). Uses: CPU scheduling, printer spooler, buffering, BFS traversal. Two ends: front (remove) and rear (insert).Infix (A+B) β operator between operands, used by humans. Postfix / RPN (AB+) β operator after operands, used by calculators/compilers. Prefix / Polish (+AB) β operator before operands. Stacks are used to convert infixβpostfix and evaluate postfix.Singly (each node has one pointer β next), Doubly (pointers to both next and previous), Circular (last node points back to first). Advantage: dynamic size, easy insertion/deletion. Disadvantage: no random access β O(n) search, unlike arrays.In-order (L-Root-R) β for BST, gives sorted ascending order. Pre-order (Root-L-R) β used to copy a tree. Post-order (L-R-Root) β used to delete a tree or evaluate expressions.Bubble / Insertion / Selection sort β O(nΒ²) average and worst case; simple but slow for large datasets. Merge sort β O(n log n), stable, needs extra O(n) space. Quick sort β O(n log n) average, O(nΒ²) worst case (bad pivot). Heap sort β O(n log n), in-place, uses a max-heap.Chaining (linked list at each bucket) or Open Addressing (probe for another slot β linear, quadratic, double hashing).Directed graph (digraph): edges have direction. Undirected graph: edges are bidirectional. Weighted graph: edges have associated costs/weights.Adjacency Matrix β VΓV boolean matrix; O(VΒ²) space, O(1) edge lookup. Adjacency List β list of neighbors per vertex; efficient for sparse graphs, O(V+E) space.Prim's algorithm β grows MST from a starting vertex (greedy). Kruskal's algorithm β adds edges in increasing weight order, skipping those that form cycles (uses Union-Find). Both are greedy algorithms.Logical data independence β changing the schema doesn't require changes to application programs. Physical data independence β changing storage structure doesn't affect the logical schema. Schema = the structure/design (stable); Instance = the actual data at a point in time (changes constantly).Primary key β uniquely identifies each row, cannot be NULL. Candidate key β any minimal set of attributes that uniquely identifies a row (primary key is chosen from candidates). Foreign key β references the primary key of another table (enforces referential integrity). Super key β any set of attributes that uniquely identifies a row (may not be minimal).1NF β all attribute values are atomic (indivisible), no repeating groups. 2NF β 1NF + no partial dependency (every non-key attribute depends on the whole composite key). 3NF β 2NF + no transitive dependency (non-key attribute does NOT depend on another non-key attribute). BCNF β stronger 3NF: every determinant must be a candidate key.DDL (Data Definition Language) β CREATE, ALTER, DROP, TRUNCATE (defines schema). DML (Data Manipulation Language) β SELECT, INSERT, UPDATE, DELETE (manipulates data). DCL (Data Control Language) β GRANT, REVOKE (controls permissions). TCL (Transaction Control Language) β COMMIT, ROLLBACK, SAVEPOINT (manages transactions).Select (Ο) β filters rows (horizontal). Project (Ο) β selects columns (vertical). Join (β) β combines rows from two tables. Union, Intersection, Difference β set operations on compatible tables.clustered index determines physical data order; a non-clustered index is a separate structure. Primary keys automatically have a clustered index.Atomicity (all operations succeed, or none do β all-or-nothing), Consistency (transaction takes the DB from one valid state to another), Isolation (concurrent transactions don't interfere with each other), Durability (once committed, changes survive crashes permanently).Shared (read) lock β multiple transactions can hold concurrently for reading. Exclusive (write) lock β only one transaction at a time, for writing. Two-Phase Locking (2PL) ensures serializability: Growing phase (acquire locks, release none) β Shrinking phase (release locks, acquire none).Prevention (impose lock ordering), Avoidance (use wait-die or wound-wait protocols), Detection & Recovery (detect cycles in wait-for graph and abort a victim transaction).Transaction failure (logic error, constraint violation), System crash (OS/hardware failure β volatile memory lost, disk intact), Disk failure (physical disk damage β most severe).UNDO β rolls back uncommitted transactions (incomplete at crash time). REDO β reapplies committed transactions that hadn't been flushed to disk at crash time.COMMIT makes a transaction's changes permanent. ROLLBACK undoes all changes since the last commit or savepoint. These are TCL (Transaction Control Language) commands.Batch OS (jobs submitted in batches, no user interaction). Time-sharing OS (multiple users share CPU via time slices). Multiprogramming OS (multiple programs in memory simultaneously). Multiprocessing OS (multiple CPUs). Real-time OS (strict timing guarantees β medical, industrial). Distributed OS (multiple computers act as one).New (being created) β Ready (waiting for CPU) β Running (executing on CPU) β Waiting/Blocked (waiting for I/O or event) β Terminated (finished). A process moves between states based on scheduling and I/O events.FCFS (First Come First Served) β non-preemptive, simple, suffers from convoy effect (short jobs wait behind long ones). SJF (Shortest Job First) β optimal for minimum average waiting time, but requires knowing burst times. Round Robin (RR) β preemptive, each process gets a time quantum, good for time-sharing. Priority Scheduling β highest priority runs first, risk of starvation for low-priority processes.Wait (P/down): decrement; if < 0, block. Signal (V/up): increment; if β€ 0, wake a blocked process. Mutex = a binary semaphore providing mutual exclusion (locked/unlocked).Producer-Consumer (bounded buffer), Readers-Writers (multiple readers OK, only one writer), Dining Philosophers (5 philosophers, 5 forks β illustrates deadlock and starvation). All solved using semaphores or monitors.Swapped out = moved to disk; Swapped in = loaded back to memory. Slow due to disk I/O.FIFO β replace the oldest loaded page (simple but can suffer Belady's anomaly: more frames β more faults). LRU (Least Recently Used) β replace the page not used for the longest time (good approximation of optimal). Optimal (OPT) β replace the page not needed for the longest future time (theoretically best, requires future knowledge β used as benchmark).Internal fragmentation β wasted space inside an allocated block (e.g., allocating 8KB block for 6KB process wastes 2KB). Occurs in paging/fixed partitioning. External fragmentation β free memory exists but is scattered in small non-contiguous gaps. Occurs in variable-size allocation. Fixed by compaction (moving processes to consolidate free space) or paging.Contiguous β file occupies consecutive disk blocks; fast access but external fragmentation and hard to grow. Linked β each block points to the next; no fragmentation but no random access. Indexed β index block holds pointers to all data blocks; efficient random access, supports files of varying sizes. Used in UNIX (inode). System Administration: user account management, backups, security, monitoring, start-up/shutdown procedures.