Sabitlenmiş Tweet
AlgoMaster.io
67 posts

AlgoMaster.io
@algomaster_io
Master DSA and System Design with visual explanations. Learn more here: https://t.co/jkSAEHWpOb
Katılım Haziran 2024
1 Takip Edilen4.9K Takipçiler

If you want to learn Big O and time complexity in more detail, click here: algomaster.io/learn/dsa/big-…
English

10 Must-Know Time Complexity Patterns for Interviews:
1. 𝐇𝐚𝐬𝐡 𝐋𝐨𝐨𝐤𝐮𝐩 - 𝐎(1) 𝐚𝐯𝐞𝐫𝐚𝐠𝐞
A lookup usually takes constant time, regardless of input size. In the worst case, it can degrade to O(n).
2. 𝐇𝐚𝐥𝐯𝐢𝐧𝐠 𝐋𝐨𝐨𝐩 - 𝐎(𝐥𝐨𝐠 𝐧)
The input size is divided by a constant factor in every step, such as in binary search.
3. 𝐒𝐢𝐧𝐠𝐥𝐞 𝐋𝐨𝐨𝐩 - 𝐎(𝐧)
Each element is processed once.
4. 𝐒𝐞𝐪𝐮𝐞𝐧𝐭𝐢𝐚𝐥 𝐋𝐨𝐨𝐩𝐬 - 𝐎(𝐧 + 𝐦)
You iterate over two separate inputs one after another, not with one loop nested inside the other.
5. 𝐋𝐨𝐨𝐩 + 𝐁𝐢𝐧𝐚𝐫𝐲 𝐒𝐞𝐚𝐫𝐜𝐡 - 𝐎(𝐧 𝐥𝐨𝐠 𝐧)
A loop runs n times, and each iteration performs O(log n) work.
6. 𝐃𝐢𝐯𝐢𝐝𝐞 & 𝐂𝐨𝐧𝐪𝐮𝐞𝐫 - 𝐎(𝐧 𝐥𝐨𝐠 𝐧)
The problem is divided across roughly log n levels, with O(n) total work at each level. Merge sort is a common example.
7. 𝐍𝐞𝐬𝐭𝐞𝐝 𝐋𝐨𝐨𝐩𝐬 - 𝐎(𝐧²)
For every element, you iterate over all elements again.
8. 𝐓𝐫𝐢𝐚𝐧𝐠𝐮𝐥𝐚𝐫 𝐋𝐨𝐨𝐩 - 𝐎(𝐧²)
The inner loop performs fewer iterations each time, but the total is still roughly n(n − 1) / 2, which is quadratic.
9. 𝐁𝐫𝐚𝐧𝐜𝐡𝐢𝐧𝐠 𝐑𝐞𝐜𝐮𝐫𝐬𝐢𝐨𝐧 - 𝐄𝐱𝐩𝐨𝐧𝐞𝐧𝐭𝐢𝐚𝐥 𝐓𝐢𝐦𝐞
When each recursive call creates multiple new calls, the work can grow exponentially.
10. 𝐏𝐞𝐫𝐦𝐮𝐭𝐚𝐭𝐢𝐨𝐧𝐬 - 𝐎(𝐧!)
There are n! possible orderings, and producing or copying each complete permutation can take O(n) time.
♻️ Repost to help others in your network.
GIF
English

