Algorithms & Data Structures Cartes | Quizlet

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/99

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

100 Terms

1
New cards

Greedy Algorithm

an algorithm that follows problem solving heuristic of making optimal choices at each stage. Hopefully finds the global optimum. An example would be Kruskal's algorithm.

2
New cards

Divide and Conquer

works by recursively breaking down a problem into two or more sub problems until the problems become simple enough to be solved directly. An example would be mergesort.

3
New cards

Recursive Algorithms

solve a problem by solving smaller internal instances of a problem -- work towards a base case.

4
New cards

Dynamic Programming

Break down a problem into smaller and smaller subproblems. At their lowest levels, the subproblems are solved and their answers stored in memory. These saved answers are used again with other larger (sub)problems which may call for a recomputation of the same information for their own answer. Reusing the stored answers allows for optimization by combining the answers of previously solved subproblems.

5
New cards

Selection Sort

Non-stable, in place sort. Has an N-squared order of growth, needs only one spot of extra space. Works by searching the entire array for the smallest item, then exchanging it with the first item in the array. Repeats this process down the entire array until it is sorted.

6
New cards

Insertion Sort

Stable, in place sort with an order of growth which is between N and N-squared, needs only one spot of extra space and is dependent on the order of the items. Works by scanning over the list, then inserting the current item to the front of the list where it would fit sequentially. All the items to the left of the list will be sorted, but may not be in their final place as the larger items are continuously pushed back to make room for smaller items if necessary.

7
New cards

ShellSort

Non-stable, in place sort with an order of growth which is undetermined, though usually given at being N-to-the 6/5. Needs only one spot of extra space. Works as an extension of insertion sort. It gains speed by allowing exchanges of entries which are far apart, producing partially sorted arrays which are eventually sorted quickly at the end with an insertion sort. The idea is to rearrange the array so that every h-th entry yields a sorted sequence. The array is h-sorted.

8
New cards

Quick Sort

Non-stable, in place sort with an order of growth of NlogN. Needs lgN of extra space. It has a probabilistic guarantee. Works by making use of a divide and conquer method. The array is divided into two parts, and then the parts are sorted independently. An arbitrary value is chosen as the partition. Afterwards, all items which are larger than this value go to the right of it, and all items which are less than this value go to the left of it.

We arbitrarily choose a[lo] as a partitioning item. Then we scan from the left end of the array one by one until we find an entry that is greater than a[lo]. At the same time, we are scanning from a[lo] to the right to find an entry that is less than or equal to a[lo]. Once we find these two values, we swap them.

9
New cards

3-Way Quick Sort

Non-stable, in place sort with an order of growth between N and NlogN. Needs lgN of extra space. Is probabilistic and dependent on the distribution of input keys.

10
New cards

Mergesort

Stable sort which is not in place. It has an order of growth of NlogN and requires N amount of extra space. Works by dividing an array in half continuously into smaller and smaller arrays. At the lowest level, these arrays are sorted and then merged together after sorting in the reverse order they were divided apart in.

11
New cards

Heap Sort

Non-stable, in place sort which has an order of growth of NlogN. Requires only one spot of extra space. Works like an improved version of selection sort. It divides its input into a sorted and unsorted region, and iteratively shrinks the unsorted region by extracting the smallest element and moving it into the sorted region. It will make use of a heap structure instead of a linear time search to find the minimum.

12
New cards

Lower Bound on the complexity of pairwise comparisons

No compare based sorting algorithm can have fewer than ~NlogN compares

13
New cards

Counting Sort (Key Indexed sort)

An integer sorting algorithm which counts the number of objects that have a distinct key value, and then used arithmetic on those countes to determine the positions of each key value in the output array.

It cannot handle large keys efficiently, and is often used as a subroutine for other sorting algorithms such as radix sort.

Has a time complexity of N.

14
New cards

LSD Radix Sort

Stable sort which sorts fixed length strings. Uses an axillary array, and therefore is not in place. Goes through to the last character of a string (its least significant digit), and takes its value. All strings given are then organized based on the value of their least significant digit.

Following this, the algorithm proceeds to the next least significant digit, repeating the process until it has gone through the length of the strings.

Best used for sorting things with fixed string lengths, like Social Security numbers or License Plates.

Has a time complexity of O(n*k) where n is the number of keys and k is the average length of those keys.

15
New cards

MSD Radix Sort

Used to sort an array of strings based on their first character. Is done recursively and can sort strings which are of different lengths. This algorithm will be slower than its counterpart if used for sets of strings which all have the same length.

Has a time complexity of 2W(N+R).

16
New cards

Unordered Linked List

Data structure with non-efficently supported operations. Is unordered. Has a worst case cost of search and insertion at N, an average case cost of insertion at N, and an average case cost of searching at N/2.

17
New cards

Binary Search

An ordered array of data which has efficiently supported operations. The worst and average case of a search using this structure is lgN. The Worst case of an insertion is N, and the average case of an insertion is N/2.

18
New cards

Binary Search Tree

Will have a best case high of lgN. This is also its expected height. In the worst case, it will have a height of N, and thus become similar to a linked list.

