Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 744ecb1

Browse files
authored
formatting
1 parent 2b3487e commit 744ecb1

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

‎revision/Revision.md

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
11
# Patterns for Problem Solving
22

33
## Pattern: Two Pointers
4-
**Description:** This method uses two pointers to traverse an array or a list from different ends or directions.
5-
**Usage:** It's particularly useful for ordered data structures, where we can make intelligent decisions based on the position of the pointers.
6-
**Problems:** 'Pair with Target Sum', 'Remove Duplicates', 'Squaring a Sorted Array'.
4+
**Description:** This method uses two pointers to traverse an array or a list from different ends or directions.
5+
**Usage:** It's particularly useful for ordered data structures, where we can make intelligent decisions based on the position of the pointers.
6+
**Problems:** 'Pair with Target Sum', 'Remove Duplicates', 'Squaring a Sorted Array'.
77

88
## Pattern: Island (Matrix Traversal)
9-
**Description:** It involves traversing a matrix to find 'islands' or contiguous groups of elements.
10-
**Usage:** It's generally used in grid-based problems, especially when we need to group connected elements together.
11-
**Problems:** 'Number of Islands', 'Max Area of Island', 'Flood Fill'.
9+
**Description:** It involves traversing a matrix to find 'islands' or contiguous groups of elements.
10+
**Usage:** It's generally used in grid-based problems, especially when we need to group connected elements together.
11+
**Problems:** 'Number of Islands', 'Max Area of Island', 'Flood Fill'.
1212

1313
## Pattern: Fast & Slow Pointers
14-
**Description:** In this method, two pointers move at different speeds in a data structure.
15-
**Usage:** It is commonly used to detect cycles in a structure, find middle elements, or to solve other specific problems related to linked lists.
16-
**Problems:** 'LinkedList Cycle', 'Middle of the LinkedList', 'Palindrome LinkedList'.
14+
**Description:** In this method, two pointers move at different speeds in a data structure.
15+
**Usage:** It is commonly used to detect cycles in a structure, find middle elements, or to solve other specific problems related to linked lists.
16+
**Problems:** 'LinkedList Cycle', 'Middle of the LinkedList', 'Palindrome LinkedList'.
1717

1818
## Pattern: Sliding Window
19-
**Description:** This pattern involves creating a 'window' into the data structure and then moving that window around to gather specific information.
20-
**Usage:** Mostly used in array or list-based problems where you need to find a contiguous subset that fulfills certain conditions.
21-
**Problems:** 'Maximum Sum Subarray of Size K', 'Smallest Subarray with a given sum', 'Longest Substring with K Distinct Characters'.
19+
**Description:** This pattern involves creating a 'window' into the data structure and then moving that window around to gather specific information.
20+
**Usage:** Mostly used in array or list-based problems where you need to find a contiguous subset that fulfills certain conditions.
21+
**Problems:** 'Maximum Sum Subarray of Size K', 'Smallest Subarray with a given sum', 'Longest Substring with K Distinct Characters'.
2222

2323
## Pattern: Merge Intervals
24-
**Description:** This pattern involves merging overlapping intervals.
25-
**Usage:** Often used in problems involving time intervals, ranges, or sequences.
26-
**Problems:** 'Merge Intervals', 'Insert Interval', 'Intervals Intersection'.
24+
**Description:** This pattern involves merging overlapping intervals.
25+
**Usage:** Often used in problems involving time intervals, ranges, or sequences.
26+
**Problems:** 'Merge Intervals', 'Insert Interval', 'Intervals Intersection'.
2727

2828
## Pattern: Cyclic Sort
29-
**Description:** This pattern involves sorting an array containing numbers in a given range.
30-
**Usage:** It's useful in situations where the data involves a finite range of natural numbers.
31-
**Problems:** 'Cyclic Sort', 'Find the Missing Number', 'Find all Duplicates'.
29+
**Description:** This pattern involves sorting an array containing numbers in a given range.
30+
**Usage:** It's useful in situations where the data involves a finite range of natural numbers.
31+
**Problems:** 'Cyclic Sort', 'Find the Missing Number', 'Find all Duplicates'.
3232

3333
## Pattern: In-place Reversal of a Linked List
34-
**Description:** This pattern involves reversing elements of a linked list in-place.
35-
**Usage:** It's generally used when reversing a sequence without using extra space.
36-
**Problems:** 'Reverse a LinkedList', 'Reverse a Sub-list', 'Reverse Every K-element Sub-list'.
34+
**Description:** This pattern involves reversing elements of a linked list in-place.
35+
**Usage:** It's generally used when reversing a sequence without using extra space.
36+
**Problems:** 'Reverse a LinkedList', 'Reverse a Sub-list', 'Reverse Every K-element Sub-list'.
3737

