Time and Space Complexity Flashcards
Focus on the complexity analysis of different algorithms and data structures.
What is Omega (Ω) Notation?
Omega Notation describes the lower bound of the time complexity of an algorithm. It gives the best-case scenario, or the minimum time required by an algorithm.
What is Theta (Θ) Notation?
Theta Notation tightly bounds the time complexity of an algorithm. It represents the exact upper and lower bounds of the time required for the algorithm.
Time Complexity of Common Sorting Algorithms
Bubble Sort: O(n^2)
Quick Sort: Average - O(n log n), Worst - O(n^2)
Merge Sort: O(n log n)
Insertion Sort: Average - O(n^2), Best - O(n)
What algorithms and patterns are suitable for an input size of 10 (10^1)?
Time Complexity: O(n!)
Problems: Permutations, Traveling Salesman Problem, Exhaustive Search
Patterns: Backtracking, Brute Force
Algorithms: Permutation Generation, Hamiltonian Cycle
What algorithms and patterns are suitable for an input size of 100 (10^2)?
Time Complexity: O(n³)
Problems: Smaller Dynamic Programming Problems, Dense Graphs
Patterns: Dynamic Programming, Graph Algorithms
Algorithms: Floyd-Warshall, Subset Sum
What algorithms and patterns are suitable for an input size of 1000 (10^3)?
Time Complexity: O(n²)
Problems: Medium Dynamic Programming Problems, Basic Sorting
Patterns: Dynamic Programming, Divide and Conquer
Algorithms: Bubble Sort, Insertion Sort, Selection Sort
What algorithms and patterns are suitable for an input size of 10000 (10^4)?
Time Complexity: O(n log n) / O(n√n)
Problems: Larger Sorting, Efficient Graph Algorithms
Patterns: Divide and Conquer, Greedy Algorithms
Algorithms: Merge Sort, Quick Sort, Heap Sort
What algorithms and patterns are suitable for an input size of 100000 (10^5)?
Time Complexity: O(n log n) / O(n)
Problems: Large Scale Sorting, Segment Trees, Efficient Graph Traversal
Patterns: Greedy Algorithms, Graph Theory
Algorithms: Merge Sort, Quick Sort, Dijkstra’s Algorithm
What algorithms and patterns are suitable for an input size of 1000000 (10^6)?
Time Complexity: O(n) / O(log n)
Problems: Linear Searches, Binary Searches, Simple Loops
Patterns: Searching and Traversal, Graph Theory
Algorithms: Linear Search, Binary Search, BFS, DFS
How do you calculate the number of digits in n = 1000?
Use the formula d = floor(log10(n)) + 1
. For n = 1000, log10(1000) = 3, so d = 3 + 1 = 4. Therefore, 1000 has 4 digits.
What is the time complexity of the logarithmic relationship in algorithms that process each digit of a number?
For algorithms that involve operations on each digit of a number (like summing digits), the time complexity is O(log n). This is because the number of operations is tied to the number of digits, which grows logarithmically with the size of the number.