Section 1

Preview this deck

Combinations

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

5 years ago

Date created

Mar 14, 2020

Cards (95)

Section 1

(50 cards)

Combinations

Front

Repetition is Allowed: such as coins in your pocket (5,5,5,10,10) No Repetition: such as lottery numbers (2,14,15,27,30,33) https://www.mathsisfun.com/combinatorics/combinations-permutations.html

Back

Advantages/Disadvantages of Common Sorting Algorithms

Front

Back

Internal Sorting

Front

An internal sort is any data sorting process that takes place entirely within the main memory of a computer. This is possible whenever the data to be sorted is small enough to all be held in the main memory. For sorting larger datasets, it may be necessary to hold only a chunk of data in memory at a time, since it won't all fit. The rest of the data is normally held on some larger, but slower medium, like a hard-disk. Any reading or writing of data to and from this slower media can slow the sortation process considerably.

Back

Bipartite Graph

Front

Graph can be colored without conflicts while using only two colors.

Back

Heuristics

Front

Any approach to problem solving, learning, or discovery that employs a practical method not guaranteed to be optimal or perfect, but sufficient for the immediate goals. Where finding an optimal solution is impossible or impractical, heuristic methods can be used to speed up the process of finding a satisfactory solution. Heuristics can be mental shortcuts that ease the cognitive load of making a decision. Examples of this method include using a rule of thumb, an educated guess, an intuitive judgment, stereotyping, profiling, or common sense

Back

Recurrence Relation

Front

An equation that is defined in terms of itself. Any polynomial or exponential can be represented by a recurrence.

Back

Divide-and-Conquer Recurrances

Front

T(n) = aT(n/b) + f(n)

Back

Vertex-coloring

Front

Seeks to assign a label (or color) to each vertex of a graph such that no edge links any two vertices of the same color.

Back

Big Oh Notation

Front

Back

Compute XOR of every bit in an integer

Front

Similar to addition, XOR is associative and communicative, so, we need to XOR every bit together. First, XOR the top half with the bottom half. Then, XOR the top quarter of the bottom half with the bottom quarter of the bottom half... x ^= x >> 32 x ^= x >> 16 x ^= x >> 8 x ^= x >> 4 x ^= x >> 2 x ^= x >> 1 x = x & 1

Back

Pre-Order Traversal

Front

1. Process self. 2. Process left child. 3. Process right child.

Back

Bit Array

Front

A bit array is a mapping from some domain (almost always a range of integers) to values in the set {0, 1}. The values can be interpreted as dark/light, absent/present, locked/unlocked, valid/invalid, et cetera. The point is that there are only two possible values, so they can be stored in one bit. As with other arrays, the access to a single bit can be managed by applying an index to the array. Assuming its size (or length) to be n bits, the array can be used to specify a subset of the domain (e.g. {0, 1, 2, ..., n−1}), where a 1-bit indicates the presence and a 0-bit the absence of a number in the set. This set data structure uses about n/w words of space, where w is the number of bits in each machine word. Whether the least significant bit (of the word) or the most significant bit indicates the smallest-index number is largely irrelevant, but the former tends to be preferred (on little-endian machines).

Back

Case Analysis

Front

Analysis pattern. Split the input/execution into a number of cases and solve each case in isolation

Back

Counting Sort

Front

An algorithm for sorting a collection of objects according to keys that are small integers; that is, it is an integer sorting algorithm. It operates by counting the number of objects that have each distinct key value, and using arithmetic on those counts to determine the positions of each key value in the output sequence. Its running time is linear in the number of items and the difference between the maximum and minimum key values, so it is only suitable for direct use in situations where the variation in keys is not significantly greater than the number of items. However, it is often used as a subroutine in another sorting algorithm, radix sort, that can handle larger keys more efficiently.[1][2][3] Because counting sort uses key values as indexes into an array, it is not a comparison sort, and the Ω(n log n) lower bound for comparison sorting does not apply to it.

Back

Connected Component

Front

In an undirected graph, a connected component is a maximal set of vertices such that there is a path between every pair of vertices (the example shows 3 connected components).

Back

