Made with ScholarlyTurn your own files into documents like this
Shared by Job Masalla SC25B795
This course follows data structures from types, pointers, arrays, and linked lists through abstract data types, recursion, sorting, searching, hashing, trees, and graphs. Its recurring question is how a structure’s representation and the operation’s assumptions determine correctness, time, and space costs (pp. 1, 24).
Abstract data type (ADT) — “specifies a collection of values and permitted operations, including their meaning and preconditions or effects.” It is a behavioral contract, not a memory layout; an array and linked nodes can implement the same behavior with different resource costs (pp. 1, 7). Encapsulation hides representation behind the interface so clients cannot accidentally violate invariants (p. 7).
Types, pointers, and structures: A type specifies intended values and operations, but does not guarantee that a value satisfies application rules. Pointers store addresses; dereferencing accesses the referred object, so it must be a valid pointer to a live object. A structure groups named fields, and pointer-based links connect records (pp. 2–4).
Arrays and linked lists: An array stores same-type elements contiguously, giving indexed access in O(1); middle insertions or deletions generally shift elements. Linked-list nodes need not be contiguous: traversal and search take O(n), but insertion after a known node takes O(1). A doubly linked list adds predecessor links and can remove a directly referenced node in O(1); a multi-linked list organizes a record through multiple relationships (pp. 4–5).
Stacks and queues: A stack is LIFO; a queue is FIFO. Stack operations use the top; queue operations add at the rear and remove at the front. A linked queue with front and rear pointers supports enqueue and dequeue in O(1). A circular array queue reuses freed slots without shifting elements (pp. 6–7).
Recursion and trees: A recursive solution needs a base case and recursive calls that make progress toward it. The call stack stores active calls. For binary trees, preorder emits a node before its subtrees, inorder between them, and postorder after them; each traversal visits all reachable nodes once (pp. 8–9). A basic binary search tree (BST) sends smaller keys left and larger keys right, but its operations cost time proportional to its height; sorted insertions can produce a chain and linear-time operations (pp. 17–18).
B-trees keep multiple sorted keys per node and keep all leaves at the same depth. Splitting a full node promotes a separator key to its parent, preserving ordered ranges while keeping the tree balanced. Their shallow, block-sized nodes reduce external-memory accesses (pp. 19–20).
Sorting: Selection sort makes quadratic comparisons regardless of initial order; insertion sort adapts to existing order and is stable when equal keys are not shifted past one another. Shell sort’s performance depends on its gap sequence. Mergesort has Θ(nlogn) time and typically uses O(n) auxiliary array space; it is stable when equal keys are taken from the left half first. Quicksort is typically fast with balanced partitions but has O(n2) worst-case time. Least-significant-digit radix sort needs stable passes and suitable bounded-position keys (pp. 10–12).
Searching: Sequential search works without sorted data and takes O(n) worst-case time. Binary search needs both sorted order and efficient access to the middle element; on an array it takes O(logn). A linked list’s lack of constant-time indexing means binary search does not automatically retain that advantage. Basic substring matching tests possible starting positions and takes O(nm) worst-case time for text length n and pattern length m (pp. 12–14, 26).
Hashing: A hash function deterministically maps a key to a valid table index. Collisions are handled by separate chaining or open addressing. A load factor is stored keys divided by table slots; with suitable distribution and load, operations are often expected O(1), but worst-case time is O(n) (pp. 14–17).
Graphs: An adjacency matrix uses O(V2) space and tests an indexed edge in O(1); an adjacency list uses O(V+E) space and lists a vertex’s neighbors in O(deg(u)). BFS uses a queue and finds shortest paths by edge count in unweighted or equal-cost graphs. DFS explores deeply but does not generally find shortest paths. For weighted shortest paths, Dijkstra requires nonnegative weights; Bellman–Ford allows negative weights and detects reachable negative-weight cycles (pp. 20–23).
Linked-list insertion: Given 5→8→14→null and a reference to node 8, insert 12 by setting its next link to 14, then setting 8’s next link to 12. Relinking takes O(1); finding node 8 first would take up to O(n) (p. 5).
Sorting [5, 2, 4, 1]: Selection sort first moves the minimum 1 to the front, yielding [1, 2, 4, 5]. In insertion sort, insert 2 before 5, then 4 between 2 and 5, then 1 at the front. The example illustrates insertion sort’s growing sorted prefix (pp. 10–11).
Hash collisions: With capacity 11 and h(k)=kmod11, keys 26, 38, and 49 map to slots 4, 5, and 5. Thus 38 and 49 collide; the calculation identifies only the initial slot, not the resolution method (p. 15).
BFS: In the graph with edges A–B, A–C, B–D, and C–D, starting at A and inspecting neighbors alphabetically visits A, B, C, D. Distances are 0, 1, 1, 2; B discovers D first, so D’s predecessor is B. Marking D visited when enqueued prevents C from enqueueing it again (p. 22).
Make from this