0 min · Prajwal S

Arrays

Arrays Arrays hold values of the same type at contiguous memory locations. In an array, we’re usually concerned about two things - the position/index of an element and the element itself. Different programming languages implement arrays under the hood differently and can affect the time complexity of operations you make to the array. In some languages like Python, JavaScript, Ruby, PHP, the array (or list in Python) size is dynamic and you do not need to have a size defined beforehand when creating the array....

Binary

Overview Binary operations are fundamental to computer science, involving the manipulation of numbers at the bit level. These operations are efficient and often used in algorithms for optimization and low-level computations. Key Concepts Binary Representation Numbers are represented using bits (0s and 1s). Example: The number 5 is represented as 101 in binary. Bitwise Operators Perform operations directly on the binary representation of numbers. Common Bitwise Operators Operator Symbol Description Example AND & Sets each bit to 1 if both bits are 1 5 & 3 = 1 OR ` ` Sets each bit to 1 if one of the bits is 1 XOR ^ Sets each bit to 1 if only one of the bits is 1 5 ^ 3 = 6 NOT ~ Inverts all bits ~5 = -6 Left Shift << Shifts bits to the left, padding with 0s 5 << 1 = 10 Right Shift >> Shifts bits to the right 5 >> 1 = 2 Examples of Bitwise Operations # Example: Bitwise AND print(5 & 3) # Output: 1 # Example: Bitwise OR print(5 | 3) # Output: 7 # Example: Bitwise XOR print(5 ^ 3) # Output: 6 # Example: Left Shift print(5 << 1) # Output: 10 # Example: Right Shift print(5 >> 1) # Output: 2 Applications of Binary Operations 1....

Clean Code

These notes provide a detailed summary of the “Clean Code” book, along with examples to help you understand and apply its principles effectively. General Principles of Clean Code Readability: Code is written for humans to read and understand. Prioritize clarity over clever tricks or brevity. Example: # Clear and readable code def calculate_total_price(prices, tax_rate): subtotal = sum(prices) tax = subtotal * tax_rate return subtotal + tax # Avoid unclear code def calc(p, t): return sum(p) + sum(p) * t Simplicity:...

4 min · Prajwal S

DSA

One Page to Crack Them All What is DSA? DSA involves the study of ways to organize and manipulate data to perform various tasks efficiently. DSA - A data structure is a way to store data. Primitive Data Structures are basic data structures provided by programming languages to represent single values, such as integers, floating-point numbers, characters, and booleans. Abstract Data Structures are higher-level data structures that are built using primitive data types and provide more complex and specialized operations....

5 min · Prajwal S

Dynamic Programming

Overview Dynamic Programming (DP) is a method for solving problems by breaking them into smaller overlapping subproblems. It stores the results of subproblems to avoid redundant computation (memoization) or iteratively builds up solutions (tabulation). Ideal for optimization problems and problems with overlapping subproblems and optimal substructure. Key Concepts Overlapping Subproblems The problem can be divided into subproblems that are solved multiple times. Optimal Substructure The solution to the problem can be composed of solutions to its subproblems....

Geometry

Overview Geometry algorithms deal with solving problems related to geometric shapes, properties, and relationships. These problems often involve coordinates, distances, angles, and areas, and are common in computational geometry, computer graphics, and game development. Common Techniques in Geometry 1. Point Operations Distance Between Two Points Formula: ( \text{distance} = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} ) import math def distance(x1, y1, x2, y2): return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) # Example Usage print(distance(0, 0, 3, 4)) # Output: 5....

Graph

Overview A graph is a collection of nodes, called vertices, and edges connecting pairs of vertices. Graphs are used to represent relationships between objects. Types of Graphs Undirected Graph: Edges have no direction. Directed Graph (Digraph): Edges have a direction. Weighted Graph: Edges have weights or costs associated with them. Unweighted Graph: Edges do not have weights. Cyclic Graph: Contains at least one cycle. Acyclic Graph: Does not contain any cycles....

Hash table

Introduction A hash table (commonly referred to as a hash map) is a data structure that implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function on an element to compute an index, also called a hash code, into an array of buckets or slots, from which the desired value can be found. During lookup, the key is hashed, and the resulting hash indicates where the corresponding value is stored....

Heap

Overview A heap is a specialized tree-based data structure satisfying the heap property: Max-Heap: Parent nodes are greater than or equal to their children. Min-Heap: Parent nodes are less than or equal to their children. Heaps are commonly implemented as binary heaps using arrays. Key Operations Insert: Add an element to the heap and maintain the heap property. Delete/Extract: Remove the root element and maintain the heap property. Heapify: Reorganize elements to maintain the heap property....