CS 210
The longer a street is, the more vertices will be needed to represent that street.
False
The size of the stack is unlimited. True False
False
Two different algorithms that produce the same result have the same computational complexity.
False
Using a tree data structure to implement a file system requires that each directory node support a variable number of children.
False
Using the physical distance between vertices as edge weights will often suffice in contexts where the fastest route needs to be found.
False
When traversing down a BSP tree, half the objects are eliminated each level.
False
t data structure can have additional information besides the head and tail pointers. True False
False
A directory in a file system tree is always an internal node.
False A directory containing 1 or more files or directories is an internal node, but an empty directory is a leaf node.
The recursive DFS algorithm uses a queue to determine which vertices to visit.
False it uses recursive
The text "test" and "this" are likely to immediately display on the screen. cout << "test" << endl << "this\n";
False, "test" is followed by endl, so the buffer is flushed, and "test" displays. But "this\n" only outputs "this" and a newline character, so "this" is not going to appear until the buffer is flushed.
A minimum spanning tree is a set of vertices.
False, it is a set of edges
Removing at index 0 yields the best case runtime for remove-at. True False
False. Removing the element at index 0 is the worst case, because all items in the array, except the first, need to be moved down 1 position. 2)
The formula for computing a child index evaluates to -1 if the parent is a leaf node.
Falsee
what does Floyd-Warshall all-pairs shortest path algorithm do?
Graphs with cycles and negative edge weights are supported, but the graph must not have any negative cycles
When adding a new node, what is true about the order in which the ancestor height values must be updated?
Height values must be updated
When is A binary tree is complete
If all levels, except possibly the last level, contain all possible nodes and all nodes in the last level are as far left as possible.
If the current node matches the key, when does the algorithm return the node?
Immediately
Abstract Data type (ADT)
It is a data type described by predefined user operations, such as "insert data at rear," without indicating how each operation is implemented
A function template
It is a function definition having a special type parameter that may be used in place of types in the function.
What is minimum spanning tree?
It is a subset of the graph's edges that connect all vertices in the graph together with the minimum sum of edge weights. In each iteration, the edge with the lowest weight is removed from the list of edges.
Data Strucutre
It is a way of organizing, storing, and performing operations on a data.
Computational complexity
It is the amount of resources used by the algorithm. The most common resources considered are the runtime and memory usage.
Base case
It returns a value without performing a recursive call
A computational problem
It specifies an input, a question about the input that can be answered using a computer, and the desired output. PARTICIPATION
A hash function computes a bucket index from an item's _____.
Key
What aspect of linked lists makes adapting array-based sorting algorithms to linked lists difficult?
Lack of indexed access is what prevents many sorting algorithms from being easily adapted to work with linked lists.
A max-heap's root must have the maximum key. True False
True
A node in binary tree can have zero, one, or two children. True False
True
A recursive function can have two base cases, such as N == 0 returning 0, and N == 1 returning 1.
True
A recursive function with parameter N counts up from any negative number to 0. An appropriate base case would be N == 0.
True
AVLTreeInsert works to insert a node into an empty tree.
True
AVLTreeRebalance recomputes the height for the node.
True
AVLTreeSetChild has a precondition that the child's height value is correct.
True
AVLTreeUpdateHeight has a precondition that the node's children both have correct height values.
True
An AVL insert operation involves a search, an insert, and possibly some rotations. An insert operation is thus O(log(n)).
True
An algorithm with a polynomial runtime is considered efficient. True False
True
An efficient algorithm to solve an NP-complete problem may exist. True False
True
An item can be appended to an array-based list, provided the length is less than the array's allocated size.
True
BSP can be used in 3-D graphics as well as 2-D.
True
Bubble sort only swaps adjacent elements. True False
True
Conceivably, inserting 100 items into an AVL tree may not require any rotations.
True
Double hashing would never resolve collisions if the second hash function always returned 0.
True
During rebalancing, encountering nodes with balance factors of 2 or -2 implies that a rotation must occur. True False
True
For a matrix entry representing path length from A to B, when no such path exists, a special-case value must be used to indicate that no path exists.
True
For n nodes, an AVL tree has height O(log(n)).
True
If no path exists between 2 vertices in a weighted and undirected graph, then no minimum spanning tree exists for the graph.
True
If the istream data buffer currently has "21JumpStreet" and userVal is an int type, then cin >> userVal will store 21 into userVal.
True
In MaxHeapPercolateUp, the while loop's condition nodeIndex > 0 guarantees that parentIndex is >= 0.
True
In a hash table using open addressing, the load factor cannot exceed 1.0.
True
Knowledge of an ADT's underlying implementation is needed to analyze the runtime efficiency.
True
ListRemove's implementation must not allow removal of the dummy node. True False
True
ListTraverse can be used to traverse a doubly-linked list. True False
True
ListTraverseRecursive works for both singly-linked and doubly-linked lists.
True
ListTraverseReverseRecursive has been called for each of the list's nodes by the time the tail node is visited.
True
Merge sort is a fast sorting algorithm. True False
True
Neither search nor remove-at will resize the list's array. True False
True
Only 1 minimum spanning tree exists for a graph that has no duplicate edge weights.
True
Prepending a node to the list is equivalent to inserting the node after the list's dummy node.
True
Python, C++, and Java all provide built-in support for a deque ADT. True False
True
RBTreeRotateRight works even if the node's parent is null.
True
RBTreeRotateRight works even if the node's right child is null.
True
Radix sort is a fast sorting algorithm. True False
True
StackPop points a local variable to the list's head node. True False
True
Suppose a hash table has 101 buckets. If the hash table was using chaining, the load factor could be ≤ 0.1, but an individual bucket could still contain 10 items.
True
Suppose a hash table has 101 buckets. If the hash table was using open addressing, a load factor < 0.25 guarantees that no more than 25 collisions will occur during insertion.
True
The "minimum" in "minimum spanning tree" refers to the sum of edge weights.
True
The BST removal algorithm is used as part of AVL tree removal.
True
The edge with the lowest weight will always be in the minimum spanning tree.
True
The formula for computing parent node index should not be used on the root node.
True
The head and tail pointers always point to the dummy node. True False
True
The list is sorted into ascending order:(great, greater, greatest)
True
The list is sorted into descending order:(F, D, C, B, A) True False
True
The minimum spanning tree may contain all edges from the graph.
True
The node passed to AVLTreeInsert must be a leaf node.
True
The red-black tree removal algorithm uses the normal BST removal algorithm.
True
To use cout, a program must include the statement #include <iostream>
True
When sorting an array of n 3-digit integers, RadixSort's worst-case time complexity is O(n).
True
cin is a predefined istream associated with the system's standard input.
True
Minimum spanning trees can be built for directed or undirected graphs.
True1
when two vertices are considered as adjacent?
Two vertices are adjacent if connected by an edge.
If the child to be visited is null, when does the algorithm return null?
Upon exiting the loop
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
Each node in a doubly-linked list contains data and _____ pointer(s).
2
What is the minimum possible height of an AVL tree with 7 nodes? 2 3 5 7
2
What are the child indices for a node at index 6?
2 * 6 + 1 = 13 and 2 * 6 + 2 = 14
numsList: 2, 5, 9 ListRemoveAfter(numsList, node 5)
2,5
A new BST is built by inserting 255 nodes in sorted order. What is the tree height?
254
For an array with 7 nodes, how many percolate-down operations are necessary to heapify the array?
3
Given a max-heap with levels 0, 1, 2, and 3, with the last level not full, after inserting a new node, what is the maximum possible swaps needed?
3
What is the maximum possible height of an AVL tree with 7 nodes? 2 3 5 7
3
For each question, assume a list with 6 elements. 1) With a gap value of 3, how many interleaved lists will be sorted?
3 because the gap value specifies the number of interleaved lists.
Given a hash table with 100 buckets and modulo hash function, in which bucket will HashInsert(table, item 334) insert item 334?
334%100=34
Given numsList is: 5, 8, 2, 1.ListTraverse(numsList) visits _____ node(s).
4
How many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?
4
When sorting a list with 50 elements, indexSmallest will be assigned to a minimum of _____ times.
49
For an array with 10 nodes, how many percolate-down operations are necessary to heapify the array?
5
A modulo hash function for a 50 entry hash table is: key % _____
50
numsList: 3, 57, 28, 40 ListRemoveAfter(numsList, null)
57,28,40
Inserting an item at the beginning of a 999-item array requires how many items to be shifted?
999
What library should we use for access to the string stream class?
#include <sstream>
Inserting an item at the beginning of a 999-item linked list requires how many items to be shifted?
0
Which array could be heapified with the fewest number of operations, including all swaps used for percolating?
(10,10,10)
A hash table's items will be positive integers, and -1 will represent empty. A 5-bucket hash table is: -1, -1, 72, 93, -1. How many items are in the table?
2
What are the first 2 elements swapped?
12, and 15
If a graph has 11 vertices and 7 edges, how many entries are in the all-pairs-shortest-path matrix?
121
Insertion operator (<<)
<< operator is used for converting different types of data into a sequence of charachters. The << operator is overloaded with functions to support the various data types such as int, bool, float
Bag
A bag is an ADT for storing items in which the order does not matter and duplicate items are allowed.
Binary tree
A binary tree is a data structure in which each node stores data and has up to two children, known as a left child and a right child.
When is a binary tree full?
A binary tree is full if every node contains 0 or 2 children.
When is a binary tree perfect?
A binary tree is perfect, if all internal nodes have 2 children and all leaf nodes are at the same level.
What is breadth-first search (BFS)?
A breadth-first search (BFS) is a traversal that visits a starting vertex, then all vertices of distance 1 from that vertex, then of distance 2, and so on, without revisiting a vertex.
The head and tail pointers always point to the dummy node. True False
False
what is a cycle?
A cycle is path that starts and ends at the same vertex. A directed graph is cyclic if the graph contains a cycle, and acyclic if the graph does not contain a cycle.
Deque
A deque (pronounced "deck" and short for double-ended queue) is an ADT in which items can be inserted and removed at both the front and back.
Dictionary (Map)
A dictionary is an ADT that associates (or maps) keys with values.
What is digraph or directed graph?
A directed graph, or digraph, consists of vertices connected by directed edges.
Dynamic array
A dynamic array is an ADT for holding ordered data and allowing indexed access.
comparison sort
A element comparison sorting algorithm is 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 are all comparison sorting algorithms. Radix sort, in contrast, is not a comparison sorting algorithm and requires array elements to be numbers.
A gap value
A gap value is a positive integer representing the distance between elements in an interleaved list
what is a graph?
A graph is a data structure for representing connections among items, and consists of vertices connected by edges.
Hash table
A hash table is a data structure that stores unordered items by mapping (or hashing) each item to a location in an array.
Queue
A queue is an ADT in which items are inserted at the end of the queue and removed from the front of the queue.
queue
A queue is an ADT in which items are inserted at the end of the queue and removed from the front of the queue. The queue push operation inserts an item at the end of the queue. The queue pop operation removes and returns the item at the front of the queue.
Record
A record is the data structure that stores subitems, with a name associated with each subitem.
N factorial (N!) is commonly implemented as a recursive function due to being easier to understand and executing faster than a loop implementation.
False
The length of an array-based list equals the list's array allocation size. True False
False
Time complexity of adjacency lists
A key advantage of an adjacency list graph representation is a size of O(V + E), because each vertex appears once, and each edge appears twice. However, a disadvantage is that determining whether two vertices are adjacent is O(V), because one vertex's adjacency list must be traversed looking for the other vertex, and that list could have V items
List
A list is an ADT for holding ordered data.
What does GraphTopologicalSort return?
A list of vertices
positional list
A list where elements contain pointers to the next and/or previous elements in the list.
what is a manipulator?
A manipulator is a function that overloads the insertion operator << or extraction operator >> to adjust the way output appears. Manipulators are defined in the iomanip and ios libraries in namespace std.
Heap
A max-heap 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-heap is a tree that maintains the simple property that a node's key is less than or equal to the node's childrens' keys.
what is a negative cycle ?
A negative cycle is a cycle with edge weights that sum to a negative value. The Floyd-Warshall algorithm initializes the shortest path lengths matrix in 3 steps. 1) Every entry is assigned with infinity. 2_Each entry representing the path from a vertex to itself is assigned with 0. 3) For each edge from X to Y in the graph, the matrix entry for the path from X to Y is initialized with the edge's weight.
When would inserting a new node to an AVL tree result in no height value changes for all ancestors?
A new node is inserted as a child of an internal node with 1 child
What is Parent?
A node with a child is said to be that child's parent. A node's ancestors include the node's parent, the parent's parent, etc., up to the tree's root.
dummy node (or header node):
A node with an unused data member that always resides at the head of the list and cannot be removed. Using a dummy node simplifies the algorithms for a linked list because the head and tail pointers are never null.
What is an Internal node?
A node with at least one child
What is a path?
A path is a sequence of directed edges leading from a source (starting) vertex to a destination (ending) vertex.
what is a path?
A path is a sequence of edges leading from a source (starting) vertex to a destination (ending) vertex. The path length is the number of edges in the path.
A perfect hash function
A perfect hash function maps items to buckets with no collisions
Priority queue
A priority queue is 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.
Navigation software would have no need to place a vertex on a road in a location where the road does not intersect any other roads.
False
Set
A set is an ADT for a collection of distinct items.
A stack
A stack is an ADT in which items are only inserted on or removed from the top of a stack
Stack
A stack is an ADT in which items are only inserted on or removed from the top of a stack.
What is a leaf?
A tree node with no children.
what is a vertex?
A vertex (or node) represents an item in a graph.
Only a doubly-linked list can be circular. True False
False
RBTreeRotateRight works even if the node's left child is null.
False
RadixSort can be used to sort an array of strings.
False
RadixSort has a space complexity of O(1).
False
Removal of an internal node with 2 children always requires a rotation to rebalance
False
What is the heapified array?
After performing the percolate down operation on internal nodes 12, 21, and 11, the resulting array is (21, 19, 15, 13, 11, 12).
Removing a red node with RBTreeRemoveNode will never cause RBTreePrepareForRemoval to be called.
False
recursive algorithm
An algorithm that is defined by repeated applications of the same algorithm on smaller problems is a recursive algorithm
array-based list
An array-based list supports the common list ADT operations, such as append, prepend, insert after, remove, and search.
what is an edge?
An edge represents a connection between two vertices in a graph.
The edges from any minimum spanning tree can be used to create a path that goes through all vertices in the graph without ever encountering the same vertex twice.
False
Dijkstra's shortest path algorithm
Dijkstra's algorithm initializes all vertices' distances to infinity (∞), initializes all vertices' predecessors to 0, and pushes all vertices to a queue of unvisited vertices.
Should negative edge weight be used?
Djikstra's algorithem = No
How does stack frame work?
Each function call places a new stack frame on the stack, for local parameters, local variables, and more function items. Upon return, the frame is deleted.
What are the last 2 elements swapped?
Element 11 is less than both 13 and 19, and is swapped with the larger of the 2 children.
What is Binary space partitioning (BSP)?
Binary space partitioning (BSP) is a technique of repeatedly separating a region of space into 2 parts and cataloging objects contained within the regions
The formula for computing child node indices does not work on the root node.
False
A fast sorting algorithm's worst case runtime complexity must be O(NlogN) or better.
False
A file in a file system tree is always a leaf node.
False
A hash table implementation must use only one criteria for resizing. True False
False
A hash value can be used to reconstruct the original data. True False
False
A linked list must have a list data structure. True False
False
A linked list stores items in an unspecified order. True False
False
A list ADT's underlying data structure has no impact on the program's execution.
False
A list node's data can store a record with multiple subitems. True False
False
A memory's stack region can store at most one stack frame. True False
False
A rotation at a node will only change properties of the node's descendants, but will never change properties of the node's ancestors.
False
A rotation will never change the root node's value.
False
ADTs are only supported in standard libraries. True False
False
AVLTreeGetBalance has a precondition that the node's children are both non-null.
False
AVLTreeInsert sets the height in the newly inserted node to 0 and the node's left and right child pointers to null.
False
AVLTreeInsert updates heights on all ancestors before inserting the node.
False
AVLTreeRebalance rebalances all ancestors from the node up to the root.
False
AVLTreeRebalance recomputes the height values for each non-null child.
False
After inserting a node into a tree, all tree nodes must have their balance factors updated.
False
After removing a node from an AVL tree using the standard BST removal algorithm, all nodes in the tree must be rebalanced.
False
An AVL tree maintains the minimum possible height.
False
An array sorted in ascending order is already a valid max-heap.
False
An array-based list can have a default allocation size of 0. True False
False
An efficient algorithm exists for all computational problems. True False
False
Bubble sort uses a single loop to sort the list. True False
False
Calling Heapsort on an array with 1 element will cause an out of bounds array access.
False
Characters written to cout are immediately written to a system's standard output?
False
Consider integers X and Y, such that X < Y. X will always be in a lower bucket than Y.
False
Creating an independent class that has similar members to an existing class requires copying and pasting code from one class to another.
False
For n nodes, an AVL tree has height equal to floor(log(n)).
False
GraphTopologicalSort will not work on a graph with a positive number of vertices but no edges.
False
Heapsort uses recursion.
False
If a graph contains a negative edge weight, the matrix of shortest path lengths will contain at least 1 negative value
False
If a list ADT has operations like Sort or PrintReverse, the list is clearly implemented using an array.
False
If an AVL tree has X levels, the first X-1 levels will be full.
False
If computer B in the above example computed a hash value identical to the downloaded hash value, then the downloaded message would be guaranteed to be uncorrupted.
False
If navigation software uses GPS to automatically determine the start location for a route, the vertex closest to the GPS coordinates can be used as the starting vertex.
False
If the istream data buffer currently has "Hey" and myChar is a char type, then cin >> myChar will store "Hey" into myChar.
False
Insertion sort is a fast sorting algorithm. True False
False
Integers will be placed into buckets based on the 1's digit. More buckets are needed for an array with one thousand integers than for an array with one hundred integers.
False
ListTraverseReverse can be used to traverse a singly-linked list. True False
False
MD5 produces larger hash values for larger input data sizes. True False
False
MaxHeapPercolateDown checks the node's left child first, and immediately swaps the nodes if the left child has a greater key.
False
The function should remove a few spaces from the indent parameter before returning
False
Differences between overloading and overriding?
In overloading, functions with the same name must have different parameter types. In overriding, a derived class member function takes precedence over a base class member function with the same name, regardless of the parameter types. Overloading is not performed if derived and base member functions have different parameter types; the member function of the derived class hides the member function of the base class.
InsertAfter(list, w, x)
Inserts x after w
Append(list, x)
Inserts x at end of list
Prepend(list, x)
Inserts x at start of list
what is a connected graph?
It contains a path between every pair of vertices.
How does insertion operator work?
It converts the string literal to charachters, temporarly storing characters in an output buffer.
An algorithm
It describes a sequence of steps to solve a computational problem or perform a calculation. An algorithm can be described in English, pseudocode, a programming language, hardware, etc
Binary search tree (BST)
It has an ordering property that any node's left subtree keys ≤ the node's key, and the right subtree's keys ≥ the node's key.
The Bellman-Ford algorithm
It initializes all vertices' current distances to infinity (∞) and predecessors to 0, and assigns the start vertex with a distance of 0. The algorithm performs V-1 main iterations, visiting all vertices in the graph during each iteration.
What is Ostream
It is a class that supports output and is available via #include <iostream> and in namespace std.
What is a directed edge?
It is a connection between a starting vertex and a terminating vertex. (one way connection)
What is Root?
The one tree node with no parent (the "top" node).
For the operation QueuePop(queue), poppedItem contains a pointer to the _____.
List head
Which sorting algorithm uses a gap value to jump between elements, and is difficult to adapt to linked lists for this reason?
Merge sort
Merge sort
Merge sort is 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
How much is the maximum N-node binary tree height?
N-1 because the root is at height 0
Hash function: key % 1000 Key: Customer's 3-digit U.S. phone number area code, of which about 300 exist. Hash table size: 1000
No
Hash function: key % 40 Key: 4-digit even numbers Hash table size: 40
No
Is there a difference in how we define the parameters of a recursive versus non-recursive function? Answer yes or no.
No
The BFS traversal of a graph is unique. Type: Yes or No
No
Will the hash function and expected key likely work well for the following scenarios? 1)Hash function: key % 1000 Key: 6-digit employee ID Hash table size: 20000
No
What relationship does a node's height have to the node's balance factor?
No relationship. Only the height of the node's children determine the node's balance factor.
<< is known as the stream operator.
No, it is known as insertion operator
A read from cin will directly read characters from the system's keyboard.
No. The system first automatically puts the standard input into a data buffer associated with cin, so reading from cin actually reads from that buffer, not directly from the keyboard.
After calling RBTreeRotateLeft at this node, the node will have a null left child.
Node with null left child
RBTreeRotateLeft will not work when called at this type of node.
Node with null right child
Assume the stack is implemented using a linked list. 1) An empty stack is indicated by a list head pointer value of _____.
Null
For a well-designed hash table, searching requires _____ on average.
O(1)
Kruskal's minimum spanning tree algorithm's time complexity
O(ElogE) or O(ElogV).
wat is Dijkstra's shortest path algorithm time complexity?
O(ElogV)
Quicksort runtime
O(N log N).
Resize operation has runtime of
O(N)
The average and worst case runtime ListInsertionSortSinglyLinked
O(N2). The best case runtime is O(N), which occurs when the list is sorted in descending order.
Selection sort algorithm runtime
O(N^2)
nested loop runtime
O(N^2)
Insertion sort runtime
O(N^2) For sorted or nearly sorted inputs, insertion sort's runtime is O(N)
runtime complexity of fast sorting algorithm
O(NlogN)
time complexity for GraphTopologicalSort
O(V+E)
what is Bellman-Ford algorithm shortest path algorithm time complexity
O(VE)
AVL removal algorithm complexity
O(log N)
Time complexity of AVLTreeInsert
O(log N)
Floyd-Warshall algorithm time complexity
O(n^3)
Given a max-heap with N nodes, what is the complexity for removing the root?
O⌊logN⌋
Given a max-heap with N nodes, what is the worst-case complexity of an insert, assuming an insert is dominated by the swaps?
O⌊logN⌋
Access specifiers
Private: Accessible by self Protected: Accessible by self and derived classes. public: Accessible by self, derived classes, and everyone else.
Unified Modeling Language (UML)
Programmers commonly draw class inheritance relationships using Unified Modeling Language (UML) notation
Which fast sorting algorithm's worst case runtime complexity is worse than O(NlogN)?
Quicksort
Radix sort
Radix sort is a sorting algorithm designed specifically for integers
Radix sort
Radix sort is a sorting algorithm specifically for an array of integers:
RBTreeRotateLeft called at this node requires the tree's root pointer to be updated.
Root
Re-computation of the sibling node after case RBTreeTryCase2, RBTreeTryCase5, or RBTreeTryCase6 implies that these functions may be doing what?
Rotating at the node's parent or the node's sibiling
A virtual function
Runtime polymorphism only works when an overridden member function in a base class is virtual. A virtual function is a member function that may be overridden in a derived class and is used for runtime polymorphism.
What is distance?
The distance between two vertices is the number of edges on the shortest path between those vertices.
what does fail() do?
The fail() function returns true if the previous stream operation had an error.
How many times will MaxHeapPercolateDown be called by Heapsort when sorting an array with 10 elements?
The first loop iterates for i = 4, 3, 2, 1, and 0, and the second loop iterates for i = 9, 8, 7, 6, 5, 4, 3, 2, and 1. MaxHeapPercolateDown is called once for each loop iteration, making 5 + 9, or 14, calls total.
Which of the following is NOT a requirement of the graph for topological sorting?
That the graph does not have to be weighted
Binary search tree (BST) time complexity
The average case time complexity will be O(log n) and the worst case would be O(n). To understand the O(log n)
Removing a node from an N-node nearly-fullBST has what computational complexity?
The computation is dominated by searching for the node, which is O(logN). The actual removal is just a few pointer updates.
ListTraverse begins with _____.
The list's head node
Suppose the original array to be heapified is (11, 21, 12, 13, 19, 15). 1) The percolate down operation must be performed on which nodes?
The percolate down operation is performed on internal nodes only. Nodes 12, 21, and 11 are the heap's internal nodes.
What is the maximum loop iterations for a perfect binary tree with 7 nodes, if a node matches?
The tree has 3 levels. The worst case is that the matching node is a leaf. Iteration 1 checks the first level, 2 the second, 3 the third (and returns).
percolating.
The upward movement of a node in a max-heap is sometime called percolating.
>> is known as the extraction operator.
True
A BSP implementation could choose to split regions in arbitrary locations, instead of right down the middle.
True
A customer with a higher priority has a lower numerical value in the min heap.
True
Polymorphism
There are two types of polymorphism: Compile-time polymorphism is when the compiler determines which function to call at compile-time. e.x) function overloading Runtime polymorphism is when the compiler is unable to determine which function to call at compile-time, so the determination is made while the program is running.
A linked list has O(n) space complexity, whether a list data structure is used or not.
True
override
When a derived class defines a member function that has the same name, parameters, and return type as a base class's function , the member function is said to override the base class's function.
Under what circumstance will RBTreeAreBothChildrenBlack always return true?
When both of the children are null
The DFS traversal of a graph is unique. Type: Yes or No
Yes
Will the hash function and expected key likely work well for the following scenarios? Hash function: key % 250 Key: 5-digit customer ID Hash table size: 250
Yes
The tree has an internal node, Gupta, with only one child rather than two. Is the tree still a binary tree? Type yes or no.
Yes, In a binary tree, each node has up to two children. So the tree is still a binary tree.
Consider the problem of determining the number of times (or frequency) a specific word appears in a list of words. Which can be used as the problem input?
a list of all words and the specific word for which determining the frequency is desired.
A 100 element hash table has 100 _____
buckets
The pivot
can be any value within the array being sorted, commonly the value of the middle array element
what is cin?
cin is a predefined istream pre-associated with a system's standard input. The >> operator skips leading zeros and whitespaces
How to declare a derived class?
class DerivedClass: public BaseClass { ... };
what does all pairs shortest path algorithm do?
determines the shortest path between all possible pairs of vertices in a graph. Each row corresponds to a start vertex, and each column in the matrix corresponds to a terminating vertex for each path
Bellman-Ford algorithm negative weight
does not wok with negative weight
If the head pointer is null, the queue _____.
empty
What does eof() do?
eof() or end of file that returns true or false depending on whether or not the end of the stream has been reached
AVLTreeInsert adds the new node as a child to an existing node in the tree, but the new node's parent pointer is not set and must be handled outside of the function.
false
If the istream data buffer currently has "friend!" and secondString is a string variable, then cin >> secondString will store "friend" into secondString.
false
Path reconstruction is not possible if the graph has a cycle
false
Recursive functions can be accomplished in one step, namely repeated calls to itself.
false
The worst-case time complexity for BSTGetHeight is O(log N), where N is the number of nodes in the tree.
false
When a hash table is initialized, all entries must be empty-after-removal.
false, All entries must be initialized to empty-since-start.
What is the parent index for a node at index 12?
floor((12 - 1) / 2) = floor(5.5) = 5
Which function is used to read an entire string from user input?
getline()
linear probing
handles a collision by starting at the key's mapped bucket, and then linearly searches subsequent buckets until an empty bucket is found.
When is a BST is height balanced?
if for any node, the heights of the node's left and right subtrees differ by only 0 or 1. If any node's subtree heights differ by 2 or more, the entire tree is not an AVL tree.
The Fibonacci sequence
is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, etc.; starting with 0, 1, the pattern is to compute the next number by adding the previous two numbers.
What is an AVL tree?
is a BST with a height balance property and specific operations to rebalance the tree when a node is inserted or removed
A singly-linked list
is a data structure for implementing a list ADT, where each node has data and a pointer to the next node.
A doubly-linked list
is a data structure for implementing a list ADT, where each node has data, a pointer to the next node, and a pointer to the previous node.
A hash table
is a data structure that stores unordered items by mapping (or hashing) each item to a location in an array (or vector).
Selection sort
is 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.
A pure virtual function
is a virtual function that provides no definition in the base class
When is an algorithm's best case?
is the scenario where the algorithm does the minimum possible number of operations
Declare an istringstream variable named inSS that creates an input string stream using the string variable myStrLine.
istringstream inSS(myStrLine);
what is cout?
it is a predefined ostream object declared as osream cout; that is pre associated with a system's standard output
A deque
items can be inserted and removed at both the front and back. The deque push-front operation inserts an item at the front of the deque, and the push-back operation inserts at the back of the deque.The pop-front operation removes and returns the item at the front of the deque, and the pop-back operation removes and returns the item at the back of the deque
If 2,000 customers are waiting for technical support, removing a customer from the min heap requires about 2,000 operations.
log(2000) = 11
When does stack overflow happen?
meaning a stack frame extends beyond the memory region allocated for stack, Stack overflow usually causes the program to crash and report an error like: segmentation fault, access violation, or bad access. The size of parameters and local variables results in a larger stack frame. Large vectors, arrays, or strings declared as local variables, or passed by copy, can lead to faster stack overflow.
Which operation should usually be preceded by a check that the stack is not empty?
pop
A priority queue implementation that requires objects to have a data member storing priority would implement the _____ function.
push
)A priority queue implementation that does not require objects to have a data member storing priority would implement the _____ function.
push with priority
Why is no preparation action required if the node is red?
removing a red node will not change the number of black nodes along the way
What does setprecision() , fixed, scientific, and showpoint , setfill(c), setw(n), endl manipulator do?
setprecision() = If stream has not been manipulated to fixed or scientific:Sets max number of digits in number. If stream has been manipulated to fixed or scientific:Sets max number of digits in fraction only (after the decimal point).From <iomanip> fixed = Use fixed-point notation.From <ios> manipulate decimal numbers. scientific = Use scientific notation.From <ios> showpoint = Even if fraction is 0, show decimal point and trailing 0s.Opposite is noshowpoint.From <ios> setfill(c) manipulator = Sets the fill to character c.From <iomanip> setw(n)= Sets the number of characters for the next output item only(does not persist, in contrast to other manipulators).By default, the item will be right-aligned, and filled with spaces.From <iomanip> endl = Inserts a newline character '\n' into the output bufferand informs the system to flush the buffer.From <iostream> flush = Informs the system to flush the buffer.From <iostream>
What is an istream?
short for "input stream," is a class that supports input. Available via #include <iostream>, istream provides the >> operator, known as the extraction operator, to extract data from a data buffer and write the data into different types of variables.
Why are sorting algorithms for arrays generally more difficult to adapt to singly-linked lists than to doubly-linked lists?
singly-linked lists does not support backward traversal
Which is not an advantage of storing password hash values, instead of actual passwords, in a database?
storage space is not saved when storing hash values.
Which function copies the input string into the string stream?
str()
How to declare a template function?
template<typename MyType>
How to declare a class template?
template<typename TheType> class TripleItem {}
RBTreePrepareForRemoval performs the check node⇢parent == null on the first line. What other check is equivalent and could be used in place of the code node⇢parent == null?
tree->root = node
AVLTreeRebalance takes no action if a node's balance factor is 1, 0, or -1.
true
Although RBTreeRemoveNode uses the node's predecessor, the algorithm could also use the successor.v
true
BSTGetHeight would also work if the recursive call on the right child was made before the recursive call on the left child.
true
Each recursive call should add a few spaces to the indent parameter. True False
true
Heapsort's worst-case runtime is O(N log N).
true
In the animation, if the parts of the screen were in 2 different regions, then all objects from the 2 regions would have to be analyzed when rendering.
true
MaxHeapPercolateDown has a precondition that nodeIndex is < arraySize.
true
MaxHeapPercolateUp works for a node index of 0.
true
How to declare a pure virtual function?
virtual string GetHours() const = 0;
Given N nodes, what is the height of a max-heap?
⌊logN⌋