Works by inserting nodes of lesser values to the left of a node, and inserting greater values to the right of the node, traversing down the tree until we reach a blank spot to insert.

Has a worst case cost of N to search and insert node. The average case of searching will be 1.39lgN compares

19
New cards

2-3 Tree

Balanced tree data structure with logN complexities on searching, inserting, and deleting in both the worst and average cases. In this data structure, every node with children has either two children and one data element, or three children and two data elements. Leaf nodes will contain only one or two data elements.

20
New cards

Red Black Tree

Worst case height of 2log(n+1). The nodes are either red or black. The root is black. If a node is red, its children MUST BE BLACK. Every path from a node to a leaf must contain the same number of black nodes. New insertions will always be red and always left leaning. Insertions must satisfy the conditions that red nodes have black children and that they have the same number of black nodes in all paths. Time complexity on its operations are O(logN).

21
New cards

Tries

A collection of nodes, each of which can hold a key and a value- often the values will be null. The nodes will have a value attached to the last character of the string upon insertion, which apparently makes searching very easy.

Very useful for searching keys.

22
New cards

B-Trees

Items are stored in leaves. The root is either a leaf, or it will have between two and M children. All non-leaf nodes will have between M/2 and M children. All leaves will be at the same depth and store between L/2 and L data values where we are free to choose L. Useful for data storage, searching a database/sorted files.

Time complexity of logN.

23
New cards

Undirected Graph

Given any path connecting vertices A and B, you can travel from A to B or B to A

24
New cards

Directed Graph

Given a path connecting vertices A and B you can only travel in 1 direction

25
New cards

Path

The edge, or link between two vertices

26
New cards

Weighted Graph

A graph which places "costs" on the edges for traveling their path

27
New cards

Cycles

When there are at least two unique paths which connect vertices A and B, forming a loop or loops

28
New cards

DAG (Directed Acyclic Graph)

A graph which is directed and contains no cycles

29
New cards

Depth First Search

A method which is used to traverse through a graph. Works by creating a stack of nodes to visit, which consist of all the nodes around your current position. You move to the next location and add the nodes surrounding it to the stack, making sure not to add any nodes you may have already visited. You repeat this pattern until you either reach the destination, or a dead end. At a dead end, you would backtrack to the last node which still has unvisited neighbors.

Time complexity of |V|+|E|

30
New cards

Topological Sort

Linear ordering of the vertices of a directed graph such that for every directed edge "uv" which connects "u" to "v" (u points to v), u comes before v. This ordering is only possible if and only if there are no directed cycles in the graph, therefore, it must be a DAG.

31
New cards

Minimum Weight Spanning Trees (MST)

A spanning tree whose weight is no larger than the weight of any other spanning tree which could be made with the graph. The properties of this thing include that the graph is connected, the edge weights may not necessarily be distances, the edge weights may be zero or negative, and the edge weights are all different.

Can be constructed using a greedy algorithm such as Prim's or Kruskal's.

Generally used in network design.

32
New cards

Prim's Algorithm

MST builder/Greedy Algorithm which works by taking a starting vertex and then successively adding the neighbor vertices which have the lowest cost of addition and don't create cycles upon their addition.

Time complexity ElogE

33
New cards

Kruskal's Algorithm

MST Builder/Greedy Algorithm which works by taking edges in order of their weight values, continuously adding edges to the tree if their addition doesn't create a cycle.

Is generally slower than the other prominent Greedy Algorithm due to its need to check whether or not an edge is part of a cycle at each phase.

Time complexity ElogE

34
New cards

Union Find

Data structure used to make sure a cycle is not created in a MST.

35
New cards

Dijksta's Algorithm

Finds the shortest path with no negative weights given a source vertex. Tries to find the distance to all other vertices in the graph. It produces a shortest paths tree by initializing the distance of all other nodes to infinity, and then relaxes these distances step by step by iteratively adding vertexes that dont already exist in the tree and have the lowest cost of distance to travel to them.

Time complexity O(|E|+|V|log|V|)

36
New cards

Memoization

What happens when a sub problem's solution is found during the process of Dynamic Programming. The solution is stored for future use, so that it may be reused for larger problems which contain this same subproblem. This helps to decrease run time.

37
New cards

Bellman-Ford Algorithm

Algorithm which computes shortest paths from a single vertex to all other vertices in a weighted digraph. Is slower than its counterpart, but is able to handle edge weights with negative values. Works by initially setting the distance to all nodes to infinity, and then iteratively relaxing the edges in an order which would maintain a shortest path from the starting edge to any other edge.

Has a time complexity of O(EV)

38
New cards

Selection sort

Find smallest, put at beginning

Best: O(n^2)

Avg: O(n^2)

Worst: O(n^2)

39
New cards

Insertion sort

Side-by-side comparison

Best: O(n)

Avg: O(n^2)

Worst: O(n^2)

40
New cards

Shellsort

Insertion sort over a gap

Best: O(n log n)

Avg: depends on gap sequence

Worst: O(n^2)

41
New cards

Mergesort

split into sub-arrays

Best: O(n log n)

Avg: O(n log n)

Worst: O(n log n)

