Hack The Future Notes
DSA, Python, Machine Learning & AI — every topic explained
Definitions, flowcharts, diagrams, code examples and interview questions. Free.
- DSABeginner
Arrays
An array is a collection of elements stored in contiguous memory, where each element is accessed directly by its index.
- DSABeginner
Linked List
A linked list is a linear data structure where each node stores a value and a pointer to the next node.
- DSABeginner
Stack
A stack is a Last-In-First-Out (LIFO) structure supporting push, pop and peek at one end.
- DSABeginner
Queue
A queue is a First-In-First-Out (FIFO) structure: add at the rear, remove from the front.
- DSABeginner
Hash Map & Hashing
A hash map stores key-value pairs and uses a hash function to find a bucket for each key in average O(1).
- DSABeginner
Binary Search
Binary search finds a target in a sorted array by repeatedly halving the search range.
- DSAIntermediate
Sorting Algorithms
Sorting arranges elements in order. Common algorithms: Bubble, Selection, Insertion, Merge, Quick and Heap sort.
- DSABeginner
Recursion
Recursion is when a function calls itself on a smaller version of the problem until a base case stops it.
- DSAIntermediate
Binary Trees & BST
A binary tree is a hierarchy where each node has at most two children. In a Binary Search Tree, left < node < right.
- DSAIntermediate
Heap & Priority Queue
A heap is a complete binary tree where each parent is smaller (min-heap) or larger (max-heap) than its children.
- DSAIntermediate
Graphs, BFS & DFS
A graph is a set of nodes connected by edges. BFS explores level by level; DFS goes deep before backtracking.
- DSAAdvanced
Dynamic Programming
Dynamic Programming solves problems by breaking them into overlapping subproblems and storing their answers.
- DSAIntermediate
Sliding Window & Two Pointers
Techniques that move one or two indexes across an array to examine sub-ranges without nested loops.
- DSAIntermediate
Greedy Algorithms
A greedy algorithm makes the locally best choice at each step hoping to reach the global optimum.
- PythonBeginner
Python Basics: Variables & Data Types
Python variables are names bound to objects. Core types: int, float, str, bool, list, tuple, dict and set.
- PythonBeginner
Python Functions
A function is a reusable block of code defined with def that takes parameters and returns a value.
- PythonIntermediate
Object-Oriented Programming in Python
OOP organises code into classes (blueprints) and objects (instances) with attributes and methods.
- PythonIntermediate
List Comprehensions & Generators
Comprehensions build lists/dicts/sets in one expression; generators produce values lazily with yield.
- PythonBeginner
Exceptions & File Handling
Exceptions signal errors at runtime and are handled with try/except; files are read and written with open().
- Machine LearningBeginner
What is Machine Learning
Machine Learning is a branch of AI where computers learn patterns from data instead of following hand-written rules.
- Machine LearningBeginner
Linear Regression
Linear regression predicts a continuous value by fitting a straight line y = mx + c that minimises squared error.
- Machine LearningBeginner
Logistic Regression
Logistic regression is a classification model that outputs a probability using the sigmoid function.
- Machine LearningIntermediate
Decision Trees & Random Forest
A decision tree splits data with if/else questions; a random forest averages many trees for better accuracy.
- Machine LearningIntermediate
K-Means Clustering
K-Means groups unlabeled data into K clusters by assigning points to the nearest centroid.
- Machine LearningIntermediate
Overfitting, Bias & Variance
Overfitting is when a model memorises training data and fails on new data; the bias-variance trade-off explains why.
- Machine LearningIntermediate
Model Evaluation Metrics
Metrics measure model quality: accuracy, precision, recall, F1 and ROC-AUC for classification; MSE and R² for regression.
- AIBeginner
What is Artificial Intelligence
Artificial Intelligence is the field of building systems that perform tasks needing human-like intelligence: reasoning, learning, perception and language.
- AIIntermediate
Neural Networks
A neural network is layers of connected neurons that multiply inputs by weights, add a bias and apply an activation.
- AIIntermediate
Gradient Descent
Gradient descent minimises a loss by repeatedly moving parameters a small step opposite to the gradient.
- AIAdvanced
CNNs & Computer Vision
Convolutional Neural Networks slide small filters over images to detect edges, shapes and objects.
- AIAdvanced
NLP, Transformers & LLMs
Transformers use self-attention to understand relationships between words; Large Language Models are huge transformers trained on text.
- AIIntermediate
AI Search: BFS, DFS & A*
AI search explores a state space to reach a goal. A* combines path cost g(n) with a heuristic h(n).
- DSABeginner
Strings
A string is an ordered sequence of characters, usually immutable, supporting indexing, slicing and searching.
- DSABeginner
Prefix Sum
A prefix sum array stores the running total so any range sum is computed in O(1).
- DSAIntermediate
Bit Manipulation
Bit manipulation uses operators like AND, OR, XOR and shifts to work directly on binary representations.
- DSAIntermediate
Merge Sort
Merge sort is a divide-and-conquer algorithm that splits the array in halves, sorts each and merges them.
- DSAIntermediate
Quick Sort
Quick sort picks a pivot, partitions smaller elements left and larger right, then sorts each side recursively.
- DSAIntermediate
Trie (Prefix Tree)
A trie is a tree where each edge is a character, so words sharing a prefix share a path.
- DSAAdvanced
Union-Find (Disjoint Set)
Union-Find tracks which elements belong to the same group with find and union operations.
- DSAAdvanced
Dijkstra's Shortest Path
Dijkstra's algorithm finds the shortest distance from a source to all nodes in a graph with non-negative weights.
- DSAAdvanced
Topological Sort
Topological sort orders nodes of a directed acyclic graph so every edge goes from earlier to later.
- DSAIntermediate
Backtracking
Backtracking builds a solution step by step and undoes a choice when it cannot lead to a valid answer.
- DSABeginner
Time Complexity & Big-O
Big-O describes how the running time or memory of an algorithm grows as input size grows.
- PythonBeginner
Python Data Types
Python's core types are int, float, str, bool, list, tuple, set and dict.
- PythonBeginner
Loops & Conditions
if/elif/else chooses a branch; for and while repeat code.
- PythonBeginner
Dictionaries & Sets
A dict maps keys to values; a set stores unique items. Both use hashing for fast lookup.
- PythonIntermediate
Generators & Iterators
A generator is a function using yield that produces values lazily, one at a time.
- PythonIntermediate
Decorators
A decorator is a function that wraps another function to add behavior without changing its code.
- PythonBeginner
Modules & Packages
A module is a .py file; a package is a folder of modules. import loads them.
- PythonIntermediate
NumPy & Pandas Basics
NumPy provides fast arrays; Pandas provides DataFrames for tabular data.
- Machine LearningBeginner
K-Nearest Neighbors
KNN predicts a label by taking a majority vote of the k closest training points.
- Machine LearningIntermediate
Naive Bayes
Naive Bayes applies Bayes' theorem assuming features are independent given the class.
- Machine LearningAdvanced
Support Vector Machine
An SVM finds the boundary that separates classes with the maximum margin.
- Machine LearningAdvanced
PCA (Dimensionality Reduction)
PCA projects data onto new axes (principal components) that capture the most variance.
- Machine LearningIntermediate
Feature Engineering & Scaling
Feature engineering creates and transforms inputs so models learn patterns better.
- Machine LearningIntermediate
Cross-Validation
K-fold cross-validation splits data into k parts, trains on k−1 and tests on the remaining one, k times.
- Machine LearningAdvanced
Gradient Boosting & XGBoost
Gradient boosting builds trees one after another, each fixing the errors of the previous ones.
- AIIntermediate
Activation Functions
Activation functions add non-linearity to neurons so networks can learn complex patterns.
- AIAdvanced
Backpropagation
Backpropagation computes gradients of the loss with respect to every weight using the chain rule.
- AIAdvanced
RNN & LSTM
RNNs process sequences step by step with a hidden state; LSTMs add gates to remember long-term information.
- AIAdvanced
Reinforcement Learning
In RL an agent learns by acting in an environment and maximizing cumulative reward.
- AIBeginner
Prompt Engineering
Prompt engineering is writing clear instructions and context so an LLM produces the desired output.
- AIAdvanced
Embeddings & RAG
Embeddings turn text into vectors; RAG retrieves relevant documents by vector similarity and feeds them to an LLM.
- DSABeginner
Insertion & Selection Sort
Insertion sort inserts each element into its place in the sorted left part; selection sort repeatedly picks the minimum.
- DSAIntermediate
Counting & Radix Sort
Counting sort counts occurrences of each value; radix sort sorts digit by digit using a stable counting sort.
- DSAAdvanced
Binary Search on Answer
Instead of searching an array, binary search over the range of possible answers using a yes/no check.
- DSAIntermediate
Monotonic Stack
A monotonic stack keeps elements in increasing or decreasing order to find next greater/smaller elements.
- DSAAdvanced
Deque & Sliding Window Maximum
A deque allows O(1) push/pop at both ends; a monotonic deque gives the max of each window.
- DSAIntermediate
Binary Search Tree
A BST keeps smaller keys in the left subtree and larger keys in the right subtree.
- DSABeginner
Tree Traversals
Traversals visit every node: preorder (root-left-right), inorder (left-root-right), postorder (left-right-root) and level order.
- DSAAdvanced
Lowest Common Ancestor
The LCA of two nodes is the deepest node that has both as descendants.
- DSAAdvanced
Minimum Spanning Tree
An MST connects all vertices with minimum total edge weight and no cycles (Kruskal or Prim).
- DSAIntermediate
0/1 Knapsack
Choose items with weights and values to maximize value without exceeding capacity; each item used at most once.
- DSAIntermediate
Longest Common Subsequence
LCS finds the longest sequence appearing in both strings in order, not necessarily contiguous.
- DSAIntermediate
Grid / Matrix Problems
Grid problems treat each cell as a graph node connected to up/down/left/right neighbors.
- PythonBeginner
String Methods & f-strings
Python strings have built-in methods like split, join, strip, replace and upper, and f-strings format values.
- PythonIntermediate
Lambda, map, filter & sorted
A lambda is a small anonymous function; map transforms, filter selects and sorted orders using a key.
- PythonIntermediate
*args and **kwargs
*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict.
- PythonIntermediate
Inheritance & Dunder Methods
Inheritance lets a class reuse and extend another; dunder methods like __str__ and __len__ customize built-in behavior.
- PythonIntermediate
Context Managers (with)
A context manager sets up and tears down a resource automatically using the with statement.
- PythonIntermediate
collections Module
collections offers Counter, defaultdict, deque, namedtuple and OrderedDict for common patterns.
- Machine LearningBeginner
Supervised vs Unsupervised Learning
Supervised learning learns from labeled examples; unsupervised learning finds structure in unlabeled data.
- Machine LearningBeginner
Train/Validation/Test Split
Data is split into training (learn), validation (tune) and test (final evaluation) sets.
- Machine LearningIntermediate
Regularization (L1 & L2)
Regularization adds a penalty on large weights to the loss to reduce overfitting.
- Machine LearningBeginner
Confusion Matrix, Precision & Recall
A confusion matrix counts TP, FP, FN and TN; precision and recall are computed from it.
- Machine LearningIntermediate
Hyperparameter Tuning
Hyperparameters are settings chosen before training (learning rate, depth, k); tuning searches for the best values.
- AIBeginner
Perceptron
A perceptron is the simplest neuron: weighted sum plus bias passed through a step function.
- AIIntermediate
Loss Functions
A loss function measures how wrong predictions are; training minimizes it.
- AIAdvanced
Optimizers (SGD, Momentum, Adam)
Optimizers decide how weights are updated from gradients; Adam adapts the step size per parameter.
- AIAdvanced
Dropout & Batch Normalization
Dropout randomly disables neurons during training; batch norm normalizes layer inputs per mini-batch.
- AIAdvanced
Attention Mechanism
Attention lets a model weigh every token against every other using queries, keys and values.
- AIAdvanced
Generative AI & Diffusion Models
Generative models create new data; diffusion models learn to remove noise step by step to produce images.
- AIBeginner
AI Ethics & Bias
AI ethics studies fairness, privacy, transparency and safety of AI systems.
- DSAIntermediate
Kadane's Algorithm
Kadane's algorithm finds the maximum-sum contiguous subarray by extending or restarting a running sum.
- DSAIntermediate
Dutch National Flag (Sort 0/1/2)
Three pointers partition an array of 0s, 1s and 2s in a single pass.
- DSAIntermediate
Fast & Slow Pointers
Two pointers move at different speeds to detect cycles or find middles.
- DSAIntermediate
Merge Intervals
Sort intervals by start, then merge each one into the previous if they overlap.
- DSAIntermediate
Top-K with Heaps
Keep a min-heap of size k; its top is the k-th largest element.
- DSAAdvanced
LRU Cache Design
An LRU cache evicts the least recently used item when full, using a hash map plus ordered list.
- DSAAdvanced
Bellman-Ford
Bellman-Ford relaxes all edges V−1 times to find shortest paths, even with negative weights.
- DSABeginner
Sieve of Eratosthenes & Number Theory
The sieve marks multiples of each prime to list all primes up to n; GCD uses Euclid's algorithm.
- DSAAdvanced
String Matching (KMP)
KMP finds a pattern in text in linear time using a prefix (LPS) table to avoid rechecking.
- DSAAdvanced
Segment Tree & Fenwick Tree
Segment and Fenwick trees answer range queries and point updates in O(log n).
- PythonBeginner
Variables, Input & Output
Variables name values; input() reads text from the user and print() writes output.
- PythonIntermediate
Recursion & Memoization in Python
Recursive functions call themselves; functools.lru_cache stores results to avoid repeat work.
- PythonIntermediate
Sorting with Keys & heapq
sorted() and list.sort() accept key functions; heapq provides a priority queue.
- PythonIntermediate
Type Hints & Dataclasses
Type hints describe expected types; @dataclass auto-generates __init__, __repr__ and __eq__.
- PythonAdvanced
Async / Await
asyncio runs many I/O tasks concurrently in one thread using coroutines with async and await.
- PythonIntermediate
Regular Expressions
The re module matches text patterns such as emails, numbers and dates.
- Machine LearningIntermediate
Polynomial Regression
Polynomial regression fits curves by adding powers of features (x², x³) to linear regression.
- Machine LearningIntermediate
ROC Curve & AUC
The ROC curve plots true-positive rate against false-positive rate across thresholds; AUC summarizes it.
- Machine LearningIntermediate
Handling Imbalanced Data
Imbalanced data has far fewer examples of one class, so models may ignore it.
- Machine LearningAdvanced
DBSCAN & Hierarchical Clustering
DBSCAN groups dense regions and marks outliers; hierarchical clustering builds a tree of merges.
- Machine LearningIntermediate
Ensemble Learning (Bagging, Voting, Stacking)
Ensembles combine several models so their errors cancel out.
- Machine LearningIntermediate
Time Series Forecasting Basics
Time series models predict future values from past ordered data, using trend, seasonality and lags.
- AIBeginner
Tokenization
Tokenization splits text into tokens (words or sub-words) that language models turn into numbers.
- AIIntermediate
Word Embeddings (Word2Vec)
Word embeddings represent words as dense vectors so similar words are close together.
- AIIntermediate
Transfer Learning & Fine-Tuning
Transfer learning reuses a model trained on a big dataset and fine-tunes it on a smaller task.
- AIAdvanced
AI Agents & Tool Use
An AI agent is an LLM that plans, calls tools (search, code, APIs) and loops until a goal is done.
- AIAdvanced
Object Detection (YOLO)
Object detection finds and labels objects with bounding boxes in images.
- AIBeginner
Knowledge Representation & Logic
Classic AI represents facts and rules in logic so a system can infer new facts.
- DSAIntermediate
Matrix Rotation & Spiral Traversal
Matrix problems walk a 2D array in special orders such as spiral, or transform it such as rotating 90°.
- DSABeginner
Hash Map Patterns (Two Sum)
Store seen values in a hash map so the complement of each element is found in O(1).
- DSAIntermediate
Cycle Detection in Graphs
Directed graphs use DFS colors (white/gray/black); undirected graphs check visited neighbors that are not the parent.
- DSAIntermediate
Bipartite Graph Check
A graph is bipartite if nodes can be colored with two colors so no edge joins same colors.
- DSAIntermediate
Coin Change
Find the fewest coins that make an amount, using unlimited coins of each type.
- DSAAdvanced
Longest Increasing Subsequence
LIS is the longest subsequence with strictly increasing values.
- DSAAdvanced
Edit Distance
Edit distance is the minimum insertions, deletions and replacements to turn one string into another.
- DSAAdvanced
N-Queens
Place N queens on an N×N board so none attack each other.
- DSAIntermediate
Permutations & Combinations
Permutations are ordered arrangements; combinations are unordered selections.
- DSAIntermediate
Activity Selection & Jump Game
Greedy choices like 'earliest finishing activity' or 'farthest reachable index' give optimal answers.
- PythonBeginner
Operators & Expressions
Operators perform arithmetic (+ − * / // % **), comparison, logical (and/or/not) and membership (in).
- PythonBeginner
Lists & Tuples In Depth
Lists are mutable ordered collections; tuples are immutable ordered collections.
- PythonIntermediate
Scope & Closures
Python resolves names by LEGB (Local, Enclosing, Global, Built-in); closures remember enclosing variables.
- PythonIntermediate
Testing with unittest & pytest
Tests are code that checks other code automatically using assertions.
- PythonAdvanced
Memory Model & the GIL
Python variables are references to objects; the GIL lets only one thread run Python bytecode at a time.
- Machine LearningBeginner
End-to-End ML Workflow
An ML project goes from problem definition to data, model, evaluation and deployment.
- Machine LearningBeginner
Exploratory Data Analysis
EDA summarizes and visualizes data to find patterns, outliers and missing values before modeling.
- Machine LearningBeginner
Correlation & Covariance
Covariance measures how two variables move together; correlation scales it to −1…1.
- Machine LearningBeginner
Probability & Statistics for ML
Probability measures uncertainty; distributions, expectation and variance describe data.
- Machine LearningIntermediate
Linear Algebra for ML
Vectors, matrices, dot products and matrix multiplication are the language of ML models.
- Machine LearningAdvanced
Model Deployment & MLOps
Deployment serves a trained model behind an API; MLOps automates training, versioning and monitoring.
- AIIntermediate
Minimax & Alpha-Beta Pruning
Minimax picks the best move assuming the opponent plays optimally; alpha-beta skips branches that can't matter.
- AIIntermediate
Constraint Satisfaction Problems
CSPs assign values to variables so all constraints hold, e.g. map coloring or Sudoku.
- AIIntermediate
Genetic Algorithms
Genetic algorithms evolve a population of solutions using selection, crossover and mutation.
- AIIntermediate
Speech Recognition & TTS
Speech recognition converts audio to text; text-to-speech generates audio from text.
- AIAdvanced
LLM Hallucinations & Evaluation
Hallucinations are confident but false LLM outputs; evaluation measures accuracy, grounding and safety.
- AIBeginner
Types of AI (Narrow, General, Super)
Narrow AI does specific tasks; general AI would match humans broadly; superintelligence would exceed them.