Data Structures & Algorithms Midterm Vocab/Textbook Questions (CSCI 2082)
Runtime and memory usage are the only two resources making up computational complexity
False
T/F - ADTs are only supported in standard libraries
False
T/F - An algorithm's best and worst case scenarios are always different
False
T/F - Computational complexity analysis allows the efficiency of algorithms to be compared
True
Space complexity
a function S(N) that represents the number of fixed-size memory units used by the algorithm for an input of size N.
Queue
an ADT in which items are inserted at the end of the queue and removed from the front of the queue
Given list: (20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11). How many list elements will be checked if the search key is not found using linear search?
11
Given list: ( 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ). Given an array with 32 elements, how many list elements will be checked if the key is less than all elements in the left, using binary search?
5
Starting with an empty list, what is the list contents after the following operations? Append(list, 11) Append(list, 4) Append(list 7) A. 4,7,11 B. 7,4,11 C. 11,4,7
C. 11,4,7
A remove operation for a list ADT will remove the specified item. Given a list with contents: 2, 20, 30, what is the list contents after the following operation? Remove(list, item 2) A. 2, 30 B. 2, 20, 30 C. 20, 30
C. 20, 30
Determine the ADT with the description: Items are ordered based on how items are added. Duplicate items are allowed.
List
What is the common algorithm to the following computational problem that can be solved using that algorithm. Do two students essays share a common phrase consisting of a sequence of more than 100 letters?
Longest common substring
Suppose a sorted list of 1024 elements is searched with binary search. How many distinct list elements are compared against a search key that is less than all elements in the list?
10
T/F - Items stored in an array can be accessed using a positional index.
True
T/F - Python, C++, and Java all provide built-in support for deque ADT
True
Computational Complexity
the amount of resources used by an algorithm. The most common resources are runtime and memory usage
Asymptotic notation
the classification of runtime complexity that uses functions that indicate only the growth rate of the bounding function.
Auxiliary space complexity
the space complexity not including the input data
Runtime
the time the algorithm takes to execute
Given list: (20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11). How many list elements will be compared to find 77 using linear search?
9
Inserting an item at the beginning of a 999-item array requires how many items to be shifted?
999
Upper bound
A function f(N) that is greater than or equal to the worst case T(N) for all values of N greater than or equal to 1
Lower bound
A function f(N) that is less than or equal to the best case T(N) for all values of N greater than or equal to 1
Computational problem
A question about the input that can be answered using a computer, and the desired output
Suppose an algorithm's best case runtime complexity is T(N) = 3N + 6, and the algorithm's worst case runtime is T(N) = 5N^2 + 7N. Which function is an upper bound for the algorithm? A. 12N^2 B. 5N^2 C. 7N
A. 12N^2
Determine the ADT with the description: Items are not ordered. Duplicate items are allowed.
Bag
What is the common algorithm to the following computational problem that can be solved using that algorithm. Given a sorted list of a company's employee records and an employee's first and last name, what is a specific employee's phone number?
Binary search
Suppose an algorithm's best case runtime complexity is T(N) = 3N + 6, and the algorithm's worst case runtime is T(N) = 5N^2 + 7N. Which function is a lower bound for the algorithm? A. 5N^2 B. 5N C. 3N
C. 3N
Consider the problem of determining the number of times a specific word appears in a list of words. Which can be used as the problem input? A. String for user-specified word B. Array of unique words and string for user-specified C. Array of all words and string for user-specified word
C. Array of all words and string for user-specified word
Consider the problem of determining the number of times a specific word appears in a list of words. What is the problem output? A. Integer value for the frequency of most frequent word B. String value for the most frequent word in input array C. Integer value for the frequency of specified word
C. Integer value for the frequency of specified word
Given list: ( 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ). How many list elements will be checked to find the value 77 using binary search?
2
Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the fastest possible runtime for linear search?
2 µs
Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the longest possible runtime for linear search?
20,000 µs
Given list: ( 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ). How many list elements will be checked to find the value 17 using binary search?
3
Given list: (20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11). How many list elements will be checked to find the value of 114 using linear search?
3
Consider the array and linked list in the animation above. Can the following algorithms be implemented with the same code for both an array and linked list? Y/N - Append an item
No
Consider the array and linked list in the animation above. Can the following algorithms be implemented with the same code for both an array and linked list? Y/N - Return the first item
No
What is the common algorithm to the following computational problem that can be solved using that algorithm. Given the airports at which an airline operates and distances between those airports, which is the shortest total flight distance between two airports?
Shortest path algorithm
Consider the array and linked list in the animation above. Can the following algorithms be implemented with the same code for both an array and linked list? Y/N - Return the current size
True
Suppose T(N) = 2N^2 + N + 9 T/F - T(N) = O(N^2)
True
Suppose T(N) = 2N^2 + N + 9 T/F - T(N) = Ω(N^2)
True
Suppose T(N) = 2N^2 + N + 9 T/F - T(N) = θ(N^2)
True
Suppose an algorithm's best case runtime complexity is T(N) = 3N + 6, and the algorithm's worst case runtime is T(N) = 5N^2 + 7N. T/F - 3N + 6 is a lower bound for the algorithm
True
Suppose an algorithm's best case runtime complexity is T(N) = 3N + 6, and the algorithm's worst case runtime is T(N) = 5N^2 + 7N. T/F - 5N^2 + 7N is an upper bound for the algorithm
True
T/F - A list node's data can store a record with multiple subitems.
True
T/F - A node in binary tree can have zero, one, or two children.
True
T/F - An algorithm with a polynomial runtime is considered efficient
True
T/F - An efficient algorithm to solve an NP-complete problem may exist.
True
T/F - Certain hardware may execute division more slowly than multiplication, but both may still be constant time operations.
True
T/F - In the code below, suppose str1 is a pointer or reference to a string. The code only executes in constant time if the assignment copies the pointer/reference, and not all the characters in the string. str2 = str1
True
T/F - The 3 constant time operations in the code below can collectively be considered 1 constant time operation x = 26.5 y = 15.5 z = x + y
True
T/F - The statement below that assigns x with y is a constant time operation. x = 10 x = y
True
Priority Queue
a queue where each items has a priority, and items with higher priority are closer to the front of the queue than items with lower priority
Best case
a scenario where the algorithm does the minimum possible number of operations
Worst case
a scenario where the algorithms does the maximum possible number of operations
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
Algorithm
a sequence of steps to solve a computational problem or perform a calculation. Can be described in English, pseudocode, a programming language, hardware, etc.
NP-complete problems
a set of problems for which no known efficient algorithm exists
Data Structure
a way of organizing, storing, and performing operations on data
Inserting an item at the beginning of a 999-item linked list requires how many items to be shifted?
0
Inserting an item at the end of a 999-item array requires how many items to be shifted?
0
Inserting an item at the end of a 999-item linked list requires how many items to be shifted?
0
Suppose T(N) = 2N^2 + N + 9 T(N) = O(N^3)
True
Algorithm Efficiency
a measurement of an algorithm's computational complexity
Determine the ADT with the description: Items are not ordered. Duplicate items are not allowed
Set
Suppose a list of 1024 elements is searched with linear search. How many distinct list elements are compared against a search key that is less than all elements in the list?
1024
Consider the problem of determining the number of times a specific word appears in a list of words. T/F - An algorithm to solve this computation problem must be written using a programming language
False
Suppose T(N) = 2N^2 + N + 9 T(N) = Ω(N^3)
False
T/F - A linked list stores items in an unspecified order.
False
T/F - A list ADT's underlying data structure has no impact on the program's execution.
False
T/F - A loop is never a constant time operation
False
T/F - A programmer must know the underlying implementation of the list ADT in order to use a list.
False
T/F - An efficient algorithm exists for all computational problems
False
T/F - Nearly every algorithm has a best case time complexity when N = 0
False
T/F - The hardware running the code is the only thing that affects what is and what is not a constant time operation
False
T/F - The underlying data structure for a list data structure is the same for all programming languages
False
T/F - Two different algorithms that produce the same result have the same computational complexity
False
Determine the ADT with the description: Items are ordered based on items' priority. Duplicate items are allowed
Priority queue
Max-heap
a binary tree that maintains the simple property that a node's key is greater than or equal to the node's childrens' keys.
Min-heap
a binary tree that maintains the simple property that a node's key is less than or equal to the node's childrens' keys.
Graph
a data structure for representing connections among items, and consists of vertices connected by edges. A vertex represents an item in a graph. An edge represents a connection between two vertices in a graph
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
Linked List
a data structure that stores an ordered list of items in nodes, where each node stores data and has a pointer to the next node
Array
a data structure that stores an ordered list of items, where each item is directly accessible by a positional index
Record
a data structure that stores subitems, often called fields, with a name associated with each subitem
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
Binary search
a faster algorithm for searching a list if the list's elements are sorted and directly accessible. Search first checks the middle element of the list. If key is not found, the algorithm repeats the search on the remaining left sublist or the remaining right sublist
Runtime complexity
a function T(N) that represents the number of constant time operations performed by the algorithm on an input of size N
Set
an ADT for a collection of distinct items (binary search tree, hash table)
Dynamic Array
an ADT for holding ordered data and allowing indexed access (array)
List
an ADT for holding ordered data structures. (array, linked list)
Bag
an ADT for storing items in which the order does not matter and duplicate items are allowed (array, linked list)
Stack
an ADT in which items are only inserted on or removed from the top of a stack (linked list)
Deque
an ADT in which items can be inserted and removed at both front and back (linked list)
Dictionary
an ADT that associates (or maps) keys with values
Ω notation
an asymptotic notation that provides a growth rate for an algorithm's lower bound
O notation
an asymptotic notation that provides a growth rate for an algorithm's upper bound
θ notation
an asymptotic notation that provides a growth rate that is both an upper and lower bound
Constant Time Operation
an operation that, for a given processor, always operates in the same amount of time regardless of input values