42
New cards

Quicksort

partitioning

Best: O(n log n) (or O(n) three-way)

Avg: O(n log n)

Worst: O(n^2)

43
New cards

Binary Search Tree

Avg height: O(log n)

Worst height: O(n)

44
New cards

Red-black Tree

Worst height: 2 log n

45
New cards

LSD

String/character sort from right to left

46
New cards

MSD

String/character sort from left to right, must keep appending from previous letters to keep order

47
New cards

Trie

Search tree but with a child position for each character in the library

Think spelling

48
New cards

B-tree

That tree where you have like 5 keys in a node and 6 offshoots

49
New cards

Breadth-first search

Use a queue to search tree

50
New cards

Depth-first search

Use a stack or recursion to search tree

51
New cards

Topographical sort

Some things have to come before others

Ex: getting dressed, course prereqs

Not necessarily unique

52
New cards

MST

Minimum spanning tree

Least weight that connects all nodes

No cycles

53
New cards

Prim's Algorithm

Start with one vertex, grow tree on min weight edge from all vertices

So out of all reachable edges that don't cause cycles, take the smallest

54
New cards

Kruskal's algorithm

Keep adding smallest edges

55
New cards

Dijkstra's algorithm

Marking nodes as they are added to tree, update reachable unmarked nodes with weight from beginning. Take smallest total weight. Repeat.

56
New cards

Self-loop

A self-loop is an edge that connects a vertex to itself.

57
New cards

Parallel

Two edges are parallel if they connect the same pair of vertices.

58
New cards

degree

The degree of a vertex is the number of edges incident on it.

59
New cards

subgraph

A subgraph is a subset of a graph's edges (and associated vertices) that constitutes a graph.

60
New cards

Path

A path in a graph is a sequence of vertices connected by edges. A simple path is one with no repeated vertices.

61
New cards

Cycle

A cycle is a path (with at least one edge) whose first and last vertices are the same. A simple cycle is a cycle with no repeated edges or vertices (except the requisite repetition of the first and last vertices).

62
New cards

Length

The length of a path or a cycle is its number of edges.

63
New cards

connected graph

A graph is connected if there is a path from every vertex to every other vertex.

64
New cards

connected vertices

We say that one vertex is connected to another if there exists a path that contains both of them.

65
New cards

connected components

A graph that is not connected consists of a set of connected components, which are maximal connected subgraphs.

66
New cards

acyclic

An acyclic graph is a graph with no cycles.

67
New cards

tree

A tree is an acyclic connected graph.

68
New cards

forest

A forest is a disjoint set of trees.

69
New cards

spanning tree

A spanning tree of a connected graph is a subgraph that contains all of that graph's vertices and is a single tree.

70
New cards

spanning forest

A spanning forest of a graph is the union of the spanning trees of its connected components.

71
New cards

bipartite graph

A bipartite graph is a graph whose vertices we can divide into two sets such that all edges connect a vertex in one set with a vertex in the other set.

72
New cards

outdegree and indegree

The outdegree of a vertex is the number of edges pointing from it. The indegree of a vertex is the number of edges pointing to it.

73
New cards

directed path

A directed path in a digraph is a sequence of vertices in which there is a (directed) edge pointing from each vertex in the sequence to its successor in the sequence.

74
New cards

simple path

A directed path with no repeated vertices

75
New cards

directed cycle

A directed cycle is a directed path (with at least one edge) whose first and last vertices are the same.

76
New cards

simple cycle

A simple cycle is a cycle with no repeated edges or vertices (except the requisite repetition of the first and last vertices).

77
New cards

reachable

We say that a vertex w is reachable from a vertex v if there exists a directed path from v to w.

78
New cards

strongly connected vertices

We say that two vertices v and w are strongly connected if they are mutually reachable: there is a directed path from v to w and a directed path from w to v.

79
New cards

strongly connected digraph

A digraph is strongly connected if there is a directed path from every vertex to every other vertex.

80
New cards

directed acyclic graph

A directed acyclic graph (or DAG) is a digraph with no directed cycles.

81
New cards

Isolate the lowest bit that is 1 in x

x & ~(x - 1)

82
New cards

Replace the lowest bit that is 1 with 0

x & (x - 1)

83
New cards

Right propagate the rightmost set bit in x

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

84
New cards

Compute x modulo a power of 2 (y)

x & (y - 1)

85
New cards

Compute XOR of every bit in an integer

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

86
New cards

Standard data structure for solving complex bit manipulation

Lookup table

87
New cards

Concrete Examples

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

88
New cards

Case Analysis

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

89
New cards

Iterative Refinement

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

90
New cards

Reduction

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

91
New cards

Graph Modeling

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

92
New cards

Sorting

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

93
New cards

Recursion

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

94
New cards

Divide-and-conquer

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

95
New cards

Greedy Algorithms

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

96
New cards

Invariants

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

97
New cards

Heuristics

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

98
New cards

memoization

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.

99
New cards

Typical runtime of a recursive function with multiple branches

O( branches^depth )

100
New cards

Arithmetic progressions

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

<p>For p &lt; -1, this sum always converges to a constant.</p>