Memoization vs Tabulation: Top-Down vs Bottom-Up Dynamic Programming

Overview Both techniques avoid redundant recomputation in dynamic programming problems by caching subproblem results, but they build that cache in opposite directions. Memoization starts from the original problem and recurses downward, caching results lazily as calls return, while tabulation starts from the base cases and iterates upward, filling a table until the final answer is reached. Comparison Diagram Memoization (Top-Down)fib(4)fib(3)fib(2)*fib(2)fib(1)* = cache hit, no recomputememo cachefib(0)=0 fib(1)=1fib(2)=1 fib(3)=2fib(4)=3recurse down, cache on returnTabulation (Bottom-Up)for i = 0 .. ndp[0]0dp[1]1dp[2]1dp[3]2dp[4]3final answerbuild up from base cases Comparison Table Aspect Memoization (Top-Down) Tabulation (Bottom-Up) Entry point Starts from the original problem call, e.g. solve(n) Starts from the smallest base cases, e.g. dp[0], dp[1] Control flow Recursive function calls, following the natural recurrence Iterative loop over subproblem indices in dependency order Subproblems computed Only those actually reachable from the initial call All subproblems up to the target, whether needed or not Storage structure Hash map or sparse cache keyed by call arguments Array or table indexed by subproblem parameters Order dependency Implicit, resolved automatically by call stack ordering Explicit, programmer must sort iteration to respect dependencies Call overhead Function call and stack frame cost per subproblem No function call overhead, just array reads and writes Stack risk Can hit recursion depth limits or stack overflow on deep inputs No recursion, so no stack depth concerns Code shape Mirrors the recursive definition, often easier to derive first Requires reformulating the recurrence as an explicit loop Key Differences Memoization computes subproblems on demand, while tabulation computes every subproblem exhaustively in order. Memoization relies on the call stack to sequence work; tabulation relies on a manually ordered loop. Tabulation typically enables space optimization (e.g. keeping only the last few rows) since access order is known upfront. Memoization can be stack-limited on deep recursion, whereas tabulation avoids recursion entirely. Memoization is usually a smaller code change from a naive recursive solution; tabulation requires restructuring it as iteration. When to Use Each Memoization (Top-Down) ...

August 2, 2026 · 3 min · 471 words · jeonck

Recursion vs Iteration: Two Ways to Repeat Work

Overview Both techniques repeat a computation until some condition is met, but they do it through fundamentally different mechanisms. Recursion repeats by having a function call itself on the call stack, while iteration repeats by looping over the same stack frame. The choice affects memory usage, readability, and how deep a computation can safely go. Comparison Diagram RecursionIterationcall stackf(n)f(n-1)f(n-2)...new frame per callO(n) stack memoryrisk: stack overflowloop body (single frame)while / fori++, same frame reusedO(1) stack memoryno growth per cycle Comparison Table Aspect Recursion Iteration Core mechanism Function calls itself with a smaller subproblem Explicit loop (for/while) repeats a block of code Termination condition A base case stops further calls A loop condition evaluates to false State storage Held implicitly in parameters and locals of each stack frame Held explicitly in variables updated each pass Memory usage O(n) call stack space, one new frame per call O(1) auxiliary space, the same frame is reused Failure mode Stack overflow on deep or unbounded recursion Infinite loop if the condition never turns false Performance overhead Function-call overhead per level unless tail-call optimized No call overhead, just a branch/jump back Best-fit problems Tree/graph traversal, divide-and-conquer, backtracking Linear, bounded repetition like counting or array scans Key Differences Recursion breaks a problem into self-similar subcalls; iteration repeats a block via an explicit loop. Recursion grows the call stack by one frame per call; iteration reuses a single frame. Deep recursion risks stack overflow, while iteration’s main failure mode is an infinite loop. Some languages apply tail-call optimization to turn tail recursion into iteration under the hood. Recursion maps naturally onto trees and graphs; iteration suits flat, bounded repetition. When to Use Each Recursion ...

August 2, 2026 · 3 min · 430 words · jeonck

BFS vs DFS: Traversal Order and Data Structure

