BFS explores level by level using a queue — best for shortest path in unweighted graphs. DFS goes as deep as possible using a stack/recursion — useful for topological sort, cycle detection, and exploring all paths. Both are O(V+E).
Algorithms· asked at Generic✓ Added to review
DP solves problems by breaking them into overlapping subproblems and storing results (memoization or tabulation) to avoid recomputation. Use it when a problem has optimal substructure and overlapping subproblems — e.g. knapsack, edit distance, longest common subsequence.
Algorithms· asked at Meta✓ Added to review
Average case O(1) for insert, lookup, and delete thanks to hashing. Worst case O(n) when many keys collide into one bucket (degenerate hashing). A good hash function and load-factor-based resizing keep operations near O(1).
Data Structures· asked at Amazon✓ Added to review
Use Floyd's tortoise-and-hare: advance one pointer by 1 and another by 2 each step. If they ever meet, there's a cycle; if the fast pointer reaches null, there isn't. O(n) time, O(1) space.
Data Structures· asked at Google✓ Added to review
An index is a data structure (often a B-tree) that speeds up reads by avoiding full table scans. Trade-off: it consumes storage and slows writes (inserts/updates must maintain the index), so index columns you frequently filter or join on.
Databases· asked at Generic✓ Added to review
Normalization organizes tables to reduce redundancy and avoid update anomalies, via normal forms (1NF–3NF/BCNF). It improves data integrity but can require more joins; denormalization is sometimes used for read performance.
Databases· asked at Amazon✓ Added to review
Atomicity (all-or-nothing transactions), Consistency (valid state transitions), Isolation (concurrent transactions don't interfere), Durability (committed data survives crashes). They guarantee reliable transaction processing in relational databases.
Databases· asked at Google✓ Added to review
`==` compares values after type coercion, so `0 == "0"` is true. `===` (strict equality) compares both value and type without coercion, so `0 === "0"` is false. Prefer `===` to avoid surprising coercion bugs.
JavaScript· asked at Generic✓ Added to review
`undefined` means a variable was declared but not assigned; `null` is an explicit 'no value' you assign intentionally. `typeof undefined` is 'undefined', `typeof null` is 'object' (a historical quirk).
JavaScript· asked at Generic✓ Added to review
Event delegation attaches a single listener to a common ancestor instead of many listeners on individual children. Events bubble up, and you inspect `event.target` to act on the originating element. It reduces memory use and works for dynamically-added elements.
JavaScript· asked at Meta✓ Added to review
A closure is a function bundled with references to its surrounding lexical scope, retaining access to those variables after the outer function returns. Practical uses: data privacy (module pattern), function factories, and maintaining state in callbacks.
JavaScript· asked at Google✓ Added to review
JS runs on a single thread with a call stack. Async callbacks go to task queues (macrotasks like setTimeout, microtasks like Promises). The event loop pushes queued callbacks onto the stack only when it is empty, draining all microtasks before the next macrotask.
JavaScript· asked at Amazon✓ Added to review
A process is an independent program with its own memory space; threads are lighter units of execution that share their process's memory. Threads are cheaper to create and communicate, but shared memory requires synchronization to avoid race conditions.
Operating Systems· asked at Microsoft✓ Added to review
A deadlock is when processes wait on each other indefinitely. It needs four conditions simultaneously (Coffman): mutual exclusion, hold-and-wait, no preemption, and circular wait. Breaking any one prevents deadlock.
Operating Systems· asked at Generic✓ Added to review
Lists are mutable (you can change, add, remove items) and use more memory; tuples are immutable and slightly faster, usable as dict keys. Use tuples for fixed collections and lists for changing sequences.
Python· asked at Generic✓ Added to review
A decorator is a callable that wraps another function to extend its behavior without modifying it, applied with `@decorator` syntax. Common uses: logging, timing, caching (`functools.lru_cache`), access control. They are functions returning functions.
Python· asked at Google✓ Added to review
The Global Interpreter Lock allows only one thread to execute Python bytecode at a time, simplifying memory management but limiting CPU-bound multithreading. Use multiprocessing or native extensions for CPU parallelism; threads still help with I/O-bound work.
Python· asked at Microsoft✓ Added to review
Vertical scaling adds more power (CPU/RAM) to one machine — simple but capped and a single point of failure. Horizontal scaling adds more machines — more complex (load balancing, data partitioning) but elastic and fault-tolerant.
System Design· asked at Generic✓ Added to review
DNS resolves the domain to an IP, a TCP (and TLS for HTTPS) connection is established, the browser sends an HTTP request, the server responds with HTML, then the browser parses HTML/CSS/JS, builds the DOM/CSSOM, and renders — fetching additional assets as needed.
System Design· asked at Google✓ Added to review
Generate a unique short code (base62 of an auto-increment ID or a hash) mapping to the long URL in a key-value/relational store. Add caching (Redis) for hot reads, a redirect service returning 301/302, analytics, and consider sharding + a counter service for scale.
System Design· asked at Amazon✓ Added to review
In a distributed system you can guarantee at most two of Consistency, Availability, and Partition tolerance. Since network partitions are unavoidable, you effectively choose between consistency (CP) and availability (AP) during a partition.
System Design· asked at Meta✓ Added to review
💬
Send Feedback / Bug
Feedback Submitted!
Thank you. Your help keeps Geeky Script running smoothly.