Queue

1. Simple Queue Basic FIFO structure. Use a list or collections.deque in Python. 2. Circular Queue The last position connects back to the first to form a circle. 3. Priority Queue Elements are dequeued based on priority, not arrival time. Use Python’s heapq module for implementation. 4. Double-Ended Queue (Deque) Elements can be added or removed from both ends. Use collections.deque for an efficient implementation. Common Operations Enqueue: Add an element to the back of the queue....

Recursion

Introduction Recursion is a method of solving a computational problem where the solution depends on solutions to smaller instances of the same problem. All recursive functions contain two parts: A base case (or cases), which defines when the recursion is stopped - otherwise it will go on forever! Breaking down the problem into smaller subproblems and invoking the recursive call. One of the most common examples of recursion is the Fibonacci sequence:...

Search & Sort

Introduction Sorting is the act of rearranging elements in a sequence in order, either in numerical or lexicographical order, and either ascending or descending. A number of basic algorithms run in O(n^2) and should not be used in interviews. In algorithm interviews, you’re unlikely to need to implement any of the sorting algorithms from scratch. Instead, you would need to sort the input using your language’s default sorting function so that you can use binary searches on them....

SQL

1. Introduction to SQL Definition: SQL (Structured Query Language) is used to manage and manipulate relational databases. Key Uses: Create and modify database structures (DDL). Insert, update, and delete data (DML). Query and retrieve data (DQL). Manage database permissions and transactions (DCL/TCL). Database Systems: MySQL, PostgreSQL, Oracle, SQL Server, SQLite. 2. Types of SQL Commands 2.1. Data Definition Language (DDL) Purpose: Define and modify database structure. Commands: Command Description CREATE Creates a database, table, or view ALTER Modifies existing database objects DROP Deletes database objects TRUNCATE Deletes all rows in a table Examples: -- Create a table CREATE TABLE employees ( id INT PRIMARY KEY, name VARCHAR(100), position VARCHAR(50), salary DECIMAL(10, 2), hire_date DATE ); -- Alter a table ALTER TABLE employees ADD COLUMN department VARCHAR(50); -- Drop a table DROP TABLE employees; -- Truncate a table TRUNCATE TABLE employees; 2....

4 min · Prajwal S

Stack

Overview A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. Operations are performed at one end, called the top of the stack. Common Stack Operations Push: Add an element to the top of the stack. Pop: Remove the top element from the stack. Peek/Top: Retrieve the top element without removing it. isEmpty: Check if the stack is empty. Implementation Stacks can be implemented using:...

Strings

Introduction A string is a sequence of characters. Many tips that apply to arrays also apply to strings. You’re recommended to read the page on Arrays before reading this page. Common data structures for looking up strings: Trie/Prefix Tree Suffix Tree Common string algorithms: Rabin Karp for efficient searching of substring using a rolling hash KMP for efficient searching of substring Time complexity A string is an array of characters, so the time complexities of basic string operations closely resemble those of array operations....

System Design

This guide provides a comprehensive overview of system design concepts, principles, patterns, and examples. Table of Contents What is System Design? Key Principles of System Design System Design Process Scalability High Availability Load Balancing Caching Database Design Sharding Replication Indexes Message Queues CAP Theorem Design Patterns Common System Design Questions Best Practices 1. What is System Design? System design is the process of defining the architecture, components, modules, interfaces, and data flow of a system to meet specific requirements....

4 min · Prajwal S

Techniques

1. Sliding Window Use Case: When dealing with contiguous subarrays or substrings. # Example: Maximum Sum Subarray of Size K def max_subarray_sum(arr, k): max_sum, window_sum = 0, sum(arr[:k]) for i in range(len(arr) - k): window_sum += arr[i + k] - arr[i] max_sum = max(max_sum, window_sum) return max_sum 2. Two Pointers Use Case: When dealing with sorted arrays or linked lists. # Example: Two Sum (Sorted Input) def two_sum(numbers, target): left, right = 0, len(numbers) - 1 while left < right: current_sum = numbers[left] + numbers[right] if current_sum == target: return [left + 1, right + 1] elif current_sum < target: left += 1 else: right -= 1 return [] 3....

5 min · Prajwal S

Tree

Overview A tree is a hierarchical data structure consisting of nodes, where each node has a value and a list of child nodes. The topmost node is called the root. Nodes with no children are called leaves. Trees are commonly used to represent hierarchical relationships and structures. Key Terminology Root: The topmost node in a tree. Parent: A node that has child nodes. Child: A node that has a parent node....

Trie

Overview A trie (prefix tree) is a tree-like data structure that stores strings. It is designed for efficient retrieval of strings, especially when searching by prefixes. Key Properties Each node represents a single character of the string. Strings are stored as paths from the root to leaf nodes. Common prefixes are shared among strings, making tries memory-efficient for such use cases. Common Operations Insert: Add a word to the trie. Search: Check if a word exists in the trie....