Recursion

Front

Algorithm design patterns. If the structure of the input is defined in a recursive manner, design a recursive algorithm that follows the input definition.

Back

One-Sided Binary Search

Front

In the absence of an upper bound, we can repeatedly test larger intervals (A[1], A[2], A[4], A[8], A[16], etc) until we find an upper bound, the transition point, p, in at most 2[log p] comparisons. One sided binary search is most useful whenever we are looking for a key that lies close to our current position.

Back

Compute x modulo a power of 2 (y)

Front

x & (y - 1)

Back

In-Order Traversal

Front

1. Process left child. 2. Process self. 3. Process right child.

Back

External Sorting

Front

External sorting is a term for a class of sorting algorithms that can handle massive amounts of data. External sorting is required when the data being sorted do not fit into the main memory of a computing device (usually RAM) and instead they must reside in the slower external memory (usually a hard drive). External sorting typically uses a hybrid sort-merge strategy. In the sorting phase, chunks of data small enough to fit in main memory are read, sorted, and written out to a temporary file. In the merge phase, the sorted subfiles are combined into a single larger file. Mergesort is typically preferred.

Back

Geometric series

Front

.

Back

Standard data structure for solving complex bit manipulation

Front

Lookup table

Back

Greedy Algorithms

Front

Algorithm design patterns. Compute a solution in stages, making choices that are local optimum at step; these choices are never undone.

Back

Solving Divide-and-Conquer Recurrances

Front

Case 1: Too many leaves. Case 2: Equal work per level. Case 3: Too expensive a root

Back

Isolate the lowest bit that is 1 in x

Front

x & ~(x - 1)

Back

Permutations

Front

A permutation is an ordered combination. Repetition is Allowed: such as the lock above. It could be "333". No Repetition: for example the first three people in a running race. You can't be first and second. https://www.mathsisfun.com/combinatorics/combinations-permutations.html

Back

Stable Sorting Algorithm

Front

Items with the same key are sorted based on their relative position in the original permutation

Back

Sorting

Front

Algorithm design patterns. Uncover some structure by sorting the input.

Back

Selection Sort

Front

An in-place comparison sort algorithm, O(n^2). The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right

Back

memoization

Front

An optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.

Back

Articulation Vertex

Front

The weakest point in a graph

Back

Hamming Weight

Front

The Hamming weight of a string is the number of symbols that are different from the zero-symbol of the alphabet used (also called the population count, popcount or sideways sum). Algorithm: - Count the number of pairs, then quads, then octs, etc, adding and shifting. v = v - ((v>>1) & 0x55555555); v = (v & 0x33333333) + ((v>>2) & 0x33333333); int count = ((v + (v>>4) & 0xF0F0F0F) * 0x1010101) >> 24;

Back

Depth-First Search

Front

Explore newest unexplored vertices first. Placed discovered vertices in a stack (or used recursion). Partitions edges into two classes: tree edges and back edges. Tree edges discover new vertices; back edges are ancestors.

Back

Replace the lowest bit that is 1 with 0

Front

x & (x - 1)

Back

Divide-and-conquer

Front

Algorithm design patterns. Divide the problem into two or more smaller independent subproblems and solve the original problem using solutions to the subproblems.

Back

Post-Order Traversal

Front

1. Process left child. 2. Process right child. 3. Process self.

Back

Trie

Front

In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. Values are not necessarily associated with every node. Rather, values tend only to be associated with leaves, and with some inner nodes that correspond to keys of interest. For the space-optimized presentation of prefix tree, see compact prefix tree.

Back

Breadth-First Search

Front

Explores the oldest unexplored vertices first. Places discovered vertices in a queue. In an undirected graph: Assigns a direction to each edge, from the discoverer to the discovered, and the discoverer is denoted to be the parent.

Back

Typical runtime of a recursive function with multiple branches

Front

O( branches^depth )

Back

Reduction

Front

Analysis pattern. Use a well-known solution to some other problem as a subroutine.

Back

Arithmetic progressions

Front

For p < -1, this sum always converges to a constant.

Back

Iterative Refinement

Front

