coding_patterns_brief Flashcards

1
Q

Sliding Window

A

Handle input data in a specific window size

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

Islands (Matrix Traversal) /Matrices

A

Matrix Traversing (2D Array)

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

Two Pointers

A

iterate input data , pointers move in opposite direction

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

Fast & Slow Pointers

A

Two Pointers to traverse the input data at different speeds

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

Merge Intervals

A

Overlaping Intervals

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

Cyclic Sort

A

Solve array problems where the input datra lies within a fixed range

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

In-place Reversal of a LinkedList

A

reverse a linkedlist without using extra memory

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

Tree Breadth-First Search

A

traverse a tree, each level fully

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

Tree Depth First Search

A

traverse a tree, going down child nodes until the end and then go back up

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

Two Heaps

A

In many problems, we are given a set of elements that can be divided into two parts. We are interested in knowing the smallest element in one part and the biggest element in the other part. Uses a Min-Heap to find the smallest element and a Max Heap to find the biggest element

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

Subsets

A

Permutations or Combinations of a set elements

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

Modified Binary Search

A

Search a sorted set of elements efficiently

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

Bitwise XOR / Bitwise Manipulation

A

Bit manipulations

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

Top ‘K’ Elements

A

Find the top/smallest/frequent ‘K’ elements in a set

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

K-way Merge

A

Solve problems that involve a list of sorted array

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

Topological Sort

A

Find a linear ordering of elements that have dependencies on each other

17
Q

0/1 Knapsack

A

Used to solve optimization problems. Use this technique to select elements that give maximum profit from a given set with limitation on capacity and that each element can only be picked once

18
Q

Fibonacci Numbers

A

Solve problems that follow the fibonacci numbers

19
Q

Palindromic Subsequence

A

This techniew is used to solve optimization problems related to palindromic sequences or strings

20
Q

Longest Common Substring

A

Use this technique to find the optimal part of a string/sequence or set of strings/sequences

21
Q

Stacks

A

Use this technique if you want to get elements out in the reverse order in which you inserted them (LIFO)

22
Q

Hash Maps

A

Use this when repeated fast access to data during the exection of algorithm. If you need to store the releationship between two sets of data in order to compute the required result. This is achieved through the mechanism of a key-value pair, where we stored the hashed version of the key to enable fast look-ups.

23
Q

Knowing What To Track

A

problem seems hard with a naive approach of at least
O(n2) time complexity, if not worse. Yet, on careful inspection, we realize that there are certain key characteristics of the input data that, if tracked, allow us to solve the problem far more efficiently

Generally speaking, this approach is worth trying when we are required to choose from a fixed set of possibilities: Yes / No, True / False, Valid / Invalid, Player 1 / Player 2.

Key characteristics could include the frequency of characters in a string, the pattern of generation of a sequence of permutations, or the implications of a given move in a game like tic-tac-toe or chess.

24
Q

Greedy Techniques

A

if selecting a series of local optima allows us to construct or identify the globally optimum solution.

25
Q

Graphs

A

There is a network of interconnected objects with some relationship between them; that is, the data can be represented as a graph.

26
Q

Custom Data Structures

A

The problem requires customizing an existing data structure, that is, adding a feature to it or modifying an existing feature. Examples include min stack and maximum frequency stack.

The problem requires combining one or more data structures to solve the problem efficiently. An example would be implementing an LRU cache.

27
Q

Backtracking

A

While constructing any single candidate solution, all paths must be explored. This means that if exploring a certain path results in a dead end, we need to move back one level and explore all the other paths in the solution space.
Example: Determine whether an undirected graph can be colored using no more than
n colors in such a way that no two adjacent vertices share the same color.

The problem requires us to consider all feasible solutions in order to select the best one. While solving such a problem, not a single feasible solution may be ignored. In certain problems, even if some feasible solutions are eventually discarded, we still need to find and evaluate them.
Example: Select elements from an array of strings and concatenate them, such that the concatenated string is of the maximum possible length and contains unique characters.

The problem requires us to compile a list of all feasible solutions.
Example: Partition a given string into substrings so that each substring is a palindrome. We need to determine all possible ways in which the partitioning can be done to obtain palindromic substrings.

28
Q

Trie

A

We need to compare two strings to detect partial matches, based on the initial characters of one or both strings.

We wish to optimize the space used to store a dictionary of words. Storing shared prefixes once allows for significant savings

29
Q

Dynamic Programming

A

Overlapping subproblems, that is, we can use the results of one subproblem when solving another, possibly larger subproblem.

Optimal substructure, that is, if the final solution can be constructed from the optimal solutions to its subproblems.

30
Q

Union Find

A

The problem requires arranging elements with a certain property into groups, or, to use graph terminology, into connected components.

We have been given a problem that contains elements represented as separate sets initially where we have to combine pairs of sets or find whether two elements belong to the same set or not.

The problem data is best organized in the form of a graph, yet the data has not been provided in the form of an adjacency list/matrix.