Data Structures and Algorithms I - C949
Self
A method parameter that refers to the class instance.
Stack
An ADT in which items are only inserted on or removed from the top of a _____. Common underlying data structures (Linked list)
Sorting
the process of converting a list of elements into ascending (or descending) order
Python float
Numeric type: Used for floating-point numbers.
locals()
Returns a dictionary of the names found in the local namespace.
NP-complete
____ are problems with no practical algorithmic solutions. a A set of problems for which no known efficient algorithm exists
scope resolution
he process of searching for a name in the available namespaces.
Asymptotic Notation
the classification of runtime complexity that uses functions that indicate only the growth rate of a bounding function
sorted()
A built-in Python function that takes one list argument, sorts the list's elements in ascending order using the less than (<) operator, and returns a new list with the sorted elements.
Graph
A data structure for representing connections among items, and consists of vertices connected by edges. A vertex represents an item in a _____. An edge represents a connection between two vertices in a _____.
Array
A data structure that stores an ordered list of items, with each item is directly accessible by a positional index.
Linked list
A data structure that stores ordered list of items in nodes, where each node stores data and has a pointer to the next node.
Hash table
A data structure that stores unordered items by mapping (or hashing) each item to a location in an array.
abstract data type (ADT)
A data type described by predefined user operations, such as "insert data at rear," without indicating how each operation is implemented. ______ can be implemented using different underlying data structures. However, a programmer need not have knowledge of the underlying implementation to use ________.
recurrence relation
A function f(N) that is defined in terms of the same function operating on a value < N.
Lower bound
A function f(N) that is ≤ the best case T(N), for all values of N ≥ 1
O(N)
A linear search has a _____ runtime complexity
Big O notation
A mathematical way of describing how a function (running time of an algorithm) generally behaves in relation to the input size.
Heap
A max-_____ is a tree that maintains the simple property that a node's key is greater than or equal to the node's childrens' keys. A min-_____ is a tree that maintains the simple property that a node's key is less than or equal to the node's childrens' keys.
Machine instruction
A series of 0s and 1s, stored in memory, that tells a processor to carry out a particular operation like a multiplication.
Radix sort
A sorting algorithm designed specifically for integers. The algorithm makes use of a concept called buckets and is a type of bucket sort. The algorithm processes one digit at a time starting with the least significant digit and ending with the most significant. Two steps are needed for each digit. First, all array elements are placed into buckets based on the current digit's value. Then, the array is rebuilt by removing all elements from buckets, in order from lowest bucket to highest.
base case
Because a problem cannot be endlessly divided into smaller subproblems, a recursive algorithm must have a _________: where a recursive algorithm completes without applying itself to a smaller subproblem. The ______ is what ensures that a recursive algorithm eventually terminates
Branching
Directs a program to execute either one group of statements or another, depending on the result of an expression.
range()
Generates a sequence of numbers, starting at zero and ending before a value given inside the parentheses.
Assembly language
Human-readable processor instructions; an assembler translates to machine instructions (0s and 1s).
26
If shell_sort() is run with an input list of size 20 and a gap values list of [15, 7, 3, 1], how many times will insertion_sort_interleaved() will be called?
Mutability
Indicates whether the object's value is allowed to change
Python int
Numeric type: Used for variable-width integers.
Integrated Development Environment (IDE)
Provides a developer with a way to create a program, run the program, and debug the program all within one application. IDLE is the official Python ______.
sort()
Python list method to do an in-place sorting of list elements in ascending order, meaning the list is modified and another list is not returned.
computational thinking
The method of evaluating a problem's most basic parts and then creating an algorithm to solve that problem is commonly known as __________.
Moore's Law
The observation that computing power roughly doubles every two years. The doubling of IC capacity roughly every 18 months.
Dictionary (Map)
n ADT that associates (or maps) keys with values. Common underlying data structures (Hash table, binary search tree)
auxiliary space complexity
The space complexity not including the input data. Ex: An algorithm to find the maximum number in a list will have a space complexity of S(N) = N + k, but an ______ of S(N) = k, where k is a constant.
Python dict
Mapping type: A container with key-values associated elements
recursion tree
A visual diagram of a operations done by a recursive function, that separates operations done directly by the function and operations done by recursive calls
Bag
Items are not ordered. Duplicate items are allowed. An ADT for storing items in which the order does not matter and duplicate items are allowed. Common underlying data structures (Array, linked list)
Set
Items are not ordered. Duplicate items are not allowed. A _______ is an ADT for a collection of distinct items, so duplicate items are not allowed. Common underlying data structures (Binary search tree, hash table)
Priority queue
Items are ordered based on items' priority. Duplicate items are allowed. A ______ is an ADT where each item has a priority. Items with higher priority are closer to the front of the queue than items with lower priority, so the item's priority determines the item's position in the queue. Both duplicate items and items with the same priority are allowed. A queue where each item has a priority, and items with higher priority are closer to the front of the queue than items with lower priority. Common underlying data structures (Heap)
Python list
Sequence type: A mutable container with ordered elements.
Python tuple
Sequence type: An immutable container with ordered elements.
Python string
Sequence type: Used for text.
Merge sort
Sorting algorithm that uses merge() and merge_sort().
Computational Problem
Specifies an input, a question about the input that can be answered using a computer, and the desired output.
worst-case runtime
The ______ of an algorithm is the runtime complexity for an input that results in the longest execution.
Scope
The area of code where a name is visible. Namespaces are used to make ______ work.
Record
The data structure that stores subitems, with a name associated with each subitem.
reserved words
Those words are part of the language and are called _____ and thus cannot be used as a programmer-defined name. Also known as keywords.
Task decomposition
To reduce a complex task into simpler basic steps, making the whole task easier to solve. A computer program is generally created by _____ into simpler basic steps, and then instructing a computer to perform those steps in a certain order.
syntax error
To violate a programming language's rules on how symbols can be combined to create a program. An example is putting multiple prints on the same line.
Compiler
Translates a high-level language program into low-level machine instructions.
dynamic typing
Used by Pythonto determine the type of objects as a program executes. For example, the consecutive statements num = 5 and num = '7' first assign num to an integer type, and then a string type. The type of num can change, depending on the value it references. The interpreter is responsible for checking that all operations are valid as the program executes. If the function call add(5, '100') is evaluated, an error is generated when adding the string to an integer.
Random Access Memory (RAM)
Volatile storage with faster access usually located off processor chip.
runtime error
Wherein a program's syntax is correct but the program attempts an impossible operation, such as dividing by zero or multiplying strings together (like 'Hello' * 'ABC').
Space-complexity (of an algorithm)
a function, S(N), that represents the number of fixed-size memory units used by the algorithm for an input of size N. Ex: an algorithm that duplicates a list of numbers is S(N) = N + k, where k is a constant representing memory used for things like the loop counter and list pointers.
Computational complexity
the amount of resources used by the algorithm. The most common resources considered are the runtime and memory usage.
Algorithm efficiency
typically measured by the algorithm's computational complexity
constant time operation
an operation that, for a given processor, always operates in the same amount of time, regardless of input values
Namespace
maps names to objects, maps the visible names in a scope to objects.
recursive function
A _____ is a function that calls itself. Commonly used to implement recursive algorithms.
Binary tree
A data structure in which each node stores data and has up to two children, known as a left child and a right child.
Upper bound
A function f(N) that is ≥ the worst case T(N), for all values of N ≥ 1
Attribute
A name following a "." symbol.
Fibonacci sequence
A numerical sequence where each term is the sum of the previous 2 terms in the sequence, except the first 2 terms, which are 0 and 1.
Bucket sort
A numerical sorting algorithm that distributes numbers into buckets, sorts each bucket with an additional sorting algorithm, and then concatenates buckets together to build the sorted result. A bucket is a container for numerical values in a specific range. Ex: All numbers in the range 0 to 50 may be stored in a bucket representing this range. This sort is designed for arrays with non-negative numbers.
interactive interpreter
A program that allows the user to execute one line of code at a time.
O(N^2)
A selection sort has a _____ runtime complexity
algorithm
A sequence of steps for accomplishing a task, methodical step-by-step procedure to perform a task.
Merge sort
A sorting algorithm that divides a list into two halves, recursively sorts each half, and then merges the sorted halves to produce a sorted list. The recursive partitioning continues until a list of 1 element is reached, as list of 1 element is already sorted.
fast sorting algorithm
A sorting algorithm that has an average runtime complexity of O(NlogN) or better.
Binary search
An algorithm that searches a sorted list for a key by first comparing the key to the middle element in the list and recursively searching half of the remaining list so long as the key is not found.
Bubble sort
A sorting algorithm that iterates through a list, comparing and swapping adjacent elements if the second element is less than the first element. It uses nested loops and as such has a runtime of O(N^2). It is often considered impractical for real-world use because many faster sorting algorithms exist.
element comparison sorting algorithm
A sorting algorithm that operates on an array of elements that can be compared to each other. Ex: An array of strings can be sorted with a comparison sorting algorithm, since two strings can be compared to determine if the one string is less than, equal to, or greater than another string. (Selection sort, insertion sort, shell sort, quicksort, merge sort, and heap sort). Radix sort, in contrast, is not as it requires array elements to be numbers.
Quicksort
A sorting algorithm that repeatedly partitions the input into low and high parts (each part unsorted), and then recursively sorts each of those parts. To partition the input, it chooses a pivot to divide the data into low and high parts. The pivot can be any value within the array being sorted, commonly the value of the middle array element. is typically O(N log N), the worst case runtime is O(N^2). Fortunately, this worst case runtime rarely occurs.
Shell sort
A sorting algorithm that treats the input as a collection of interleaved lists, and sorts each list individually with a variant of the insertion sort algorithm. It uses gap values to determine the number of interleaved lists. A gap value is a positive integer representing the distance between elements in an interleaved list. For each interleaved list, if an element is at index i, the next element is at index i + gap value.
Insertion sort
A sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly inserts the next value from the unsorted part into the correct location in the sorted part. typical runtime is O(N^2)
Selection sort
A sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly selects the proper next value to move from the unsorted part to the end of the sorted part. It has the advantage of being easy to code, involving one loop nested within another loop. Algorithm runtime is O(N^2)
data structure
A way of organizing, storing, and performing operations on data. Operations performed on a _____ include accessing or updating stored data, searching for specific data, inserting new data, and removing data.
crash
Abrupt and unintended termination of a program.
List
An ADT for holding ordered data. Items are ordered based on how items are added. Duplicate items are allowed. The order is based on how the program insert or removes items. Common underlying data structures (Array, linked list)
Queue
An ADT in which items are inserted at the end of the ____ and removed from the front of the ____. first-in first-out. Common underlying data structures (Linked list)
Deque
An ADT in which items can be inserted and removed at both the front and back. Common underlying data structures (Linked list)
recursive algorithm
An algorithm that breaks the problem into smaller subproblems and applies the algorithm itself to solve the smaller subproblems
Quickselect
An algorithm that selects the k^th smallest element in a list. Ex: Running quickselect on the list (15, 73, 5, 88, 9) with k = 0, returns the smallest element in the list, or 5. The best case and average runtime complexity are both O(N). In the worst case, it may sort the entire list, resulting in a runtime of O(N^2).
Python interpreter
An application that can be used on various operating systems, including Microsoft Windows, Linux, and MacOS.
Instance
An instantiation of a class.
Application
Another word for program.
computer program
Consists of instructions that a computer executes (or runs), like multiplying numbers or printing a number to a screen.
Operating System
Manages programs and interfaces with peripherals.
Linear search
a search algorithm that starts from the beginning of a list, and checks each element until the search key is found or the end of the list is reached
Disk
Non-volatile storage with slower access.
Constant
O(5) has a _____ runtime complexity
Quadratic
O(N + N^2) has a _____ runtime complexity.
Clock
Rate at which a processor executes instructions.
Cache
Relatively-small volatile storage with fastest access located on processor chip.
static typing
Used by many other languages like C, C++, and Java. Requires the programmer to define the type of every variable and every function parameter in a program's source code, for example String Name = "John" to declare a string variable. When the source code is compiled, the compiler attempts to detect non type-safe operations, and halts the compilation process if such an operation is found.
Θ notation
a growth rate that is both an upper and lower bound
runtime complexity
a function, T(N), that represents the number of constant time operations performed by the algorithm on an input of size N
Ω notation
a growth rate for an algorithm's lower bound
O notation
a growth rate for an algorithm's upper bound