Overview Both are algorithms for visiting every node in a tree or graph, but they differ in which node they explore next. BFS spreads outward level by level using a queue, while DFS plunges down one path as far as possible before backtracking, using a stack. Comparison Diagram BFSDFS12345671253467outinQueue (FIFO)push/popStack (LIFO) Comparison Table Aspect BFS DFS Underlying structure Queue (FIFO) Stack (FILO), often via recursion Traversal pattern Explores all neighbors at current depth before going deeper Follows one branch to its end before backtracking Order nodes are visited Level by level (breadth-first) Branch by branch (depth-first) Memory usage O(width) — can be large for wide/bushy graphs O(depth) — can be large for deep graphs Shortest path guarantee Yes, on unweighted graphs (first visit = shortest path) No, may find a longer path first Implementation style Iterative with explicit queue Recursive, or iterative with explicit stack Risk of infinite loop Low with visited-set on cyclic graphs Higher on cyclic graphs without visited-set, or infinite depth Typical use cases Shortest path, level-order processing, web crawling by hops Topological sort, cycle detection, maze/backtracking problems Key Differences BFS uses a queue and expands outward level by level, while DFS uses a stack (or recursion) and dives deep before backtracking. BFS guarantees the shortest path on unweighted graphs; DFS does not. BFS memory cost scales with graph width, while DFS memory cost scales with graph depth. DFS naturally supports backtracking algorithms like maze solving and topological sort. Both require a visited set to avoid infinite loops on cyclic graphs. When to Use Each BFS ...

August 2, 2026 · 2 min · 388 words · jeonck

Two Pointers vs Sliding Window: Choosing the Right Array Scanning Technique

Overview Two Pointers and Sliding Window are both O(n) techniques for scanning arrays or strings, but they solve different shapes of problems: Two Pointers tracks two independent indices that move toward, away from, or alongside each other, while Sliding Window maintains a contiguous subrange that expands and contracts as it scans. Picking the wrong one usually means either overcomplicating a pair-search problem or missing the running aggregate a window naturally provides. Comparison Diagram Two PointersSliding WindowLRindices converge inwardover sorted dataLRcontiguous range expands/contracts, tracking an aggregate Comparison Table Aspect Two Pointers Sliding Window Core mechanism Two independent indices scan or converge across the data Two indices (left/right) define a contiguous range that grows and shrinks Pointer movement Move toward each other, away, or in lockstep at a fixed offset Right pointer expands the range forward, left pointer contracts it Input requirement Usually needs sorted data or a paired structure Works on any unsorted array or string State tracked Just the two positions and the values being compared A running aggregate of window contents (sum, count, frequency map) Problem signature Pair-sum, palindrome check, merging two sorted arrays Longest/shortest substring or max/min sum under a constraint Relationship between pointers No notion of a range between them, only the two positions matter The range between the pointers IS the answer candidate Time and space complexity O(n) time, O(1) space O(n) time, O(1) to O(k) space for the aggregate Failure mode Breaks if data isn’t sorted or orderable for the comparison Breaks if the target condition isn’t monotonic, so the window can’t shrink safely Key Differences Two Pointers tracks two independent indices; Sliding Window tracks a contiguous range between them. Two Pointers typically requires sorted input; Sliding Window works fine on unsorted sequences. Sliding Window maintains a running aggregate as it moves; Two Pointers usually just compares individual values. Sliding Window breaks down when the target condition isn’t monotonic, since the window can’t be safely shrunk. When to Use Each Two Pointers ...

August 2, 2026 · 3 min · 460 words · jeonck

Terraform vs Ansible: Provisioning vs Configuration Management

Overview Terraform and Ansible are both infrastructure-as-code tools but solve different problems: Terraform declaratively provisions and tracks cloud infrastructure using a state file, while Ansible procedurally configures and manages software on existing hosts with no persistent state. Many teams use them together — Terraform to stand up infrastructure, Ansible to configure it. Comparison Diagram Terraformdeclarativemain.tf (desired state)state file (source of truth)dependency graphVMNetworkDBconverges infra to match stateAnsibleproceduralplaybook.ymltask 1: install pkgtask 2: configuretask 3: start serviceServer AServer BServer Csequential push over SSH, no state file Comparison Table Aspect Terraform Ansible Primary purpose Provision and tear down cloud/infra resources (VMs, networks, DBs) Configure software and manage state on existing hosts Configuration language HCL (HashiCorp Configuration Language), declarative YAML playbooks, procedural task lists Execution model Builds a dependency graph and applies changes in parallel where possible Executes tasks sequentially, in order, per host State management Maintains a state file mapping config to real resources Stateless — queries live system facts on each run Idempotency approach Diffs desired config against state file before acting Each module checks current condition before making a change Connectivity/agent requirement Agentless — calls cloud/provider APIs directly Agentless — connects over SSH or WinRM to target hosts Failure & recovery handling Partial applies are resolved by re-running against the state file Reruns the playbook from the start; tasks are re-checked, not resumed Key Differences Terraform tracks infrastructure in a persistent state file; Ansible has no state store and reads live system facts each run. Terraform resolves a dependency graph to apply changes in parallel; Ansible runs tasks sequentially. Terraform talks to infrastructure through provider APIs; Ansible connects to hosts via SSH/WinRM. Terraform is built for provisioning infra; Ansible is built for configuration of what already exists. They’re commonly paired: Terraform creates the servers, then Ansible configures them. When to Use Each Terraform ...

