Skip to content

sheetal-ahuja/concepts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

Algorithmic Patterns

1. Two Pointers

  • A technique to solve problems is having two pointers starting at different positions and moving towards a condition.
  • Useful for problems like finding a pair in a sorted array, or reversing a string in place.

2. Island

  • Used for solving matrix traversal problems like counting the number of islands in a grid.
  • Often solved using DFS or BFS.

3. Fast and Slow Pointer

  • Also known as the "Tortoise and Hare" approach.
  • Commonly used to detect cycles in a linked list or to find the middle of the list.

4. Sliding Window

  • Useful for problems involving subarrays of a fixed size or maximum/minimum sum problems.
  • Efficiently solve problems by sliding a window over the data.

5. Merge Intervals

6. Cyclic Sort

  • Sorting an array of numbers when the numbers are in a specific range.
  • Used for problems that involve finding missing or duplicate numbers.

7. In-place Reversal of a Linked List

  • Reversing a linked list using constant space.
  • Interview questions involving linked lists are commonly asked.

8. Tree Breadth-First Search

  • Traversing a tree level by level.
  • Useful for problems involving the shortest path in an unweighted graph.

9. Tree Depth First Search

  • Traversing a tree by going deep along one branch before moving to another.
  • Useful for problems like finding paths, tree diameter, etc.

10. Two Heaps

  • Technique for efficiently keeping track of the median of a stream of numbers.
  • Uses a max heap and a min-heap.

11. Subsets

  • Finding all possible subsets of a given set.
  • Can be solved using backtracking or iterative approaches.

12. Modified Binary Search

  • Binary search with variations to solve non-trivial searching problems.
  • Examples include finding rotation points or closest elements in a sorted array.

13. Top 'K' elements

  • Finding the top K elements in a collection.
  • Can be solved efficiently using heaps or quickselect.

14. Bitwise XOR

  • Bit manipulation technique.
  • Useful for problems like finding missing numbers in an array.

15. Backtracking

  • Try all possible solutions and backtrack once an invalid solution is reached.
  • Commonly used in solving problems like Sudoku, N-Queens, etc.

16. 0/1 Knapsack

  • A dynamic programming problem involving maximizing value without exceeding weight.
  • Uses a table to store intermediate results.

17. Topological Sort

  • Sorting directed graphs with dependencies.
  • Used in problems involving course scheduling or task ordering.

18. K-way Merge

  • Merging K sorted lists into a single sorted list.
  • Uses a min-heap for efficient merging.

19. Monotonic Stack

  • Stack used to maintain elements in a sorted order.
  • Useful for solving problems involving the next greater or smaller element.

20. Multi Thread

  • Concurrently executing multiple threads for parallel computation.
  • Helps in optimizing performance in multi-core systems.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published