Docsity

ALGORITHMS & DATA STRUCTURES| IT| COMPUTER SCIENCE, Exams of Computer Science

Toggle sidebar
bg1
ALGORITHMS & DATA STRUCTURES|
IT| COMPUTER SCIENCE
Greedy Algorithm - Answer-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.
Divide and Conquer - Answer-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.
Recursive Algorithms - Answer-solve a problem by solving smaller internal instances of
a problem -- work towards a base case.
Dynamic Programming - Answer-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.
Selection Sort - Answer-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.
Insertion Sort - Answer-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.
ShellSort - Answer-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.
Quick Sort - Answer-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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download ALGORITHMS & DATA STRUCTURES| IT| COMPUTER SCIENCE and more Exams Computer Science in PDF only on Docsity!

ALGORITHMS & DATA STRUCTURES|

IT| COMPUTER SCIENCE

Greedy Algorithm - Answer-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. Divide and Conquer - Answer-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. Recursive Algorithms - Answer-solve a problem by solving smaller internal instances of a problem -- work towards a base case. Dynamic Programming - Answer-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. Selection Sort - Answer-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. Insertion Sort - Answer-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. ShellSort - Answer-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. Quick Sort - Answer-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. 3-Way Quick Sort - Answer-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. Mergesort - Answer-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. Heap Sort - Answer-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. Lower Bound on the complexity of pairwise comparisons - Answer-No compare based sorting algorithm can have fewer than ~NlogN compares Counting Sort (Key Indexed sort) - Answer-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. LSD Radix Sort - Answer-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.

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. Undirected Graph - Answer-Given any path connecting vertices A and B, you can travel from A to B or B to A Directed Graph - Answer-Given a path connecting vertices A and B you can only travel in 1 direction Path - Answer-The edge, or link between two vertices Weighted Graph - Answer-A graph which places "costs" on the edges for traveling their path Cycles - Answer-When there are at least two unique paths which connect vertices A and B, forming a loop or loops DAG (Directed Acyclic Graph) - Answer-A graph which is directed and contains no cycles Depth First Search - Answer-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| Topological Sort - Answer-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. Minimum Weight Spanning Trees (MST) - Answer-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. Prim's Algorithm - Answer-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 Kruskal's Algorithm - Answer-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 Union Find - Answer-Data structure used to make sure a cycle is not created in a MST. Dijksta's Algorithm - Answer-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|) Memoization - Answer-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. Bellman-Ford Algorithm - Answer-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) Selection sort - Answer-Find smallest, put at beginning Best: O(n^2) Avg: O(n^2) Worst: O(n^2) Insertion sort - Answer-Side-by-side comparison Best: O(n) Avg: O(n^2) Worst: O(n^2) Shellsort - Answer-Insertion sort over a gap Best: O(n log n) Avg: depends on gap sequence Worst: O(n^2)

Dijkstra's algorithm - Answer-Marking nodes as they are added to tree, update reachable unmarked nodes with weight from beginning. Take smallest total weight. Repeat. Self-loop - Answer-A self-loop is an edge that connects a vertex to itself. Parallel - Answer-Two edges are parallel if they connect the same pair of vertices. degree - Answer-The degree of a vertex is the number of edges incident on it. subgraph - Answer-A subgraph is a subset of a graph's edges (and associated vertices) that constitutes a graph. Path - Answer-A path in a graph is a sequence of vertices connected by edges. A simple path is one with no repeated vertices. Cycle - Answer-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). Length - Answer-The length of a path or a cycle is its number of edges. connected graph - Answer-A graph is connected if there is a path from every vertex to every other vertex. connected vertices - Answer-We say that one vertex is connected to another if there exists a path that contains both of them. connected components - Answer-A graph that is not connected consists of a set of connected components, which are maximal connected subgraphs. acyclic - Answer-An acyclic graph is a graph with no cycles. tree - Answer-A tree is an acyclic connected graph. forest - Answer-A forest is a disjoint set of trees. spanning tree - Answer-A spanning tree of a connected graph is a subgraph that contains all of that graph's vertices and is a single tree. spanning forest - Answer-A spanning forest of a graph is the union of the spanning trees of its connected components. bipartite graph - Answer-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.

outdegree and indegree - Answer-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. directed path - Answer-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. simple path - Answer-A directed path with no repeated vertices directed cycle - Answer-A directed cycle is a directed path (with at least one edge) whose first and last vertices are the same. simple cycle - Answer-A simple cycle is a cycle with no repeated edges or vertices (except the requisite repetition of the first and last vertices). reachable - Answer-We say that a vertex w is reachable from a vertex v if there exists a directed path from v to w. strongly connected vertices - Answer-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. strongly connected digraph - Answer-A digraph is strongly connected if there is a directed path from every vertex to every other vertex. directed acyclic graph - Answer-A directed acyclic graph (or DAG) is a digraph with no directed cycles. Isolate the lowest bit that is 1 in x - Answer-x & ~(x - 1) Replace the lowest bit that is 1 with 0 - Answer-x & (x - 1) Right propagate the rightmost set bit in x - Answer-x | (x & ~(x - 1) - 1) Compute x modulo a power of 2 (y) - Answer-x & (y - 1) Compute XOR of every bit in an integer - Answer-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