August 2, 2026 · 3 min · 455 words · jeonck

Role vs ClusterRole: Kubernetes RBAC Scope Compared

Overview Role and ClusterRole are both Kubernetes RBAC objects that define sets of permission rules (verbs on resources), but they differ in scope: a Role only applies within a single namespace, while a ClusterRole is defined once for the whole cluster and can be bound either cluster-wide or scoped down to one namespace. Understanding this distinction is essential for applying least-privilege access control in multi-tenant clusters. Comparison Diagram RoleClusterRoleNamespace: devRoleRoleBindingUserlimited to this namespaceCluster scopeClusterRoleRoleBindingClusterRoleBindingUserthis ns onlyUserall namespacesone definition, reused via either binding Comparison Table Aspect Role ClusterRole API object scope Namespaced object; exists only within one Namespace Cluster-scoped object; exists once for the entire cluster Resources it can grant access to Only namespaced resources (pods, configmaps, secrets, etc.) within its own namespace Namespaced resources cluster-wide plus cluster-scoped resources such as nodes, persistentvolumes, and namespaces Non-resource URLs (e.g. /healthz, /metrics) Cannot reference non-resource URLs Can include rules for non-resource URLs Binding object required RoleBinding only, created in the same namespace RoleBinding for a namespace-scoped grant, or ClusterRoleBinding for a cluster-wide grant Effective grant when bound Permissions always limited to the Role’s own namespace Spans every namespace when bound via ClusterRoleBinding, or just one namespace when bound via RoleBinding Reuse across namespaces Must be duplicated in each namespace that needs the same rules Defined once, reused across many namespaces or cluster-wide via separate bindings Aggregation support None; rules are static within the object Supports aggregationRule to auto-combine rules from other ClusterRoles by label selector Typical built-in examples None shipped by default; teams author their own per namespace cluster-admin, admin, edit, view, and system: component roles ship as default ClusterRoles Key Differences Role is namespace-scoped while ClusterRole is cluster-scoped by definition, regardless of how it’s later bound. Only ClusterRole can grant access to cluster-scoped resources like nodes or to non-resource URLs such as /metrics. A ClusterRole can still be restricted to one namespace by binding it with a RoleBinding instead of a ClusterRoleBinding. ClusterRole supports aggregation to compose permissions from labeled ClusterRoles; Role has no equivalent mechanism. Kubernetes ships default admin/edit/view permission sets as built-in ClusterRoles, never as Roles. When to Use Each Role ...

August 2, 2026 · 3 min · 520 words · jeonck

RBAC vs ABAC: Role-Based vs Attribute-Based Access Control

Overview RBAC and ABAC are two models for deciding whether a subject can perform an action on a resource. RBAC grants access based on a user’s assigned role and that role’s fixed permission set, while ABAC evaluates a policy against attributes of the user, resource, action, and environment at request time. The choice affects how fine-grained, dynamic, and auditable your authorization system can be. Comparison Diagram RBACABACUserRole: EditorPermissionsReadWritePublishFixed, regardless of contextUser attrsResource attrsEnv attrsPolicy EngineAllow / DenyEvaluated per request, in context Comparison Table Aspect RBAC ABAC Access decision basis A user’s assigned role Attributes of the user, resource, action, and environment Permission structure Static, predefined role-to-permission mappings Dynamic policies expressed as attribute-based rules Administration Admin assigns users to existing roles Policy author writes rules combining attribute conditions Runtime evaluation Check whether the user’s role includes the requested permission Policy engine evaluates rules against current attribute values Context sensitivity Same result regardless of time, location, or device Can factor in time, location, device, and other real-time signals Granularity Coarse-grained, applied per role Fine-grained, applied per request or condition Scalability with complexity Role explosion as requirements diversify Policy complexity grows, but avoids proliferating roles Auditability Easy to audit — list who holds a given role Harder to audit — requires tracing policy logic across attributes Key Differences RBAC ties access to roles; ABAC ties access to attributes RBAC decisions are static; ABAC decisions are context-aware ABAC enables fine-grained control at the cost of policy complexity RBAC suffers from role explosion as requirements grow RBAC is generally easier to audit than ABAC When to Use Each RBAC ...

