Technique: break problem into smaller parts, solve recursively, combine results, Divide & Conquer, Split the problem into smaller subproblems, Divide, Recursively solve each subproblem, Conquer, Merge subproblem results into the final solution, Combine, Divide-and-conquer sort; always O(n log n) for all cases, Merge Sort, Search by halving sorted array; requires sorted input; O(log n), Binary Search, Find maximum and minimum in array; O(n) using divide and conquer, Max-Min Problem, Time complexity common to divide and conquer sorting algorithms, O(n log n), A function that calls itself to solve smaller versions of the same problem, Recursion, DIVIDE → CONQUER → COMBINE, 3 Phases of Divide & Conquer, Binary Search, Merge Sort, Quick Sort, Max-Min, Strassen, 5 Common D&C Algorithms, Find mid → Compare → Narrow half → Repeat, Binary Search Steps, O(n log n) for ALL cases (best, average, worst), Merge Sort Time Complexity, Best O(1) | Average O(log n) | Worst O(log n), Binary Search Cases, D&C matrix multiplication using 7 multiplications instead of 8; introduced 1969, Strassen's Algorithm, Strassen's 7 pre-computed products used to derive the result matrix, M1–M7, Makes the locally optimal choice at each step hoping for global optimum, Greedy Algorithm, Best choice at the current step without considering future consequences, Locally Optimal, Best overall solution across all possible choices, Globally Optimal, The condition where a greedy approach is guaranteed to give the correct answer, Greedy Property, Choose largest coin denomination first; works only with standard coin systems, Coin Change (Greedy), Classic greedy problem: select maximum activities that don't overlap, Activity Selection, Greedy algorithm for lossless data compression, Huffman Coding, 8 multiplications + 4 additions, Standard Matrix Multiplication, 7 multiplications (saves 1 multiplication at cost of more additions), Strassen's Method, Define problem → Choose best immediate option → Repeat, 3 Greedy Strategy Steps, Activity Selection, Fractional Knapsack, Huffman Coding, Prim's, Kruskal's, Dijkstra's, 6 Classic Greedy Problems, More additions, not efficient for small matrices, higher memory, Strassen Disadvantages, Greedy optimization: take fractions of items to maximize value within weight limit, Fractional Knapsack, Key metric in fractional knapsack; sort items by this in descending order, Value/Weight Ratio, Schedule jobs to maximize profit; assign each job to latest slot ≤ its deadline, Job Sequencing, The last time slot a job can be completed to count for profit, Deadline (Job Seq.), A unit of time period used in job scheduling; one job per slot, Time Slot, DP version: items CANNOT be split; requires dynamic programming, 0/1 Knapsack, Value/Weight Ratio — higher ratio = take first, Greedy Basis (Knapsack), Profit — higher profit job is scheduled first, Greedy Basis (Jobs), Compute ratios → Sort descending → Take full/partial items, Fractional Knapsack Steps, Sort by profit → Create slots → Assign to LATEST available slot ≤ deadline, Job Sequencing Steps, O(n log n) due to sorting, Fractional Knapsack Time Complexity, Sorting O(n log n) + Scheduling O(n²), Job Sequencing Time Complexity, Fractional Knapsack allows splitting; Job Sequencing does NOT, Key Difference, Technique: solve subproblems once, store results, reuse to avoid recomputation, Dynamic Programming (DP), Same subproblems appear multiple times — DP stores results to avoid repeat work, Overlapping Subproblems, Optimal solution can be built from optimal solutions of smaller subproblems, Optimal Substructure, Recursive DP; cache results in dict/array; solve only needed subproblems, Memoization (Top-Down), Iterative DP; fill table from base case upward; preferred in production, Tabulation (Bottom-Up), Formula that defines DP solution in terms of smaller subproblem solutions, Recurrence Relation, Smallest subproblem with a known answer (e.g., fib(0)=0, fib(1)=1), Base Case, Longest Common Subsequence — longest shared sequence in two strings, LCS, Items cannot be split; DP builds table of max values per weight, 0/1 Knapsack, Minimum coins for a target; DP required when denominations are irregular, Coin Change (DP), Optimal order of matrix multiplications to minimize total operations, Matrix Chain Mult., Cut rod to maximize revenue; similar to Unbounded Knapsack, Rod Cutting, Overlapping Subproblems + Optimal Substructure, 2 Key DP Requirements, Top-Down (Memoization) vs Bottom-Up (Tabulation), 2 DP Approaches, Without DP = O(2ⁿ) | With DP = O(n), Fibonacci Complexity, Identify subproblems → Check overlap → Define recurrence → Choose approach → Store results, 5 Steps to Solve DP, Fibonacci, 0/1 Knapsack, LCS, Coin Change, Matrix Chain, Rod Cutting, 6 Common DP Problems, Brute Force (all possibilities) | Greedy (local optimal) | DP (store & reuse), 3 Technique Comparison, Data structure representing relationships: set of vertices and edges, Graph, An entity or object in a graph, Vertex / Node, A connection between two vertices, Edge / Link, Edges have direction (u → v only), Directed Graph (Digraph), Edges have no direction (u ↔ v), Undirected Graph, Edges carry a cost or weight value, Weighted Graph, Directed Acyclic Graph — no cycles, edges go one direction, DAG, 2D array to represent graph; O(V²) space; fast lookup, Adjacency Matrix, Array of neighbor lists; O(V+E) space; space efficient, Adjacency List, Breadth-First Search — level-by-level traversal using a Queue, BFS, Depth-First Search — deep traversal using Stack or recursion, DFS, Subgraph with all vertices, no cycles, exactly V-1 edges, Spanning Tree, Minimum Spanning Tree — spanning tree with smallest total weight, MST, MST: edge-based, sort edges by weight, use Union-Find; best for sparse graphs, Kruskal's Algorithm, MST: vertex-based, grow tree from any node, use Priority Queue; best for dense graphs, Prim's Algorithm, Shortest path: non-negative weights only; greedy; O((V+E) log V), Dijkstra's Algorithm, Shortest path: handles negative weights; detects negative cycles; O(VE), Bellman-Ford, All-pairs shortest path; check all intermediate nodes; O(V³), Floyd-Warshall, Layered DAG; solved with backward DP; no priority queue needed; O(E), Multistage Graph, Data structure used in Kruskal's to detect cycles efficiently, Union-Find, Undirected, Directed, Unweighted, Weighted, Cyclic, Acyclic (DAG), Connected, Disconnected, 8 Types of Graphs, Adjacency Matrix (O(V²)) vs Adjacency List (O(V+E)), 2 Graph Representation Methods, BFS (Queue, level-by-level) | DFS (Stack, deep-first), 2 Traversal Algorithms, All vertices included + No cycles + Exactly V-1 edges, 3 Properties of Spanning Tree, Kruskal's (edge-based, sparse) | Prim's (vertex-based, dense), 2 MST Algorithms, Dijkstra (no negatives) | Bellman-Ford (negatives OK) | Floyd-Warshall (all-pairs), 3 Shortest Path Algorithms, Layered DAG + Backward DP + O(E) time + No priority queue needed, Multistage Graph, Complexity = O((V+E)logV) | O(VE) | O(V³), Dijkstra vs Bellman-Ford vs Floyd.
0%
AC
Chia sẻ
Chia sẻ
Chia sẻ
bởi
Plandezagelyn
Chỉnh sửa nội dung
In
Nhúng
Nhiều hơn
Tập
Bảng xếp hạng
Hiển thị thêm
Ẩn bớt
Bảng xếp hạng này hiện đang ở chế độ riêng tư. Nhấp
Chia sẻ
để công khai bảng xếp hạng này.
Chủ sở hữu tài nguyên đã vô hiệu hóa bảng xếp hạng này.
Bảng xếp hạng này bị vô hiệu hóa vì các lựa chọn của bạn khác với của chủ sở hữu tài nguyên.
Đưa các lựa chọn trở về trạng thái ban đầu
Thẻ thông tin
là một mẫu kết thúc mở. Mẫu này không tạo điểm số cho bảng xếp hạng.
Yêu cầu đăng nhập
Phong cách trực quan
Phông chữ
Yêu cầu đăng ký
Tùy chọn
Chuyển đổi mẫu
Hiển thị tất cả
Nhiều định dạng khác sẽ xuất hiện khi bạn phát hoạt động.
)
Mở kết quả
Sao chép liên kết
Mã QR
Xóa
Bạn có muốn khôi phục tự động lưu:
không?