Analysis pattern. Most problems can be solved using s brute-force approach. Find such a solution and improve upon it.

Back

Topological Sort

Front

A linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering.

Back

Right propagate the rightmost set bit in x

Front

x | (x & ~(x - 1) - 1)

Back

Concrete Examples

Front

Analysis pattern. Manually solve concrete instances of the problem and then build a general solution

Back

Dominance pecking order

Front

Back

Heapify (bubble down)

Front

Swap a node with one of its children, calling bubble_down on the node again until it dominates its children. Each time, place a node that dominates the others as the parent node.

Back

Graph Modeling

Front

Analysis pattern. Describe the problem using a graph and solve it using an existing algorithm.

Back

Adjacency Matrix vs Adjacency List

Front

Back

Invariants

Front

Algorithm design patterns. Identify an invariant and use it to rule out potential solutions that are suboptimal/dominated by other solutions.

Back

Section 2

(45 cards)

Strongly Connected Graphs

Front

There lies a path between any two vertices on a directed graph.

Back

Double Checked Locking

Front

Double-checked locking is a software design pattern used to reduce the overhead of acquiring a lock by first testing the locking criterion (the "lock hint") without actually acquiring the lock. Only if the locking criterion check indicates that locking is required does the actual locking logic proceed. (Often used in Singletons, and has issues in C++).

Back

Type erasure

Front

Type erasure is any technique in which a single type can be used to represent a wide variety of types that share a common interface. In the C++ lands, the term type-erasure is strongly associated with the particular technique that uses templates in the interface and dynamic polymorphism in the implementation. 1. A union is the simplest form of type erasure. - It is bounded, and all participating types have to be mentioned at the point of declaration. 2. A void pointer is a low-level form of type erasure. Functionality is provided by pointers to functions that operate on void* after casting it back to the appropriate type. - It is unbounded, but type unsafe. 3. Virtual functions offer a type safe form of type erasure. The underlying void and function pointers are generated by the compiler. - It is unbounded, but intrusive. - Has reference semantics. 4. A template based form of type erasure provides a natural C++ interface. The implementation is built on top of dynamic polymorphism. - It is unbounded and unintrusive. - Has value semantics.

Back

Dijkstra's Algorithm

Front

An algorithm for finding the shortest paths between nodes in a weighted graph. For a given source node in the graph, the algorithm finds the shortest path between that node and every other. It can also be used for finding the shortest paths from a single node to a single destination node by stopping the algorithm once the shortest path to the destination node has been determined. Its time complexity is O(E + VlogV), where E is the number of edges and V is the number of vertices.

Back

Palindrome

Front

String that reads the same forwards as backwards

Back

Prim's Algorithm

Front

(Minimum Spanning Trees, O(m + nlogn), where m is number of edges and n is the number of vertices) Starting from a vertex, grow the rest of the tree one edge at a time until all vertices are included. Greedily select the best local option from all available choices without regard to the global structure.

Back

Set Partition

Front

A partitioning of elements of some universal set into a collection of disjointed subsets. Thus, each element must be in exactly one subset.

Back

Inverted Index

Front

An index data structure storing a mapping from content, such as words or numbers, to its locations in a database file, or in a document or a set of documents (named in contrast to a Forward Index, which maps from documents to content). The purpose of an inverted index is to allow fast full text searches, at a cost of increased processing when a document is added to the database.

Back

Sharding

Front

Sharding is a type of database partitioning that separates very large databases the into smaller, faster, more easily managed parts called data shards.

Back

Balanced Binary Tree

Front

For each node in the tree, the difference in the height of its left and right subtrees is at most one.

Back

Viterbi Algorithms

Front

A dynamic programming algorithm for finding the most likely sequence of hidden states - called the Viterbi path - that results in a sequence of observed events. The Viterbi algorithm provides an efficient way of finding the most likely sequence of characters in a maximum a posteriori (MAP) probability sense.

Back

Directed Graph Finding Cycles

Front

Check if node is a back edge in DFS by being both discovered and not processed

Back

Degree of a Vertex

Front

The number of edges incident of the vertex, with loops counted twice

Back

