Part 5: Discrete Mathematics and Algorithms
The Performance Bug That Taught Me Discrete Math
def has_duplicates_v1(items):
"""Check if list has any duplicate elements"""
for i in range(len(items)):
for j in range(i + 1, len(items)):
if items[i] == items[j]:
return True
return Falsedef has_duplicates_v2(items):
"""Check using set properties"""
return len(items) != len(set(items))What is Discrete Mathematics?
Set Theory: Foundation of Data Structures
Basic Set Operations
Real Application: Finding Common Elements
Set-Based Deduplication
Logic and Boolean Algebra
Truth Tables and Logic Gates
De Morgan's Laws
Combinatorics: Counting Possibilities
Permutations (order matters)
Combinations (order doesn't matter)
Real Application: Testing Combinations
Recurrence Relations and Recursion
Understanding Recurrence
Solving Recurrence Relations
Algorithm Complexity Analysis
Big O Notation
Analyzing Your Own Code
Choosing the Right Data Structure
Pigeonhole Principle
Key Takeaways
What's Next
Navigation
Last updated