Skip to content

stevesajustephen/Mastering-DSA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frequency Counter Pattern

Often, using a frequency counter will help to avoid using a nested loop, thus reducing the time complexity of our algorithm. Frequency counters can easily take an operation that would be O(N²) down to a much more palatable O(N). The reason that it can be applied to problems that arrays and strings specifically is because strings are considered array-like objects in JavaScript, therefore you can both access and perform operations on an index of a string with the exact same syntax you could use on an array.

The Multiple Pointer Pattern

A problem-solving technique where we use two or more pointers (indexes or references) to navigate through a data structure (like an array) simultaneously. These pointers move towards each other or in different directions based on certain conditions, helping us solve problems more efficiently.

Here are the key aspects of the Multiple Pointer Technique:

Two or More Pointers: In this technique, you use two or more pointers that traverse the data structure, often an array or string. Pointer Movement: The pointers can move in different directions (left to right, right to left, or both), and their movement is based on the problem’s requirements. Efficiency: The goal is to optimize the solution by reducing the time complexity, often avoiding nested loops or unnecessary iterations. Common Use Cases: Multiple pointers are frequently employed to solve problems involving searching, sorting, or determining the presence of a specific pattern within the data structure.