Rabin-Karp

Front

Compute hash codes of each substring whose length is the length of s, such as a function with the property that the hash code of a string is an additive function of each individual character. Get the hash code of a sliding window of characters and compare if the hash matches.

Back

Full Binary Tree

Front

A full binary tree (sometimes referred to as a proper or plane binary tree) is a tree in which every node in the tree has either 0 or 2 children.

Back

Rolling hash function

Front

A rolling hash (also known as a rolling checksum) is a hash function where the input is hashed in a window that moves through the input. A few hash functions allow a rolling hash to be computed very quickly—the new hash value is rapidly calculated given only the old hash value, the old value removed from the window, and the new value added to the window—similar to the way a moving average function can be computed much more quickly than other low-pass filters. One of the main applications is the Rabin-Karp string search algorithm, which uses the rolling hash described below.

Back

Preemption

Front

Preemption is the act of temporarily interrupting a task being carried out by a computer system, without requiring its cooperation, and with the intention of resuming the task at a later time. Such a change is known as a context switch.

Back

Chromatic Number

Front

The smallest number of colors needed for an edge coloring of a graph

Back

Bipartite Matching

Front

Pair off vertices such that each vertex is in one pair (boys and girls are paired as potential marriage partners)

Back

Radix Sort

Front

Non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value. Two classifications of radix sorts are least significant digit (LSD) radix sorts and most significant digit (MSD) radix sorts.

Back

Maximum Spanning Tree

Front

A spanning tree of a weighted graph having maximum weight. It can be computed by negating the edges and running either Prim's or Kruskal's algorithms.

Back

Floyd-Warshall Algorithm

Front

An algorithm for finding shortest paths in a weighted graph with positive or negative edge weights (but with no negative cycles). A single execution of the algorithm will find the lengths (summed weights) of the shortest paths between all pairs of vertices, though it does not return details of the paths themselves.

Back

Replica

Front

Replication in computing involves sharing information so as to ensure consistency between redundant resources, such as software or hardware components, to improve reliability, fault-tolerance, or accessibility.

Back

Undirected Graph Finding Cycles

Front

Check if the parent of y != x

Back

Hidden Markov Model

Front

A statistical Markov model in which the system being modeled is assumed to be a Markov process with unobserved, hidden states. In its discrete form, a hidden Markov process can be visualized as a generalization of the Urn problem with replacement (where each item from the urn is returned to the original urn before the next step).

Back

Anagram

Front

a word, phrase, or name formed by rearranging the letters of another, such as cinema, formed from iceman.

Back

Search Pruning

Front

The technique of cutting off the search the instant we have established that a partial solution cannot be extended into a full solution.

Back

Quick Select

Front

A selection algorithm to find the kth smallest element in an unordered list. Quickselect uses the same overall approach as quicksort, choosing one element as a pivot and partitioning the data in two based on the pivot, accordingly as less than or greater than the pivot. However, instead of recursing into both sides, as in quicksort, quickselect only recurses into one side - the side with the element it is searching for. This reduces the average complexity from O(n log n) to O(n). Partition algorithm:

Back

Fibonacci Heap

Front

A data structure that is a collection of trees satisfying the minimum-heap property, that is, the key of a child is always greater than or equal to the key of the parent. This implies that the minimum key is always at the root of one of the trees. The trees do not have a prescribed shape and in the extreme case the heap can have every element in a separate tree. This flexibility allows some operations to be executed in a "lazy" manner, postponing the work for later operations. For example, merging heaps is done simply by concatenating the two lists of trees, and operation decrease key sometimes cuts a node from its parent and forms a new tree. For the Fibonacci heap, the find-minimum operation takes constant (O(1)) amortized time. The insert and decrease key operations also work in constant amortized time. Deleting an element (most often used in the special case of deleting the minimum element) works in O(log n) amortized time, where n is the size of the heap. This means that starting from an empty data structure, any sequence of a insert and decrease key operations and b delete operations would take O(a + b log n) worst case time, where n is the maximum heap size. In a binary or binomial heap such a sequence of operations would take O((a + b) log n) time. A Fibonacci heap is thus better than a binary or binomial heap when b is smaller than a by a non-constant factor. It is also possible to merge two Fibonacci heaps in constant amortized time, improving on the logarithmic merge time of a binomial heap, and improving on binary heaps which cannot handle merges efficiently. Using Fibonacci heaps for priority queues improves the asymptotic running time of important algorithms, such as Dijkstra's algorithm for computing the shortest path between two nodes in a graph, compared to the same algorithm using other slower priority queue data structures.

