









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A study guide for C949 Data Structures and Algorithms. It includes definitions and examples of data structures, algorithms, and sorting methods. It also covers topics such as ADT, function, polymorphism, and instantiation. the Big O notation and provides examples of sorting algorithms such as selection, insertion, shell, quick, merge, and bucket sort. It is a useful resource for students studying data structures and algorithms.
Typology: Exams
1 / 15
This page cannot be seen from the preview
Don't miss anything!










Record - Answer: Data structure that stores subitems, w/ names associated w/ each subitem Array - Answer: Data structure that stores an ordered list of items, w/ each item directly accessible by a positional index. Linked List - Answer: Data structure that stores an ordered list as nodes, each node stores data and has a pointer to the next node.
Binary Tree - Answer: Data structure where each node stores data and has up to two children, left child and right child. Hash Table - Answer: Data structure that stores unordered items by mapping each item to a location in an array. Max Heap - Answer: Tree that maintains the simple property that a node's key is greater than or equal to a node's children key. Min Heap - Answer: A tree that maintains simple property that node's key is less than or equal to the node's children key. Graph - Answer: Represents connections among items. Consists of vertices and edges. Vertex represents an item on a graph. Edges represent a connection between two vertices. ADT (Abstract Data Type) - Answer: Data type described by predefined user operations. Does not say anything about the implementation.
if expression:
else:
Boolean Operators - Answer: Has 3 operators: and / or / not In Python, True/False are case sensitive Membership Operators - Answer: not , in Cannot check for values but can check for keys. ex. my_dict = {'A': 1, 'B': 2, 'C': 3} if 'B' in my_dict: print("Found 'B'") else: print("'B' not found")
if 3 in my_dict: print('Found 3') else: print('3 not found') reversed() - Answer: Iterates over a for loop backwards. ex. print('\nPrinting in reverse:') for name in reversed(names): print(name, '|', end=' ') Function (invoking a function is called a function call, which causes a function to execute. ) - Answer: Named series of statements. e.g.: def compute_square(num_square): return num_square * num_square
print('Go!') else: print(count) count_down(count-1) count_down(2) Loop over dictionaries - Answer: for key in dictionary: # Loop expression
#Statements to execute after the loop Conditional List - Answer: new_list = [expression for name in iterable if condition] Algorithm Efficiency - Answer: measures algorithm complexity Computational Complexity - Answer: amount of resources used by algorithm. ex runtime / memory usage.
Big O - Answer: notation for expressing the worst-case run-time of an algorithm, useful for comparing the speed of two algorithms. logN (log2N + 1) - Answer: binary search efficiency Selection Sort - Answer: A sort algorithm that repeatedly scans for the smallest item in the list and swaps it with the element at the current index. The index is then incremented, and the process repeats until the last two elements are sorted. Run time : O(N^2) Insertion Sort - Answer: A simple sorting algorithm that builds the final sorted array (or list) one item at time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. Run time : O(N^2) selection, insertion - Answer: difference is in what the inner loop does: In _______ sort, the inner loop is over the unsorted elements. Each pass selects one element, and moves it to its final location (at the current end of the sorted region).
In _______ sort, each pass of the inner loop iterates over the sorted elements. Shell Sort - Answer: Starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared. Starting with far apart elements can move some out-of-place elements into position faster than a simple nearest neighbor exchange. gap value: distance between elements in an interleaved list Worst Case: O(N^(3/2)) Quick Sort - Answer: Unstable, O(n log n) for a good pivot,O(n^2) for a bad pivot Ω(n log n) : Uses partitioning O(n), Pick a median of 1st, middle, and last element for pivot. Random selection is also good, but expensive. Algorithm can be slow because of many function calls. Midpoint: i + (k-i)/ def quicksort (numbers, start_index, end_index):
Radix Sort - Answer: an O(n*k) search algorithm where K = keylength. Stable. Sorts input into bins based on the lowest digit; then combines bins in order and sorts on the next highest digit & so forth. O(d(n+b)) Bubble Sort - Answer: Moving through a list repeatedly, swapping elements that are in the wrong order. O(N^2) Quickselect - Answer: A selection algorithm to find the kth smallest element in an unordered list.
Appending to a list - Answer: Inserts a new node after the lists tail. Prepending to a list - Answer: Inserts a new node before the list's head node. insertAfter() - Answer: Insert every element in the set of matched elements after the target. (list, curNode, newNode) RemoveAfter() - Answer: Removes node after specified list node. Hash Table - Answer: A data structure that stores unordered items by mapping each item to a location in an array (or vector) Mid square - Answer: hash function that extracts R digits middle number and returns middle number divided by hash table size remainder. For N buckets R must be greater than or equal to log N ex. 453*453 = 205209 middle number is 52 52 % 100 gives remainder 52.