

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























1D Array - ANSA linear collection of data items in a program, all of the same type, such as an array of integers or an array of strings, stored in contiguous memory, and easily accessed using a process called indexing. 2D Array - ANSAn array of an arrays, characterized by rows and columns, arranged in a grid format, but still stored in contiguous, or side-by-side memory, accessed using two index values. 3-Way Quick Sort - ANSNon-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. 4 Rules of Recursion - ANSBase Cases: You must always have some base cases, which can be solved without recursion. Making Progress: For the cases that are to be solved recursively, the recursive call must make progress to a base case. Design rule: Assume that all recursive calls work Compound Interest Rule: Never duplicate word by solving the same instance of a problem in separate recursive calls. Abstract Data Types - ANSConsists of 2 parts:
Advantages/Disadvantages of Common Sorting Algorithms - ANS Aggregate Data Types - ANSAny type of data that can be referenced as a single entity, and yet consists of more than one piece of data, like strings, arrays, classes, and other complex structures. Algorithm - ANShas input, produces output, definite, finite, operates on the data it is given Algorithm Analysis - ANShow long it takes a computer to do something Anagram - ANSa word, phrase, or name formed by rearranging the letters of another, such as cinema, formed from iceman. Arithmetic progressions - ANSFor p < -1, this sum always converges to a constant. Array Bucket - ANS-- a bucket of arrays. -Fixed in size. -size of about 3 work usually well. Array Index - ANSA value that indicates the position in the array of a particular value. The last element in a zero-indexed array would be the length of the array, minus 1. Array length - ANSA value that represents the number of elements contained in an array. Often there is a process associated with an array that provides this value, such as list.length, or len(list). Array: access, search, insert, delete - ANSAccess: O(1)
Big-Oh - ANST(n) = O(f(n)) if there are positive constants c & n° such that T(n) <= c * f(n) for all n >= n° Binary Search - ANSAn 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. Binary Search Tree - ANSAvg height: O(log n) Worst height: O(n) Binary Search Tree - ANSWill 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 Binary Tree - ANSA data structure that consists of nodes, with one root node at the base of the tree, and two nodes (left child and right child) extending from the root, and from each child node. Bit Array - ANSA 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). Bloom Filters - ANSProbabilistic hash table. No means no. Yes means maybe. Multiple (different) hash functions. Can't resize table. Also can't remove elements. Breadth-First Search - ANSExplores 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. Bubble Sort - ANSStable, O(n^2), Ω(n) : Compares neighboring elements to see if sorted. Stops when there's nothing left to sort. Bucket Sort - ANSO(n+m) where m is the # of buckets. Case Analysis - ANSAnalysis pattern. Split the input/execution into a number of cases and solve each case in isolation Chained bucket: - ANS+--easy to implement +-- buckets can't overfill +-- buckets won't waste time. +-- buckets are dynamically sized.
Compute x modulo a power of 2 (y) - ANSx & (y - 1) Compute XOR of every bit in an integer - ANSSimilar 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 Concrete Examples - ANSAnalysis pattern. Manually solve concrete instances of the problem and then build a general solution Contiguous Memory - ANSMemory that is "side-by-side" in a computer, typical of an array structure. Counting Sort - ANSAn 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. Counting Sort (Key Indexed sort) - ANSAn 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. cycle - ANSA path of positive length that starts and ends at the same vertex and does not traverse the same edge more than once. data structure - ANSa particular scheme organizing related data items. Data Structure - ANSA way of organizing data in a computer so that it can be used efficiently, such as an array, linked list, stack, queue, or binary tree. Depth-First Search - ANSExplore 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. Dictionary: definition - ANSA data structure that maps keys to values.
Insert: O(1) Delete: O(1) Doubly Linked List: advantage, disadvantage - ANSAdvantage: quick insert, quick delete Disadvantage: slow search Doubly Linked List: memory - ANSMemory: O(3n) (LL: O 2n) Dynamic Memory - ANSMemory that is allocated as needed, and NOT contiguous (side-by-side), specifically during the implementation of a linked list style data structure, which also includes binary trees and graphs. Dynamic Programming - ANSBreak 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. Euclidean Algorithm GCD - ANSdef gcd(a, b): while a: b, a = a, b%a return b Exception handling - ANSWhen there's an error, the program makes an error object and passes it off to the runtime system, which looks for a method in the call stack to handle it.
External Sorting - ANSExternal 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. Extraction: - ANSBreaking keys into parts and using the parts that uniquely identify with the item. 379452 = 394 121267 = 112 Fibonacci Heap - ANSA 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
Good Hash Function qualities: - ANS1. Must be deterministic: -> Key must ALWAYS generate the same Hash Index (excluding rehashing).
v = v - ((v>>1) & 0x55555555); v = (v & 0x33333333) + ((v>>2) & 0x33333333); int count = ((v + (v>>4) & 0xF0F0F0F) * 0x1010101) >> 24; Hash collision - ANStwo (or more) keys hash to same slot Hash Function - ANSA function that takes in the key to compute a specific Hash Index. Hash function - ANStakes an object and tells you where to put it. Hash Table - ANSConstant access time (on average). hash Table: - ANSAn array that stores a collection of items. HashCode Method: - ANS-method of OBJECT class -Returns an int -default hash code is BAD-- computed from Object's memory address. --> must override HashMap complexity of basic operations: - ANSO(1) HashMap underlying structure: - ANSHashTable with chained buckets HashTable & HashMap class - ANSjava.util
Heapify (bubble down) - ANSSwap 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. Heuristics - ANSAny 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 How do you delete a value within the hash table? - ANSYou just set Table[hash(Key)] = null How do you insert a value within the hash table? - ANSTable[Hash(key)]=data; How do you look up a value within the hash table? - ANSreturn Table[Hash(key)]; How does Hashing work? - ANS1. you have a key for the item.
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 - ANS-> We'd simply count each one as an index -> Hash table would be huge. Important Sorting Assumptions - ANS1.Sorting array of integers
Iterative Refinement - ANSAnalysis pattern. Most problems can be solved using s brute-force approach. Find such a solution and improve upon it. Iterators - ANSAn object that knows how to "walk" over a collection of things. Encapsulates everything it needs to know about what it's iterating over. Should all have similar interfaces. Can read data, move, know when to stop. Key - ANSInformation in items that is used to determine where the item goes into the table. L N R - ANSin-order traversal L R N - ANSPostorder traversal (Reverse Polish) Lazy Deletion - ANSMarking a spot as deleted in a hash table rather than actually deleting it. Linear Data Structure - ANSA programming data structure that occupies contiguous memory, such as an array of values. Linear Probing - ANSChecks each spot in order to find available location, causes primary clustering. Linear Probing: - ANSStep size is 1. Find the index, and keep incrementing by one until you find a free space. Linked List - ANSA linear data structure, much like an array, that consists of nodes, where each node contains data as well as a link to the next node, but that does not use contiguous memory.
linked list - ANSA sequence of zero or more nodes containing some data and pointers to other nodes of the list. list - ANSa collection of data items arranged in a certain linear order Little-Oh - ANST(n) = 0(f(n)) if T(n) = O(f(n)) and T(n) != Ω(f(n)) Load Factor - ANS#items(n) / table size Load Factor - ANSApproximately how it's full... 0.7-0.8. Load Factor (LF) - ANSNumber of items/Table size. For instance, a load factor of 1 = 100% of the items are used. memoization - ANSAn 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. Memoization - ANSWhat 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. Merge Sort - ANSStable, O(n log n), Ω(n log n): Use recursion to split arrays in half repeatedly. An array with size 1 is already sorted. Mergesort - ANSsplit into sub-arrays