<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DataStructures | Portfolio</title><link>https://ansangah.github.io/en/tags/datastructures/</link><atom:link href="https://ansangah.github.io/en/tags/datastructures/index.xml" rel="self" type="application/rss+xml"/><description>DataStructures</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en</language><lastBuildDate>Thu, 10 Oct 2024 00:00:00 +0000</lastBuildDate><image><url>https://ansangah.github.io/media/sharing.png</url><title>DataStructures</title><link>https://ansangah.github.io/en/tags/datastructures/</link></image><item><title>Algorithms</title><link>https://ansangah.github.io/en/blog/subjects/algorithm/</link><pubDate>Thu, 10 Oct 2024 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/algorithm/</guid><description>&lt;h2 id="1-overview"&gt;1. Overview&lt;/h2&gt;
&lt;p&gt;This note compiles the key concepts covered in an undergraduate algorithms course. Use it to refresh important ideas quickly and to understand how the individual topics are connected.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="2-sorting-algorithms"&gt;2. Sorting Algorithms&lt;/h2&gt;
&lt;p&gt;Sorting is the preparatory step for many problems. When choosing an algorithm, consider input size, data distribution, auxiliary space, and whether stability (preserving the order of equal keys) matters.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;Average Time&lt;/th&gt;
&lt;th&gt;Worst Time&lt;/th&gt;
&lt;th&gt;Extra Space&lt;/th&gt;
&lt;th&gt;Highlights&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Merge Sort&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;Stable; great for external sorting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Quick Sort&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(log n)&lt;/td&gt;
&lt;td&gt;Divide and conquer; pivot choice is critical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Selection Sort&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Few swaps but generally slow; unstable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bubble Sort&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Simple; fast on nearly sorted data with early exit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Insertion Sort&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Excellent for small or nearly sorted arrays; stable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Radix Sort&lt;/td&gt;
&lt;td&gt;O(d·n)&lt;/td&gt;
&lt;td&gt;O(d·n)&lt;/td&gt;
&lt;td&gt;O(n + k)&lt;/td&gt;
&lt;td&gt;Digit-wise; bypasses comparisons&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Counting/Bucket Sort&lt;/td&gt;
&lt;td&gt;O(n + k)&lt;/td&gt;
&lt;td&gt;O(n + k)&lt;/td&gt;
&lt;td&gt;O(n + k)&lt;/td&gt;
&lt;td&gt;Strong when value range is small or uniform&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id="21-merge-sort"&gt;2.1 Merge Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Recursively splits the array and merges the sorted halves.&lt;/li&gt;
&lt;li&gt;Stable because equal keys retain their relative order.&lt;/li&gt;
&lt;li&gt;Drawbacks: needs extra memory and incurs recursion overhead.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="22-quick-sort"&gt;2.2 Quick Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Partitions around a pivot into smaller and larger elements and recurses.&lt;/li&gt;
&lt;li&gt;Typically the fastest in practice, but degenerates to O(n²) on sorted data unless you randomise or choose smart pivots (median-of-three, etc.).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="23-selection-sort"&gt;2.3 Selection Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Repeatedly selects the minimum (or maximum) remaining element and swaps it into place.&lt;/li&gt;
&lt;li&gt;Swap count is limited to O(n), but the algorithm is mainly pedagogical due to its O(n²) comparisons.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="24-bubble-sort"&gt;2.4 Bubble Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Repeatedly swaps adjacent elements that are out of order so the largest “bubbles” to the end.&lt;/li&gt;
&lt;li&gt;Each pass places one element; adding a flag for “already sorted” speeds up nearly sorted inputs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="25-insertion-sort"&gt;2.5 Insertion Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Inserts each element into the correct position within the already sorted prefix.&lt;/li&gt;
&lt;li&gt;Stable and efficient for tiny datasets or partially ordered inputs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="26-radix-sort"&gt;2.6 Radix Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Sorts integers or fixed-length strings digit by digit: LSD (least significant digit first) or MSD (most significant digit first).&lt;/li&gt;
&lt;li&gt;Requires a stable subroutine (e.g., counting sort) to guarantee global stability.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="27-counting--bucket-sort"&gt;2.7 Counting &amp;amp; Bucket Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Counting sort achieves O(n + k) for small value range k; bucket sort achieves expected O(n) when inputs are uniformly distributed.&lt;/li&gt;
&lt;li&gt;Both need extra memory and require advance knowledge of the key range.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-trees-red-black-trees"&gt;3. Trees: Red-Black Trees&lt;/h2&gt;
&lt;p&gt;Red-black trees are balanced binary search trees that maintain O(log n) height by enforcing colour-based invariants.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invariants:&lt;/strong&gt;&lt;br&gt;
(1) Every node is red or black.&lt;br&gt;
(2) The root and NIL leaves are black.&lt;br&gt;
(3) Red nodes have black children.&lt;br&gt;
(4) Every path from a node to its descendant NIL nodes contains the same number of black nodes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operations:&lt;/strong&gt;&lt;br&gt;
Insert like a BST, then fix colours/rotations. Delete by replacing with a successor and resolving the “double black” case.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Why use them:&lt;/strong&gt; Fewer rotations than AVL trees, making them practical when inserts/deletes are frequent.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Examples:&lt;/strong&gt; &lt;code&gt;std::map&lt;/code&gt;, &lt;code&gt;std::set&lt;/code&gt;, Java &lt;code&gt;TreeMap&lt;/code&gt;, Linux CFS scheduler.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-hash-tables"&gt;4. Hash Tables&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Hash a key to an array index so average lookup/insertion/deletion becomes O(1).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Collision:&lt;/strong&gt; When multiple keys hash to the same bucket. Quality of the hash function and load factor (n/m) dictate performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="41-collision-resolution-strategies"&gt;4.1 Collision-Resolution Strategies&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Separate chaining:&lt;/strong&gt; Linked lists or dynamic arrays per bucket. Simple and flexible, but needs pointer storage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Open addressing:&lt;/strong&gt; Probe for the next empty slot (linear, quadratic probing, double hashing). Cache-friendly, yet suffers from clustering.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rehashing:&lt;/strong&gt; Enlarge the table when the load factor exceeds a threshold and reinsert all entries.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="42-design-tips"&gt;4.2 Design Tips&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Aim for a hash function that distributes keys evenly, is fast to compute, and resists adversarial input.&lt;/li&gt;
&lt;li&gt;For concurrent scenarios, look into lock-free buckets, striped locks, or partitioned tables.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-graph-algorithms"&gt;5. Graph Algorithms&lt;/h2&gt;
&lt;p&gt;Graphs model networks, dependency orders, and relationships. Sparse graphs typically use adjacency lists; dense graphs favour adjacency matrices.&lt;/p&gt;
&lt;h3 id="51-topological-sort"&gt;5.1 Topological Sort&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Produces a linear order of a DAG’s prerequisites.&lt;/li&gt;
&lt;li&gt;Implement via Kahn’s algorithm (in-degree queue) or DFS finishing times; both detect cycles when sorting fails.&lt;/li&gt;
&lt;li&gt;Useful for course prerequisites, build systems, and task scheduling.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-bellmanford-algorithm"&gt;5.2 Bellman–Ford Algorithm&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Handles graphs with negative edge weights to find single-source shortest paths.&lt;/li&gt;
&lt;li&gt;Runs |V|−1 relaxations and checks for updates on the |V|th iteration to detect negative cycles.&lt;/li&gt;
&lt;li&gt;Critical for routing protocols such as RIP where Dijkstra cannot be applied.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="53-pebble-game"&gt;5.3 Pebble Game&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Places “pebbles” on DAG nodes to study computation order and resource usage.&lt;/li&gt;
&lt;li&gt;Helps derive lower bounds for register allocation, memory minimisation, and proof complexity.&lt;/li&gt;
&lt;li&gt;Solving the optimal pebbling strategy is challenging beyond restricted graph classes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="54-additional-highlights"&gt;5.4 Additional Highlights&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;DFS/BFS:&lt;/strong&gt; Core search routines; basis for connectivity, cycle detection, and topological sort.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strongly Connected Components:&lt;/strong&gt; Kosaraju’s or Tarjan’s algorithms condense graphs into DAGs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Minimum Spanning Tree:&lt;/strong&gt; Kruskal and Prim minimise connection cost in undirected weighted graphs.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-string-matching-rabinkarp"&gt;6. String Matching: Rabin–Karp&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Uses a rolling hash to compare the pattern hash with substrings of the text.&lt;/li&gt;
&lt;li&gt;Offers expected O(n + m) time; collisions trigger explicit substring comparisons.&lt;/li&gt;
&lt;li&gt;Particularly handy for multi-pattern search after precomputing pattern hashes.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-study-tips"&gt;7. Study Tips&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Implement algorithms and analyse both average and worst cases using your own test datasets.&lt;/li&gt;
&lt;li&gt;Visualise algorithm steps with tools such as VisuAlgo or CS Academy.&lt;/li&gt;
&lt;li&gt;In coding interviews or contests, inspect input bounds and memory constraints before choosing a strategy.&lt;/li&gt;
&lt;li&gt;Suggested reading: &lt;em&gt;CLRS&lt;/em&gt;, Sedgewick’s &lt;em&gt;Algorithms&lt;/em&gt;, and &lt;em&gt;Problem Solving with Algorithms and Data Structures&lt;/em&gt; by Miller &amp;amp; Ranum.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Data Structures</title><link>https://ansangah.github.io/en/blog/subjects/ds/</link><pubDate>Mon, 15 Apr 2024 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/ds/</guid><description>&lt;h2 id="1-overview"&gt;1. Overview&lt;/h2&gt;
&lt;p&gt;Data structures organise information in memory and on disk so that algorithms can run efficiently. When solving problems, consider both the abstract data type (what operations are supported) and the concrete implementation (time/space trade-offs).&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="2-arrays-and-wrapper-classes"&gt;2. Arrays and Wrapper Classes&lt;/h2&gt;
&lt;h3 id="21-arrays"&gt;2.1 Arrays&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Traits:&lt;/strong&gt; Contiguous memory, O(1) random access by index.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limitations:&lt;/strong&gt; Fixed size; mid-array insert/delete costs O(n) shifts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use cases:&lt;/strong&gt; Cache-friendly for numerical computing, DP tables, game state loops.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="22-class-wrappers"&gt;2.2 Class Wrappers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Wrapping arrays inside classes adds safety features such as bounds checking, dynamic resizing, and iterators.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;std::vector&lt;/code&gt; (C++) and &lt;code&gt;ArrayList&lt;/code&gt; (Java) double their capacity when full, yielding amortised O(1) append operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-stack-and-queue"&gt;3. Stack and Queue&lt;/h2&gt;
&lt;h3 id="31-stack"&gt;3.1 Stack&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Last-in-first-out (LIFO). Underpins call stacks, delimiter checking, DFS backtracking.&lt;/li&gt;
&lt;li&gt;Core ops: &lt;code&gt;push&lt;/code&gt;, &lt;code&gt;pop&lt;/code&gt;, &lt;code&gt;top&lt;/code&gt;. Implementable with arrays or linked lists.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="32-queue"&gt;3.2 Queue&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;First-in-first-out (FIFO). Used in BFS, job scheduling, buffering.&lt;/li&gt;
&lt;li&gt;Core ops: &lt;code&gt;enqueue&lt;/code&gt;, &lt;code&gt;dequeue&lt;/code&gt;, &lt;code&gt;front&lt;/code&gt;. Circular arrays eliminate index wrap-around.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="33-deque"&gt;3.3 Deque&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Inserts and deletes on both ends. Handy for sliding windows and monotonic queues.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-pointers-and-linked-lists"&gt;4. Pointers and Linked Lists&lt;/h2&gt;
&lt;h3 id="41-pointers"&gt;4.1 Pointers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Store memory addresses and reference dynamically allocated objects.&lt;/li&gt;
&lt;li&gt;Beware of null dereferences, dangling pointers, and double frees.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-singly-linked-list"&gt;4.2 Singly Linked List&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Nodes store &lt;code&gt;(data, next)&lt;/code&gt;. Inserts/deletes run in O(1); random access takes O(n).&lt;/li&gt;
&lt;li&gt;Techniques: head insertion, tail pointer maintenance, sentinel (dummy) heads.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-doubly-linked-list"&gt;4.3 Doubly Linked List&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Each node keeps &lt;code&gt;prev&lt;/code&gt; and &lt;code&gt;next&lt;/code&gt;, enabling bidirectional traversal.&lt;/li&gt;
&lt;li&gt;Useful for LRU caches and editors. Twice as many pointer updates—test carefully.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-list-abstract-data-type"&gt;5. List Abstract Data Type&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;List ADTs define ordered collections; performance depends on implementation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic array list:&lt;/strong&gt; O(1) indexing, O(n) mid-insert/delete.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Linked list:&lt;/strong&gt; O(1) insert/delete (with references), O(n) search; cursor iterators help frequent traversals.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-recursion"&gt;6. Recursion&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Functions call themselves to break a problem into smaller cases.&lt;/li&gt;
&lt;li&gt;Essential elements: &lt;strong&gt;base case&lt;/strong&gt;, &lt;strong&gt;recursive relation&lt;/strong&gt;, and &lt;strong&gt;state propagation&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Watch call-stack depth; tail recursion can often be transformed into iteration.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="7-trees"&gt;7. Trees&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Hierarchical, acyclic structures branching from a root.&lt;/li&gt;
&lt;li&gt;Terminology: depth, height, degree, subtree.&lt;/li&gt;
&lt;li&gt;Traversals: preorder, inorder, postorder, level-order—implemented via recursion or queues.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="8-binary-search-tree-bst"&gt;8. Binary Search Tree (BST)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Maintains the invariant left subtree &amp;lt; root &amp;lt; right subtree.&lt;/li&gt;
&lt;li&gt;Average O(log n) lookup/insert/delete; skewed trees degrade to O(n).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Balancing options:&lt;/strong&gt; AVL, red-black tree, treap, splay tree—guarantee logarithmic height.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="9-priority-queue"&gt;9. Priority Queue&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Stores elements with priorities; retrieves the highest (or lowest) priority element.&lt;/li&gt;
&lt;li&gt;Typically implemented with heaps: &lt;code&gt;insert&lt;/code&gt; and &lt;code&gt;extract&lt;/code&gt; in O(log n), &lt;code&gt;peek&lt;/code&gt; in O(1).&lt;/li&gt;
&lt;li&gt;Applications: Dijkstra’s algorithm, schedulers, event simulation, running medians.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="10-graphs"&gt;10. Graphs&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Comprised of vertices (V) and edges (E). Consider direction, multiedges, self-loops.&lt;/li&gt;
&lt;li&gt;Representations:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Adjacency list:&lt;/strong&gt; O(V + E) space—ideal for sparse graphs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adjacency matrix:&lt;/strong&gt; O(V²) space—constant-time edge existence checks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Traversals: DFS (stack/recursion) and BFS (queue) underpin connectivity, topological order, and cycle detection.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="11-weighted-graphs"&gt;11. Weighted Graphs&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Each edge carries a cost. Models maps, networks, logistics.&lt;/li&gt;
&lt;li&gt;Single-source shortest paths: Dijkstra (non-negative weights), Bellman–Ford (with negatives), SPFA (practical improvements).&lt;/li&gt;
&lt;li&gt;All-pairs shortest paths: Floyd–Warshall (O(V³)), Johnson’s algorithm (sparse graphs).&lt;/li&gt;
&lt;li&gt;Minimum spanning tree: Kruskal (Union-Find) and Prim (priority queue).&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="12-sorting-review"&gt;12. Sorting (Review)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Reorders data to enable faster search or analytics.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Comparison-based:&lt;/strong&gt; Quick, merge, heap sort—lower bound O(n log n).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Non-comparison:&lt;/strong&gt; Counting, radix, bucket sort—use key range/digits to reach O(n + k).&lt;/li&gt;
&lt;li&gt;Evaluate stability, in-place behaviour, memory footprint, and whether divide-and-conquer fits the scenario.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="13-searching"&gt;13. Searching&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Linear search:&lt;/strong&gt; Scan sequentially; works on unsorted collections; O(n).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Binary search:&lt;/strong&gt; Halves the range on a sorted array; O(log n).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hash lookup:&lt;/strong&gt; Average O(1) with well-designed collisions handling.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tree search:&lt;/strong&gt; Balanced BSTs or B-Trees deliver O(log n); maintaining balance is vital.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="14-study-tips"&gt;14. Study Tips&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Build your own complexity tables and revisit them regularly.&lt;/li&gt;
&lt;li&gt;Step through pointer manipulations with a debugger to internalise recursion and linked structures.&lt;/li&gt;
&lt;li&gt;Analyse input size, update frequency, and random access needs before choosing a structure.&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>