Back

Mnemonic

Front

A device such as a pattern of letters, ideas, or associations that assists in remembering something

Back

Degenerate Binary Tree

Front

A degenerate (or pathological) tree is where each parent node has only one associated child node.This means that performance-wise, the tree will behave like a linked list data structure.

Back

Perfect Binary Tree

Front

A perfect binary tree is a binary tree in which all interior nodes have two children and all leaves have the same depth or same level.

Back

Rooted Binary Tree

Front

A rooted binary tree has a root node and every node has at most two children.

Back

Union-Find

Front

(Disjoint-set data structure) keeps track of a set of elements partitioned into a number of disjoint (nonoverlapping) subsets. It supports two useful operations: find and union. Find: Determine which subset a particular element is in. Find typically returns an item from this set that serves as its "representative"; by comparing the result of two Find operations, one can determine whether two elements are in the same subset. Union: Join two subsets into a single subset. In order to define these operations more precisely, some way of representing the sets is needed. One common approach is to select a fixed element of each set, called its representative, to represent the set as a whole. Then, Find(x) returns the representative of the set that x belongs to, and Union takes two set representatives as its arguments.

Back

Combinations of binary tree traversal sequences that do not uniquely identify a tree

Front

1. Postorder and preorder. 2. Preorder and level-order. 3. Postorder and level-order.

Back

Kruskal's Algorithm

Front

(Minimum Spanning Trees, O(mlogm) with a union find, which is fast for sparse graphs) Builds up connected components of vertices, repeatedly considering the lightest remaining edge and tests whether its two endpoints lie within the same connected component. If not, insert the edge and merge the two components into one.

Back

Combinations of binary tree traversal sequences that uniquely identify a tree

Front

1. Inorder and preorder. 2. Inorder and postorder. 3. inorder and level-order.

Back

Minimum Spanning Trees

Front

The smallest connected graph in terms of edge weight, minimizing the total length over all possible spanning trees. However, than can be more than one minimum spanning tree in a graph. All spanning trees of an unweighted graph are minimum spanning trees.

Back

Backtracking

Front

A systematic way to iterate through all possible configurations of a search space

Back

Constructing a heap in linear time

Front

1. Place the data into the heap's data set blindly. It will have the correct shape, but the dominance order will be incorrect. 2. Starting from the last (nth) position, walk backwards through the array until we encounter an internal node with children. 3. Perform bubble down n times. Explanation: heapify() takes time proportional to the height of the heaps it is merging. Most of these heaps are extremely small. In a full binary tree on n nodes, there are n/2 nodes that are leaves, n/4 nodes that are height 1, n/8 nodes that are height 2, and so on. In general, there are at most n/(2^(h+1) nodes of hieght h, so the cost of building the heap is <= 2n (see picture).

Back

Transitive Closure

Front

Can one get from node a to node d in one or more hops? A binary relation tells you only that node a is connected to node b, and that node b is connected to node c, etc. After the transitive closure is constructed one may determine that node d is reachable from node a. (use Floyd-Warshall Algorithm)

Back

Complete Binary Tree

Front

In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.

Back

Sparse Graph

Front

A graph in which the number of edges is close to the minimal number of edges. Sparse graphs can be a disconnected

Back

Minimum Product Spanning Tree

Front

The cost of a tree is the product of all the edge weights in the tree, instead of the sum of the weights. Since log(a*b) = log(a) + log(b), the minimum spanning tree on a graph whose edge weights are replaced with their logarithms gives the minimum product spanning tree on the original graph.

Back

Euclidean Algorithm GCD

Front

def gcd(a, b): while a: b, a = a, b%a return b

Back