7 Must-Know Big-O Complexities for Interviews:
1. 𝐎(1) - 𝐂𝐨𝐧𝐬𝐭𝐚𝐧𝐭 𝐭𝐢𝐦𝐞
- The runtime doesn't change regardless of the input size.
- Example: Accessing an element in an array by its index.
2. 𝐎(𝐥𝐨𝐠 𝐧) - 𝐋𝐨𝐠𝐚𝐫𝐢𝐭𝐡𝐦𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows slowly as the input size increases. Typically seen in algorithms that divide the problem in half with each step.
- Example: Binary search in a sorted array.
3. 𝐎(𝐧) - 𝐋𝐢𝐧𝐞𝐚𝐫 𝐭𝐢𝐦𝐞
- The runtime grows linearly with the input size.
- Example: Finding an element in an array by iterating through each element.
4. 𝐎(𝐧 𝐥𝐨𝐠 𝐧) - 𝐋𝐢𝐧𝐞𝐚𝐫𝐢𝐭𝐡𝐦𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows slightly faster than linear time. It involves a logarithmic number of operations for each element in the input.
- Example: Sorting an array using quick sort or merge sort.
5. 𝐎(𝐧^2) - 𝐐𝐮𝐚𝐝𝐫𝐚𝐭𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows proportionally to the square of the input size.
- Example: Bubble sort algorithm which compares and potentially swaps every pair of elements.
6. 𝐎(2^𝐧) - 𝐄𝐱𝐩𝐨𝐧𝐞𝐧𝐭𝐢𝐚𝐥 𝐭𝐢𝐦𝐞
- The runtime doubles with each addition to the input. These algorithms become impractical for larger input sizes.
- Example: Generating all subsets of a set.
7. 𝐎(𝐧!) - 𝐅𝐚𝐜𝐭𝐨𝐫𝐢𝐚𝐥 𝐭𝐢𝐦𝐞
- Runtime is proportional to the factorial of the input size.
- Example: Generating all permutations of a set.
♻️ Repost to help others learn this
GIF
English

👉 If you want to master all important algorithms and patterns for coding interviews checkout algomaster.io
English

10 Must-Know Graph Algorithms for Coding Interviews:
1. DFS (Depth-First Search)
2. BFS (Breadth-First Search)
3. Topological Sort
4. Union Find (Disjoint Set)
5. Cycle Detection
6. Connected Components
7. Bipartite Check
8. Flood Fill
9. Minimum Spanning Tree
10. Shortest Path (Dijkstra)
♻️ Repost to help others in your network

English

Basic OOP Concepts Explained with Clear Examples:
1. 𝐄𝐧𝐜𝐚𝐩𝐬𝐮𝐥𝐚𝐭𝐢𝐨𝐧
Hide internal data behind public methods.
- Example: A BankAccount class keeps balance and pin private. The only way to interact with it is through deposit() and getBalance().
2. 𝐀𝐛𝐬𝐭𝐫𝐚𝐜𝐭𝐢𝐨𝐧
Expose a simple interface, hide the complexity behind it.
- Example: An EmailService class gives you sendEmail(to, body). Internally, it handles SMTP connections, authentication, and retry logic. The caller doesn't need to know any of that. They just call one method and it works.
3. 𝐈𝐧𝐡𝐞𝐫𝐢𝐭𝐚𝐧𝐜𝐞
Let child classes reuse and override behavior from a parent class.
- Example: An Animal class defines speak(). Dog extends it and returns "Woof!", Cat extends it and returns "Meow!". Shared logic lives in one place, and each subclass customizes what it needs.
4. 𝐏𝐨𝐥𝐲𝐦𝐨𝐫𝐩𝐡𝐢𝐬𝐦
Write code that works with multiple types through a common interface.
- Example: Define a Shape interface with a draw() method. Now Circle, Rectangle, and Triangle each implement draw() their own way. A single drawShape(Shape s) method works with all of them.
♻️ Repost to help others learn this

English

𝐇𝐨𝐰 𝐭𝐨 𝐅𝐢𝐧𝐝 𝐚 𝐂𝐲𝐜𝐥𝐞 𝐢𝐧 𝐚 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭
Use Floyd’s Cycle Detection Algorithm, also known as the slow and fast pointer technique.
Start two pointers at the head:
- slow moves one step at a time
- fast moves two steps at a time
If the linked list has no cycle, fast will eventually reach the end.
If there is a cycle, fast will eventually catch up with slow inside the loop.
Why does this work?
Think of two runners on a circular track. If one runs faster than the other, they are guaranteed to meet eventually.
Time Complexity: O(n)
Space Complexity: O(1)
English
AlgoMaster.io retweetledi

👉 Checkout the full list of patterns with detailed explanations and problems at algomaster.io
English

