Patterns Full Description Flashcards

1
Q

the sliding window pattern is used to process sequential data by maintaining a moving subset of elements, called a window. The pattern is aimed at reducing the use of nested loops in an algorithm. It may be viewed as a variation of the two pointers pattern, with the pointers being used to set the window bounds.

A

Sliding Window

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Most of the problems requiring matrixes can be solved using the following operations: Matrix transformations:

A few transformations are scaling, translation, rotation, and reflection.
Matrix traversals: A few matrix traversals are simple, spiral, and diagonal traversals, as illustrated below.

A

Islands (Matrix Traversal) /Matrices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

the two pointers pattern uses two pointers to iterate over an array or list until the conditions of the problem are satisfied. This is useful because it allows us to keep track of the values of two different indexes in a single iteration. Whenever there’s a requirement to find two data elements in an array that satisfy a certain condition, the two pointers pattern should be the first strategy to come to mind.

A

Two Pointers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

“pattern uses two pointers to traverse an iterable data structure at different speeds. It’s usually used to identify distinguishable features of directional data structures, such as a linked list or an array.

Detect Cycles”

A

Fast & Slow Pointers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

“the __ pattern deals with problems involving overlapping intervals. Each interval is represented by a start and an end time. For example, an interval of [10,20]
seconds means that the interval starts at 10 seconds and ends at 20
seconds, such that both 10 and time 20 are included in the interval.

The most common problems solved using this pattern are scheduling problems.”

A

Merge Intervals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

___ is an in-place, unstable, comparison sort algorithm. Its Is based on the insights that subsequences of numbers in the input array that are not in sorted order acutally describes cycles, and the process of placing each number in its correct position removes these cycles

A

Cyclic Sort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The ____ of a linked list pattern allows us to reverse a linked list without any additional memory, using only the given nodes.

A

In-place Reversal of a LinkedList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“____ is a method to reduce the use of nested loops in our tree-related problems. ___ search in a ___ is usually implemented recursively. However, it can also be implemented iteratively with the help of a stack. The fundamental characteristic of this pattern is that it travels as far as possible along each tree branch before exploring the others.

There are three main methods to solving a problem with the depth-first search pattern—Preorder, Inorder, and Postorder.

Preorder - root, left, right
In order- left, root, right
Postorder - left, right, root

Therefore, we would prefer __ if the destination node were close to a leaf. Meanwhile, we would favor ___ if our goal is to search for a node that is more likely to be closer to the root itself.”

A

Tree Depth First Search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

___ search is an important tree traversal algorithm for finding a node in a tree that satisfies the given constraints. It starts searching at the root node and moves down level by level, exploring adjacent nodes at level k+1 Essentially, it first visits nodes that are one edge away from the root, followed by nodes that are two edges away, and so on. This helps in efficiently finding neighbor nodes, particularly peer-to-peer networking systems.

A

Tree Breadth-First Search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

As the name suggests, the____ pattern uses either two min-heaps, two max-heaps, or a min-heap and a max-heap simultaneously to solve the problem.

A

Two Heaps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

“The__ pattern is useful in finding the permutations and combinations of elements in a data structure. The input data structure might be a set containing unique elements. It can also be an array, or a list, which may contain duplicate elements. We then make a series of subsets from the elements in this data structure. The specific subsets generated are based on the conditions that the problem provides us.

We use a programming technique, defined below, known as backtracking to generate the required subsets of a given data structure of elements. The method is to build the subsets incrementally, including or excluding each element of the original data structure, depending on the constraints of the problem. This process is continued recursively for the remaining elements until all desired subsets have been generated.”

A

Subsets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

“The ___ pattern builds upon the basic binary search algorithm discussed above. It involves adapting the traditional binary search approach by applying certain conditions or transformations, allowing us to solve more complex problems.

A few common variations of the modified binary search pattern are:

__ on a modified array: Sometimes, the array may be modified in a certain way, which affects the search process. For example, the array might be sorted and then rotated around some unknown pivot. Alternatively, some elements in a sorted array might be modified based on a specific condition. To handle such scenarios, we can modify the basic binary search technique to detect anomalies in the sorted order.

__ with multiple conditions: When searching for a target satisfying multiple conditions, a modified binary search can be used. It involves adapting the comparison logic within the binary search to accommodate multiple conditions. Examples include finding a target range rather than a single target, or finding the leftmost, or the rightmost occurrence of a target value.”

A

Modified Binary Search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