August 2, 2026 · 3 min · 427 words · jeonck

SIGTERM vs SIGKILL: Graceful vs Forced Process Termination

Overview SIGTERM and SIGKILL are both Unix signals used to stop a running process, but they differ in whether the process gets a chance to clean up after itself. SIGTERM asks a process to terminate and lets it run its own shutdown logic, while SIGKILL is an unconditional kernel-level termination that the process cannot intercept or delay. The distinction matters for avoiding data corruption, leaked resources, and orphaned locks during shutdown. ...

August 2, 2026 · 3 min · 463 words · jeonck

Blocking vs Non-blocking I/O: How a Thread Waits for Data

Overview Blocking and non-blocking I/O differ in what happens to the calling thread when a read or write can’t complete immediately. Blocking I/O suspends the thread until data is ready; non-blocking I/O returns at once and lets the caller check back later. The choice shapes how a system scales to many simultaneous connections. Comparison Diagram Blocking I/ONon-blocking I/OThreadcall read()thread blockedno other work possibleuntil data arrivesdata ready, resumes1 thread ≈ 1 in-flight callthread / event loopread() returns at oncepoll / epoll checkretrymeanwhile: serves otherconnectionsready → callback fires1 thread ≈ many in-flight calls Comparison Table Aspect Blocking I/O Non-blocking I/O Call behavior Call halts the calling thread until the operation completes Call returns immediately, with data or an EWOULDBLOCK/EAGAIN error Thread state while I/O is pending Thread is suspended off the run queue — no CPU used, but unavailable for other work Thread stays runnable and can be reused to serve other requests How readiness is discovered OS wakes the thread automatically once data is ready Caller polls or registers with select/poll/epoll/kqueue Concurrency model One thread (or process) per concurrent connection Single or few threads multiplex many connections via an event loop Resource overhead at scale Grows linearly with connections — thread stacks, context switches Stays flat, bounded by CPU cores rather than connection count Code / control-flow complexity Simple, sequential, top-to-bottom logic Callback, promise, or async/await structure; state tracked across suspensions Failure / edge-case handling A slow or hung peer blocks the thread indefinitely without a timeout A slow peer only delays its own event; a stalled callback can starve the whole loop Key Differences Blocking I/O ties up a thread for the full call; non-blocking frees it immediately. Non-blocking servers rely on an event loop to learn when data is finally ready. Blocking scales concurrency with more threads; non-blocking scales with more callbacks on fewer threads. Blocking code reads sequentially; non-blocking code needs explicit state management across suspensions. At high connection counts, blocking hits a C10K wall that non-blocking avoids. When to Use Each Blocking I/O ...

August 2, 2026 · 3 min · 488 words · jeonck

Container vs VM: Virtualization Approaches Compared

Overview Containers and virtual machines both let you package and isolate workloads, but they virtualize at different layers of the stack: containers share the host OS kernel while VMs emulate entire hardware and run a full guest OS each. That difference drives everything else — startup speed, image size, isolation strength, and how many instances you can pack onto one host. Comparison Diagram VSContainerVMApp+LibsApp+LibsApp+LibsContainer Engine(Docker / containerd)Host OS Kernel (shared)~MBs · starts in msApp+LibsGuest OSApp+LibsGuest OSApp+LibsGuest OSHypervisor(ESXi / KVM / Hyper-V)Physical Hardware~GBs · starts in minutes Comparison Table Aspect Container VM Isolation boundary OS-level, enforced by kernel namespaces and cgroups Hardware-level, enforced by a hypervisor Guest OS None — shares the host kernel Full guest OS instance per VM Startup time Milliseconds to a few seconds Tens of seconds to minutes (full OS boot) Image/footprint size Megabytes Gigabytes Resource overhead Low; near-native performance Higher; hypervisor plus guest OS overhead Portability Highly portable across any host with a compatible kernel and engine Portable via VM image formats but heavier to move and convert Security isolation strength Weaker — shared kernel widens attack surface Stronger — separate kernel per VM Typical density per host Hundreds of instances Tens of instances Key Differences Containers share the host kernel instead of running a separate OS like VMs. VM isolation is enforced by a hypervisor, giving stronger security boundaries than containers. Containers typically boot in milliseconds, while VMs take minutes to boot a full OS. Container images measure in megabytes; VM images measure in gigabytes. A single host can run far higher density of containers than VMs due to lower per-instance overhead. When to Use Each Container ...

August 2, 2026 · 3 min · 469 words · jeonck