memoization - Answer-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. Typical runtime of a recursive function with multiple branches - Answer- O( branches^depth ) Arithmetic progressions - Answer-For p < -1, this sum always converges to a constant. Geometric series - Answer-. Dominance pecking order - Answer- Big Oh Notation - Answer- Stable Sorting Algorithm - Answer-Items with the same key are sorted based on their relative position in the original permutation Trie - Answer-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. Hamming Weight - Answer-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; Bit Array - Answer-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). One-Sided Binary Search - Answer-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. Recurrence Relation - Answer-An equation that is defined in terms of itself. Any polynomial or exponential can be represented by a recurrence. Divide-and-Conquer Recurrances - Answer-T(n) = aT(n/b) + f(n) Solving Divide-and-Conquer Recurrances - Answer-Case 1: Too many leaves. Case 2: Equal work per level. Case 3: Too expensive a root Heapify (bubble down) - Answer-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. Permutations - Answer-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 Combinations - Answer-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

Connected Component - Answer-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). Vertex-coloring - Answer-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. Bipartite Graph - Answer-Graph can be colored without conflicts while using only two colors. In-Order Traversal - Answer-1. Process left child.

  1. Process self.
  2. Process right child. Pre-Order Traversal - Answer-1. Process self.
  3. Process left child.
  4. Process right child. Post-Order Traversal - Answer-1. Process left child.
  5. Process right child.
  6. Process self. Breadth-First Search - Answer-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. Depth-First Search - Answer-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. Articulation Vertex - Answer-The weakest point in a graph Topological Sort - Answer-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. Strongly Connected Graphs - Answer-There lies a path between any two vertices on a directed graph.

Chromatic Number - Answer-The smallest number of colors needed for an edge coloring of a graph Degree of a Vertex - Answer-The number of edges incident of the vertex, with loops counted twice Quick Select - Answer-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: Balanced Binary Tree - Answer-For each node in the tree, the difference in the height of its left and right subtrees is at most one. Perfect Binary Tree - Answer-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. Rooted Binary Tree - Answer-A rooted binary tree has a root node and every node has at most two children. Full Binary Tree - Answer-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. Complete Binary Tree - Answer-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. Degenerate Binary Tree - Answer-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. Combinations of binary tree traversal sequences that uniquely identify a tree - Answer-

  1. Inorder and preorder.
  2. Inorder and postorder.
  3. inorder and level-order. Combinations of binary tree traversal sequences that do not uniquely identify a tree - Answer-1. Postorder and preorder.
  4. Preorder and level-order.
  5. Postorder and level-order.

be more than one minimum spanning tree in a graph. All spanning trees of an unweighted graph are minimum spanning trees. Prim's Algorithm - Answer-(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. Kruskal's Algorithm - Answer-(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. Union-Find - Answer-(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. Sparse Graph - Answer-A graph in which the number of edges is close to the minimal number of edges. Sparse graphs can be a disconnected Set Partition - Answer-A partitioning of elements of some universal set into a collection of disjointed subsets. Thus, each element must be in exactly one subset. Maximum Spanning Tree - Answer-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. Minimum Product Spanning Tree - Answer-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.

Fibonacci Heap - Answer-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 prior Dijkstra's Algorithm - Answer-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. Floyd-Warshall Algorithm - Answer-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. Type erasure - Answer-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.

Replica - Answer-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. Sharding - Answer-Sharding is a type of database partitioning that separates very large databases the into smaller, faster, more easily managed parts called data shards. What is the goal of Hashing? - Answer-Do faster than O(LogN) time complexity for: lookup, insert, and remove operations. To achieve O(1) What kind of Collection is Hashing? - Answer-value-orientated. How does Hashing work? - Answer-1. you have a key for the item.

  1. the item's key gets churned within the hash function to form the Hash index.
  2. The hash index can be applied to the data array, and so, the specific data is found. hash Table: - Answer-An array that stores a collection of items. Table Size(TS) - Answer-The Array's Length Load Factor (LF) - Answer-Number of items/Table size. For instance, a load factor of 1 = 100% of the items are used. Key - Answer-Information in items that is used to determine where the item goes into the table. Hash Function - Answer-A function that takes in the key to compute a specific Hash Index. What would the Perfect Hash Function be? - Answer-Each Key maps to an unique Hash Index. How do you delete a value within the hash table? - Answer-You just set Table[hash(Key)] = null How do you look up a value within the hash table? - Answer-return Table[Hash(key)]; How do you insert a value within the hash table? - Answer-Table[Hash(key)]=data; What is the worst case time complexity for: Insert, lookup, and delete, for hash functions? - Answer-O(1)

If we have UW-Madison student ID's, and we wanted the ideal hash functions, how would we do it, and why would there be a problem - Answer--> We'd simply count each one as an index -> Hash table would be huge. Collisions: - Answer-When the Hash Function returns the same index for different keys. Good Hash Function qualities: - Answer-1. Must be deterministic: -> Key must ALWAYS generate the same Hash Index (excluding rehashing).

  1. Must achieve uniformity -> Keys should be distributed evenly across hash table.
  2. FAST/EASY to compute -> only use parts of the key that DISTINGUISH THE ITEMS FROM EACH OTHER
  3. Minimize collisions: Extraction: - Answer-Breaking keys into parts and using the parts that uniquely identify with the item. 379452 = 394 121267 = 112 Folding: - Answer-Combining parts of the key using operations like + and bitwise operations such as exclusive or. Key: 123456789 123 456 789 1368 ( 1 is discarded) Weighting: - Answer-Emphasizing some parts of the key over another. Compressing: - Answer-Ensuring the hash code is a valid index for the table size. The more items a table can hold, the () likely a collision will happen. - Answer-less Load Factor - Answer-Approximately how it's full... 0.7-0.8. Why do we use prime numbers for table size? - Answer-We mod often, and prime numbers give us the most unique numbers. (2*ts+1) Steps to resizing: - Answer-1. Double table size to nearest prime number
  4. Re-hash items from old table into the new table.