___ is the process of modifying bits algorithmically using bitwise operations. Logical bitwise operations are the fastest computations, because processors natively support them. This approach generally leads to efficient solutions in problems where we can efficiently transform the input into its binary form or manipulate it directly at the bit level to produce the required output.

A

Bitwise XOR / Bitwise Manipulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

“The __ pattern helps find some specific k number of elements from the given data with optimum time complexity.

Many problems ask us to find the top, the smallest, or the most/least frequent k
elements in an unsorted list of elements. To solve such problems, sorting the list takes O(nlog(n))
time, then finding the k elements takes O(k) time. However, the top k elements pattern can allow us to solve the problem using O(n.logk) time without sorting the list first.”

A

Top ‘K’ Elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

“The __ pattern is a common algorithmic technique used to merge K sorted data structures, such as arrays and linked lists, into a single data structure that maintains the sorted order. It’s an extension of the standard merge sort algorithm, which merges two sorted data structures into one.

The basic idea behind the __ algorithm is to repeatedly select the smallest (or largest, depending on the sorting order) element among the K input lists and add it to the output list (with the same data type as the inputs). This process continues until all elements from all input lists have been added to the output list.”

A

K-way Merge

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The __ pattern is used to find valid orderings of elements that have dependencies on, or priority over each other. Scheduling and grouping problems that have prerequisites or dependencies generally fall under this pattern.

A

Topological Sort

17
Q

__ in programming are used to store elements that are sequentially dependent on each other.

A

Stacks

18
Q

Reduce Time it takes to find and access values. Key -value pairs

A

Hash Maps

19
Q

“The___ pattern is mostly used to find the frequency count of the data. It’s able to avoid the O(n2) time by simplifying the problem and identifying certain key numeric properties in the given data.

This pattern is often used with an array and strings, and helps solve problems that require counting data frequencies or returning boolean values (TRUE/FALSE). More often than not, the problems that can be solved using this pattern include comparison and checks, such as the examples given below:

Check if the values of the first array have corresponding squared values in the second array
Check if two strings are anagrams
Check if the player wins the game”

A

Knowing What To Track

20
Q

“A ___ algorithm, as the name implies, always makes the choice that seems to be the best at the time. It makes a locally-optimal choice in the hope that it will lead to a globally optimal solution. In other words, greedy algorithms are used to solve optimization problems.

___ algorithms work by recursively constructing a solution from the smallest possible constituent parts. A recursion is an approach to problem-solving in which the solution to a particular problem depends on solutions to smaller or equal instances of the same problem. “

A

Greedy Techniques

21
Q

A __ is a nonlinear data structure that consists of vertices, V, and edges, E. Vertices, also called nodes, can represent any data, and edges are the lines that connect two vertices in the graph. A __ can be represented as G(V,E), where V represents vertices, and E represents edges. An edge connecting u and v, such that u,v∈V, is represented by a pair of vertices denoted as (u,v).

A

Graphs

22
Q

Using __ makes it easier and more efficient to solve problems that would otherwise be difficult with the existing data structures.

A

Custom Data Structures

23
Q

__ is a technique that explores multiple paths to find the solution. It builds the solution step by step by increasing values with time and removes the choices that don’t contribute to the problem’s solution based on some constraints. __ is different from recursion because, in recursion, the function calls itself until it reaches a base case whereas __ tries to explore all possible paths to a solution.

A

Backtracking

24
Q

__ is a tree data structure used for storing and locating keys from a set. The keys are usually strings that are stored character by character—each node of a __ corresponds to a single character rather than the entire key. This can be used for grammer checking etc.

A

Trie

25
Q

” We can use the __ pattern to save the result once and use it wherever the subproblem is repeated.

We’ve discussed that we need to save the computations, but how can we save and use them? There are two approaches in __ that we can use to solve the problems:

Top-down approach with memoization - store results in a array or hash map
Bottom-up approach with tabulation - allows us to not use recursion as we used it in the top-down approach, it uses n-dimensional array to store the results of solved subproblems during the iteration of the array “

A

Dynamic Programming

26
Q

“The __ is used to group elements into sets based on a specified property. Each set is non-overlapping, that is, it contains unique elements that are not present in any other set. The pattern uses a disjoint set data structure such as an array, to keep track of which set each element belongs to.

Each set forms a tree data structure and has a representative element that resides at the root of the tree. Every element in this tree maintains a pointer to its parent. The representative’s parent pointer points to itself. If we pick any element in a set and follow its parent pointers, we’ll always reach the set representative.

The pattern is composed of two operations performed on the disjoint data structure:

find(x): Finds the representative of the set that contains x.

union(x, y): Merges the sets of x and y into one.”

A

Union Find