3838
## Pattern: Tree Breadth First Search
39-
**Description:** This pattern involves level-by-level traversal of a tree.
40-
**Usage:** It's used when we need to traverse a tree or graph in a level-by-level (breadth-first) manner.
41-
**Problems:** 'Level Order Traversal', 'Reverse Level Order Traversal', 'Zigzag Traversal'.
39+
**Description:** This pattern involves level-by-level traversal of a tree.
40+
**Usage:** It's used when we need to traverse a tree or graph in a level-by-level (breadth-first) manner.
41+
**Problems:** 'Level Order Traversal', 'Reverse Level Order Traversal', 'Zigzag Traversal'.
4242

4343
## Pattern: Tree Depth First Search
44-
**Description:** This pattern involves traversing a tree or graph depth-wise before visiting siblings or neighbors.
45-
**Usage:** It's used when you need to search deeper into a tree/graph first before going across.
46-
**Problems:** 'Binary Tree Path Sum', 'All Paths for a Sum', 'Count Paths for a Sum'.
44+
**Description:** This pattern involves traversing a tree or graph depth-wise before visiting siblings or neighbors.
45+
**Usage:** It's used when you need to search deeper into a tree/graph first before going across.
46+
**Problems:** 'Binary Tree Path Sum', 'All Paths for a Sum', 'Count Paths for a Sum'.
4747

4848
## Pattern: Two Heaps
49-
**Description:** This pattern involves using two heaps to divide a set of numbers into two parts.
50-
**Usage:** It's useful when you need to find median numbers in a sequence, or other similar problems.
51-
**Problems:** 'Find the Median of a Number Stream', 'Sliding Window Median', 'Maximize Capital'.
49+
**Description:** This pattern involves using two heaps to divide a set of numbers into two parts.
50+
**Usage:** It's useful when you need to find median numbers in a sequence, or other similar problems.
51+
**Problems:** 'Find the Median of a Number Stream', 'Sliding Window Median', 'Maximize Capital'.
5252

5353
## Pattern: Subsets
54-
**Description:** This pattern involves generating all subsets of a set.
55-
**Usage:** It's helpful for solving problems that require exploring all subsets of a given set.
56-
**Problems:** 'Subsets', 'Subsets With Duplicates', 'Permutations'.
54+
**Description:** This pattern involves generating all subsets of a set.
55+
**Usage:** It's helpful for solving problems that require exploring all subsets of a given set.
56+
**Problems:** 'Subsets', 'Subsets With Duplicates', 'Permutations'.
5757

5858
## Pattern: Modified Binary Search
59-
**Description:** This is a tweaked version of the binary search algorithm.
60-
**Usage:** It's used when a simple binary search isn't sufficient, like finding a number in a bitonic array.
61-
**Problems:** 'Order-agnostic Binary Search', 'Ceiling of a Number', 'Next Letter'.
59+
**Description:** This is a tweaked version of the binary search algorithm.
60+
**Usage:** It's used when a simple binary search isn't sufficient, like finding a number in a bitonic array.
61+
**Problems:** 'Order-agnostic Binary Search', 'Ceiling of a Number', 'Next Letter'.
6262

6363
## Pattern: Top 'K' Elements
64-
**Description:** This pattern is used to find the top 'k' elements among a certain category.
65-
**Usage:** It's commonly used in problems involving sorting, searching, and in heap data structures.
66-
**Problems:** 'Top K Frequent Numbers', 'Kth Largest Number in a Stream', 'Top K Frequent Elements'.
64+
**Description:** This pattern is used to find the top 'k' elements among a certain category.
65+
**Usage:** It's commonly used in problems involving sorting, searching, and in heap data structures.
66+
**Problems:** 'Top K Frequent Numbers', 'Kth Largest Number in a Stream', 'Top K Frequent Elements'.
6767

6868
## Pattern: Bitwise XOR
69-
**Description:** This pattern involves the use of Bitwise XOR to solve various array-based problems.
70-
**Usage:** It's used when we need to manipulate and compare bits directly.
71-
**Problems:** 'Single Number', 'Two Single Numbers', 'Complement of Base 10 Number'.
69+
**Description:** This pattern involves the use of Bitwise XOR to solve various array-based problems.
70+
**Usage:** It's used when we need to manipulate and compare bits directly.
71+
**Problems:** 'Single Number', 'Two Single Numbers', 'Complement of Base 10 Number'.
7272