20 must-know DSA patterns for coding interviews:
1. Prefix Sum
2. Two Pointers
3. Sliding Window
4. Fast & Slow Pointers
5. LinkedList In-place Reversal
6. Frequency Counting
7. Monotonic Stack
8. Bit Manipulation
9. Top ‘K’ Elements
10. Overlapping Intervals
11. Binary Search Variants
12. Binary Tree Traversal
13. Depth-First Search (DFS)
14. Breadth-First Search (BFS)
15. Shortest Path
16. Matrix Traversal
17. Backtracking
18. Prefix Search (Trie)
19. Greedy
20. Dynamic Programming Patterns
♻️ Repost to help others master coding interviews

English

7 Must-Know Big-O Complexities for Coding Interviews:
1. 𝐎(1) - 𝐂𝐨𝐧𝐬𝐭𝐚𝐧𝐭 𝐭𝐢𝐦𝐞
- The runtime doesn't change regardless of the input size.
- Example: Accessing an element in an array by its index.
2. 𝐎(𝐥𝐨𝐠 𝐧) - 𝐋𝐨𝐠𝐚𝐫𝐢𝐭𝐡𝐦𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows slowly as the input size increases. Typically seen in algorithms that divide the problem in half with each step.
- Example: Binary search in a sorted array.
3. 𝐎(𝐧) - 𝐋𝐢𝐧𝐞𝐚𝐫 𝐭𝐢𝐦𝐞
- The runtime grows linearly with the input size.
- Example: Finding an element in an array by iterating through each element.
4. 𝐎(𝐧 𝐥𝐨𝐠 𝐧) - 𝐋𝐢𝐧𝐞𝐚𝐫𝐢𝐭𝐡𝐦𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows slightly faster than linear time. It involves a logarithmic number of operations for each element in the input.
- Example: Sorting an array using quick sort or merge sort.
5. 𝐎(𝐧^2) - 𝐐𝐮𝐚𝐝𝐫𝐚𝐭𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows proportionally to the square of the input size.
- Example: Bubble sort algorithm which compares and potentially swaps every pair of elements.
6. 𝐎(2^𝐧) - 𝐄𝐱𝐩𝐨𝐧𝐞𝐧𝐭𝐢𝐚𝐥 𝐭𝐢𝐦𝐞
- The runtime doubles with each addition to the input. These algorithms become impractical for larger input sizes.
- Example: Generating all subsets of a set.
7. 𝐎(𝐧!) - 𝐅𝐚𝐜𝐭𝐨𝐫𝐢𝐚𝐥 𝐭𝐢𝐦𝐞
- Runtime is proportional to the factorial of the input size.
- Example: Generating all permutations of a set.
♻️ Repost to help others learn this

English

𝐇𝐨𝐰 𝐌𝐞𝐫𝐠𝐞 𝐒𝐨𝐫𝐭 𝐖𝐨𝐫𝐤𝐬
Merge Sort is a classic Divide & Conquer algorithm.
Here’s the idea:
- Divide → Split the array into two halves
- Conquer → Recursively sort both halves
- Combine → Merge the sorted halves into one sorted array
The magic lies in the merge step, where two sorted arrays are combined efficiently in linear time.
Time Complexity: O(n log n) (always)
Quick example:
[5, 2, 4, 1] → [5, 2] + [4, 1] → [2, 5] + [1, 4] → [1, 2, 4, 5]
♻️ Repost to help others in your network
English

👉 For more coding interview patterns checkout algomaster.io
English

If you want to master dynamic programming for coding interviews, learn these 20 patterns:
1. Fibonacci Numbers
2. 0/1 Knapsack
3. Unbounded Knapsack
4. Longest Common Subsequence
5. Longest Increasing Subsequence
6. Palindromic Subsequence
7. Matrix Chain
8. Edit Distance
9. Coin Change
10. Kadane's Algorithm
11. Grid Paths
12. Subset Sum
13. Rod Cutting
14. Climbing Stairs
15. House Robber
16. Interval DP
17. State Machine DP
18. Tree DP
19. Bitmask DP
20. Digit DP
♻️ Repost to help others in your network

English



