Artificial Intelligence Master Cheat Sheet: Formulas, Complexity & Code

This master reference cheat sheet provides a rapid, high-density summary of core formulas, algorithmic time and space complexities, mathematical symbols, and essential Python syntax across the entire artificial intelligence curriculum.

Algorithm Complexity Quick Reference

Algorithm Time Complexity Space Complexity Complete? Optimal?
Breadth-First Search (BFS) ( O(b^d) ) ( O(b^d) ) Yes Yes (unit costs)
Depth-First Search (DFS) ( O(b^m) ) ( O(b cdot m) ) No No
Iterative Deepening (IDS) ( O(b^d) ) ( O(b cdot d) ) Yes Yes (unit costs)
A* Search ( O(b^d) ) (worst) ( O(b^d) ) Yes Yes (if admissible)
Minimax (Full Tree) ( O(b^m) ) ( O(b cdot m) ) Yes Yes
Alpha-Beta Pruning ( O(b^{m/2}) ) (best) ( O(b cdot m) ) Yes Yes
K-Means Clustering ( O(I cdot K cdot N cdot d) ) ( O(N cdot d) ) Heuristic Local optimum
Self-Attention Layer ( O(N^2 cdot d) ) ( O(N^2 + N cdot d) ) Deterministic N/A

Essential Mathematical Formulas

  • A* Heuristic: ( f(n) = g(n) + h(n) )
  • Bayes' Theorem: ( P(H | E) = rac{P(E | H) cdot P(H)}{P(E)} )
  • Sigmoid Function: ( sigma(z) = rac{1}{1 + e^{-z}} )
  • Binary Cross-Entropy (Log-Loss): ( - rac{1}{N} sum [y ln hat{y} + (1-y) ln(1-hat{y})] )
  • Shannon Entropy: ( H(S) = - sum p_i log_2(p_i) )
  • Gini Impurity: ( ext{Gini}(S) = 1 - sum p_i^2 )
  • Scaled Dot-Product Attention: ( ext{Attention}(Q, K, V) = ext{softmax}left( rac{QK^T}{sqrt{d_k}} ight)V )
  • Cosine Similarity: ( cos( heta) = rac{mathbf{u} cdot mathbf{v}}{|mathbf{u}| |mathbf{v}|} )

Essential Python One-Liners & CLI Commands

# PyTorch: Set device dynamically
device = torch.device("cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu"))

# Hugging Face: Instant Text Generation Pipeline
from transformers import pipeline
generator = pipeline('text-generation', model='meta-llama/Meta-Llama-3-8B-Instruct', device_map='auto')
output = generator("Explain quantum computing in 2 sentences.", max_new_tokens=50)

# ChromaDB: Instant Vector Search
import chromadb
client = chromadb.Client()
coll = client.create_collection("docs")
coll.add(documents=["AI rules the world", "Cats are cute"], ids=["1", "2"])
print(coll.query(query_texts=["artificial intelligence"], n_results=1))

# Launch Local Model with Ollama CLI
ollama run llama3

Frequently Asked Questions (FAQ) - Student & Interview Review

Q1. What is the fastest way to memorize AI search complexities for exams?

Remember that b is the branching factor, d is goal depth, and m is maximum depth. Breadth-first algorithms depend exponentially on goal depth d: O(b^d). Depth-first algorithms plunge down maximum depth m: O(b^m). Iterative Deepening gives you the time complexity of BFS with the linear space complexity of DFS: O(b*d).

Q2. What is the difference between PyTorch CPU, CUDA, and MPS?

CPU executes on standard computer processors. CUDA executes on NVIDIA graphics cards (the enterprise deep learning standard). MPS (Metal Performance Shaders) executes on Apple Silicon (M1/M2/M3/M4) unified memory GPUs on macOS.

Q3. What is the purpose of Hugging Face device_map='auto'?

device_map='auto' uses the Accelerate library to automatically inspect your computer's available hardware (VRAM across multiple GPUs, system CPU RAM, and disk swap), splitting and offloading model layers to maximize memory efficiency without manual GPU allocation code.

Q4. How can I quickly convert Hugging Face PyTorch models into fast ONNX format?

Use the Hugging Face Optimum library CLI: optimum-cli export onnx --model meta-llama/Meta-Llama-3-8B-Instruct --task text-generation-with-past onnx_model/. This exports the graph for fast WebGPU and C++ runtimes.

Explore Related Artificial Intelligence Tutorials & Next Steps

Broaden your foundational and advanced AI knowledge across our curriculum:

30+ AI Practice Exercises

Apply cheat sheet code snippets directly into executable lab projects.

120+ AI Technical Interview Q&A

Deepen your conceptual mastery of the formulas and libraries listed.

AI Career Blueprint & Freelancing

Build in-demand skills and launch a career in artificial intelligence.

AI Tutorial Complete Syllabus

Explore all 52 comprehensive classes of the Veewom AI tutorial series.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!