7373
## Pattern: Backtracking
74-
**Description:** This pattern involves exploring all possible solutions and then backtracking to correct the course whenever you're on the wrong path.
75-
**Usage:** It's typically used for solving complex combinatorial problems, puzzles, and games.
76-
**Problems:** 'Sudoku Solver', 'N-Queens', 'Generate Parentheses'.
74+
**Description:** This pattern involves exploring all possible solutions and then backtracking to correct the course whenever you're on the wrong path.
75+
**Usage:** It's typically used for solving complex combinatorial problems, puzzles, and games.
76+
**Problems:** 'Sudoku Solver', 'N-Queens', 'Generate Parentheses'.
7777

7878
## Pattern: 0/1 Knapsack (Dynamic Programming)
79-
**Description:** This pattern deals with problems where items have different values and weights, and we need to determine the maximum value we can carry.
80-
**Usage:** It's typically used in optimization problems, especially those involving physical constraints.
81-
**Problems:** '0/1 Knapsack', 'Equal Subset Sum Partition', 'Subset Sum'.
79+
**Description:** This pattern deals with problems where items have different values and weights, and we need to determine the maximum value we can carry.
80+
**Usage:** It's typically used in optimization problems, especially those involving physical constraints.
81+
**Problems:** '0/1 Knapsack', 'Equal Subset Sum Partition', 'Subset Sum'.
8282

8383
## Pattern: Topological Sort (Graph)
84-
**Description:** This pattern involves sorting nodes in a directed graph in a specific order where the preceding node comes before the following node.
85-
**Usage:** It's used for scheduling problems and in scenarios where order needs to be imposed on how you process nodes.
86-
**Problems:** 'Task Scheduling Order', 'All Tasks Scheduling Orders', 'Alien Dictionary'.
84+
**Description:** This pattern involves sorting nodes in a directed graph in a specific order where the preceding node comes before the following node.
85+
**Usage:** It's used for scheduling problems and in scenarios where order needs to be imposed on how you process nodes.
86+
**Problems:** 'Task Scheduling Order', 'All Tasks Scheduling Orders', 'Alien Dictionary'.
8787

8888
## Pattern: K-way Merge
89-
**Description:** This pattern involves merging 'k' sorted lists.
90-
**Usage:** It's typically used in problems involving lists, where merging is required.
91-
**Problems:** 'Merge K Sorted Lists', 'Kth Smallest Number in M Sorted Lists', 'Smallest Number Range'.
89+
**Description:** This pattern involves merging 'k' sorted lists.
90+
**Usage:** It's typically used in problems involving lists, where merging is required.
91+
**Problems:** 'Merge K Sorted Lists', 'Kth Smallest Number in M Sorted Lists', 'Smallest Number Range'.
9292

9393
## Pattern: Monotonic Stack
94-
**Description:** This pattern involves using a stack to maintain a monotonic (either entirely non-increasing or non-decreasing) order of elements.
95-
**Usage:** It's often used for solving problems where you need to find the next greater or smaller elements.
96-
**Problems:** 'Next Greater Element', 'Next Smaller Element', 'Largest Rectangle in Histogram'.
94+
**Description:** This pattern involves using a stack to maintain a monotonic (either entirely non-increasing or non-decreasing) order of elements.
95+
**Usage:** It's often used for solving problems where you need to find the next greater or smaller elements.
96+
**Problems:** 'Next Greater Element', 'Next Smaller Element', 'Largest Rectangle in Histogram'.
9797

9898
## Pattern: Multi-threaded
99-
**Description:** This pattern involves designing algorithms that can execute multiple threads in parallel.
100-
**Usage:** It's used in situations where a task can be divided into independent sub-tasks that can execute concurrently.
101-
**Problems:** 'Invert Binary Tree', 'Binary Search Tree Iterator', 'Same Tree'.
99+
**Description:** This pattern involves designing algorithms that can execute multiple threads in parallel.
100+
**Usage:** It's used in situations where a task can be divided into independent sub-tasks that can execute concurrently.
101+
**Problems:** 'Invert Binary Tree', 'Binary Search Tree Iterator', 'Same Tree'.
102102

103103
## Pattern: Union Find
104-
**Description:** Union Find, also known as Disjoint Set Union (DSU), is a data structure that keeps track of a partition of a set into disjoint subsets.
105-
**Usage:** This pattern is particularly useful for problems where we need to find whether 2 elements belong to the same group or need to solve connectivity-related problems in a graph or tree.
106-
**Problems:** 'Graph Redundant Connection', 'Number of Provinces', 'Is Graph Bipart
104+
**Description:** Union Find, also known as Disjoint Set Union (DSU), is a data structure that keeps track of a partition of a set into disjoint subsets.
105+
**Usage:** This pattern is particularly useful for problems where we need to find whether 2 elements belong to the same group or need to solve connectivity-related problems in a graph or tree.
106+
**Problems:** 'Graph Redundant Connection', 'Number of Provinces', 'Is Graph Bipart'.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /