Data Structure Final
B.) either vertexA, vertex B, or vertex E
A DFS traversal starting from vertex C will visit _____ last. A.) vertex C B.) either vertexA, vertex B, or vertex E C.) vertex A D.) either vertex A or vertex D
Connected
Assume you have a graph where every node has a path to every other node in the graph. What is the word used to describe this type of graph?
B.) False
Assume you have an iterative vs a recursive solution to a problem and you are wanting to implement the solution in C++. The recursive solution, in most cases, will be the most efficient in terms of execution time. A.) True B.) False
C.) vector<set<string>>
Assume you want to create a vector of sets of string for the application you are working on. In other words, you want each vector element to be a set of strings. Which of the following would be the correct type declaration. A.) vector<set, string> B.) set<vector<string>> C.) vector<set<string>> D.) set<vector, string>
B.) False
Assume you write the following recursive function to sum the integers from 1 to n, where n is an input from the user and is the first value passed to the recursive function sum1toN. Review the function and answer true if the function will work correctly or answer false if it will not. (you may always assume that n >= 1) int sum1toN (int n) { if (n == 1) return n; else return n + sum1toN(n + 1); } A.) True B.) False
A.) patientName.emplace("Julia", 32);
Given [map<string, int> patientName;] which statement will add a mapping for a patient named Julia of age 32? A.) patientName.emplace("Julia", 32); B.) patientName.at("Julia", 32); C.) patientName.insert("Julia", 32); D.) patientName.erase("Julia", 32);
17
Given a balanced BST that has 100,000 nodes, approximately how many accesses in the worst case will it take to locate an item?
A.) True
Given the BST below, The correct pre-order traversal would be: 41 20 11 29 32 65 50 91 72 99 A.) True B.) False
A.) True
Given the BST diagram below, the correct post-order traversal of the tree is: 5 4 7 6 50 71 23 15 A.) True B.) False
Yes
Given the adjacency matrix below, does a path between the source G and the destination B exist?
D.) Pam
Given the doubly-linked list students (Tom, Sam), what will be the second node in the list after the following operations? ListInsertAfter(students, list⇢tail, node Hal) ListInsertAfter(students, list⇢head, node Pam) A.) Sam B.) Hal C.) Tom D.) Pam
A.) if (N == 0)
Given the following code for generating the Fibonacci series for N numbers, which XXX would replace the missing statement? A.) if (N == 0) B.) if (N < 0) C.) if (N > 0) D.) if (N != 0)
A.) null
Given the following doubly-linked list, what is node Hal's previous pointer value after ListPrepend(students, node Hal) is executed? A.) null B.) the head C.) node Hal D.) node Tom
B.) Node Tim's next pointer
Given the following queue, which pointer points to the new item when the operation QueueEnqueue(studentsQueue, "Hal") is executed? A.) The studentsQueue head pointer B.) Node Tim's next pointer C.) Node Tom's next pointer D.) The null pointer
C.) Take one step left and then go as far right as possible
How do you locate the closest predecessor value to a given value in a BST? A.) Go as far right as possible from the given node B.) Take one step right and then go as far left as possible C.) Take one step left and then go as far right as possible D.) Go as far left as possible from the given node
A.) 3
How many different paths from A to F take 15 minutes? A.) 3 B.) 2 C.) 1 D.) 4
A.) B, A, D, E, C
Identify the DFS traversal of the graph if the starting vertex is B. A.) B, A, D, E, C B.) B, D, C, E, A C.) B, E, A, C, D D.) B, C, E, A, D
B.) ListTraverseReverse(students) { curNode = students⇢tail while (curNode is not null) { Print curNode's data curNode = curNode⇢prev } }
Identify the correct algorithm for reverse traversal in the doubly-linked list studentList. A.) ListTraverseReverse(students) { curNode = students⇢head while (curNode is not null) { Print curNode's data curNode = curNode⇢next } } B.) ListTraverseReverse(students) { curNode = students⇢tail while (curNode is not null) { Print curNode's data curNode = curNode⇢prev } } C.) ListTraverseReverse(students) { curNode = students⇢head while (curNode is null) { Print curNode's data curNode = curNode⇢prev } } D.) ListTraverseReverse(students) { curNode = students⇢tail while (curNode is not null) { Print curNode's data curNode = curNode⇢next } }
B.)
Identify the correct algorithm for reverse traversal in the doubly-linked list studentList. A.) ListTraverseReverse(students) { curNode = students⇢head while (curNode is not null) { Print curNode's data curNode = curNode⇢next } } B.) ListTraverseReverse(students) { curNode = students⇢tail while (curNode is not null) { Print curNode's data curNode = curNode⇢prev } } C.) ListTraverseReverse(students) { curNode = students⇢head while (curNode is null) { Print curNode's data curNode = curNode⇢prev } } D.) ListTraverseReverse(students) { curNode = students⇢tail while (curNode is not null) { Print curNode's data curNode = curNode⇢next } }
D.) The statement [curNode = list⇢head⇢next] should be [curNode = curNode⇢next].
Identify the error in the following algorithm for traversing a linked list. A.) The statement [while (curNode is not null)] should be [while (curNode is null)]. B.) The statement [curNode = list⇢head] should be [curNode = list⇢tail]. C.) The statement [while (curNode is not null)] should be [while (list⇢tail is not null)]. D.) The statement [curNode = list⇢head⇢next] should be [curNode = curNode⇢next].
D.) The while condition should be [while (curNode is not null)].
Identify the error in the following algorithm to search for a node in the singly-linked list of students. A.) The statement [curNode = curNode⇢next] should be [curNode = students⇢head]. B.) The statement [curNode = students⇢head] should be [curNode = students⇢tail]. C.) The if condition should be [if (curNode⇢data != key)]. D.) The while condition should be [while (curNode is not null)].
A.) 3
Identify the number of elements in a set formed by adding the following: element 10, 4 times element 15, 5 times element 20, 6 times A.) 3 B.) 16 C.) 2 D.) 15
C.) 0
Identify the number of negative edge weight cycles. A.) 2 B.) 1 C.) 0 D.) 4
B.) x1, x5
Identify the shortest path between vertices B and D. A.) x6, x3, x7 B.) x1, x5 C.) x7, x4 D.) x2, x3, x4
D.) A doubly linked list's reverse traversal starts with the list's tail node.
Identify the statement that is true of linked list traversal. A.) A singly-linked list supports reverse traversal. B.) A list traversal algorithm starts with the list's next node. C.) A doubly-linked list does not support list traversal. D.) A doubly linked list's reverse traversal starts with the list's tail node.
10,000
If a graph had 100 nodes and you decided to store the edge information in an adjacency matrix, how many cells(slots) in the matrix would you have to have?
A.) prepend
If a stack is implemented as a linked list, then a push will be a(n) _____ operation. A.) prepend B.) append C.) replace D.) insert
D.) the front
In a queue, a dequeue operation always removes _____ element. A.) a random B.) the middle C.) the back D.) the front
B.) terminates
In a recursive function, the base case _____ the function. A.) passes a parameter to B.) terminates C.) provides input to D.) loops
D.) City 7
In the following graph, which city is not directly connected to City 1? A.) City 5 B.) City 2 C.) City 6 D.) City 7
complete
Name a type of binary tree which has the maximum number of nodes on every level except the last, and on this last level, the nodes occur exactly from left to right.
D.) 26, 42
Set A = {12, 24, 26, 38, 42} and Set B = {10, 20, 26, 30, 42}. Identify A ∩ B. A.) 10, 12, 20, 24, 26, 30, 38, 42 B.) 10, 12, 20, 24, 30, 38 C.) 12, 24, 38 D.) 26, 42
A.) Harry is directly friends with Rody
The following adjacency list represents the friendship between people. Identify the correct statement. A.) Harry is directly friends with Rody B.) Hank can introduce Tim to Bob C.) Bob is directly friends with Hank D.) Rita can introduce Bella to Tina
B.) False
The following code will correctly implement the DeleteLeaf function in the BST class. void BST::DeleteLeaf(Node * nodeToDelete, Node * Parent){ if (Parent->Lt == nodeToDelete) Parent->Lt = nullptr; else { Parent->Rt = nullptr; } delete nodeToDelete; } A.) True B.) False
B.) False
The following code would be a correct way to check to see if an item was added to a map that has string for it's key and a double for it's value. if (aMap.emplace("student1", 3.69)) cout << "student1 added to the map" << endl; else cout << "student1 not added to the map." << endl; A.) True B.) False
A.) True
The tree below is balanced. A.) True B.) False
A.) Binary Tree
What data structure is diagrammed in the following? A.) Binary Tree B.) Linked List C.) Hash Table D.) Graph
D.) Graph
What data structure is diagrammed in the following? A.) Heap B.) Hash Table C.) Binary Tree D.) Graph E.) Linked List
A.) 1
What is output? A.) 1 B.) 3 C.) 0 D.) 9
B.) 4
What is the height of a BST built by inserting nodes in the order 12, 24, 23, 48, 47? A.) 3 B.) 4 C.) 2 D.) 5
C. 4
What is the height of the "Practical.jpg" node? A.) 5 B.) 3 C.) 4 D.) 2
clear
What is the name of the function that will reset a set or a map to an empty state?
A.) Science
What is the parent of the "Theory.doc" node? A.) Science B.) Tom C.) Students D.) Mark
A.) 14 min
What is the shortest time taken to travel between A and G? A.) 14 min B.) 15 min C.) 16 min D.) 17 min
C.) [0, 2, 4, 6, 8]
What values are stored in the list numList? A.) [2, 4, 6, 8, 10] B.) [1, 2, 3, 4, 5] C.) [0, 2, 4, 6, 8] D.) [1, 3, 5, 7, 9]
A.) Node Tim's prev pointer
When executing ListRemove(students, node Sam) on the following doubly-linked list, what will change? A.) Node Tim's prev pointer B.) The list's tail C.) The list's head D.) Node Tom's prev pointer
A.) newNode->previous = tail;
Which XXX completes the Append() function in the C++ LinkedList class for a doubly-linked list? A.) newNode->previous = tail; B.) newNode->previous = head; C.) head = newNode; D.) head->next = newNode;
A.) tail->next = newNode;
Which XXX completes the Append() function in the C++ LinkedList class for a singly-linked list? A.) tail->next = newNode; B.) head = tail; C.) head->next = newNode; D.) head = newNode;
D.) BSTPrintInorder(node⇢left)
Which XXX completes the BST in order traversal algorithm? A.) BSTPrintInorder(node) B.) BSTPrintInorder(node⇢right) C.) BSTPrintInorder(null) D.) BSTPrintInorder(node⇢left)
A.) if (key < cur⇢key)
Which XXX completes the BST search algorithm? A.) if (key < cur⇢key) B.) if (key > cur⇢right⇢key) C.) if (key < cur⇢left⇢key) D.) if (key > cur⇢key)
B.) data = initialData; next = nullptr;
Which XXX completes the C++ Node class constructor for a node in a singly-linked list? A.) data = nullptr; next = nullptr; B.) data = initialData; next = nullptr; C.) data = nullptr; next = initialData; D.) head = initialData; tail = initialData;
C.) currentNode->next
Which XXX completes the InsertAfter() function in the C++ LinkedList class for a singly-linked list? A.) tail B.) currentNode C.) currentNode->next D.) nullptr
B.) head->previous = newNode;
Which XXX completes the Prepend() function in the C++ LinkedList class for a doubly-linked list? A.) tail = newNode; B.) head->previous = newNode; C.) newNode->previous = head; D.) head->next = newNode;
C.) newNode->next = head;
Which XXX completes the Prepend() function in the C++ LinkedList class for a singly-linked list? A.) newNode = head; B.) tail = newNode; C.) newNode->next = head; D.) head->next = newNode;
B.) list⇢tail = null
Which XXX completes the algorithm to remove a node from the singly-linked list? A.) list⇢tail = curNode B.) list⇢tail = null C.) sucNode = list⇢head⇢next D.) list⇢head = sucNode
A.) newNode⇢next = curNode⇢next curNode⇢next = newNode
Which XXX completes the following algorithm for inserting a new node into a singly-linked list? A.) newNode⇢next = curNode⇢next curNode⇢next = newNode B.) newNode⇢next = null curNode⇢next = list⇢tail⇢next C.) newNode⇢next = curNode⇢next curNode⇢next = null D.) newNode⇢next = curNode⇢next curNode = newNode
B.) guestIn.erase("John");
Which XXX function removes the map entry John from the guest list? A.) guestIn.at("John"); B.) guestIn.erase("John"); C.) guestIn.clear("John"); D.) guestIn.pop("John");
D.) logIn.at("12.4");
Which XXX function returns the map entry associated to 12.4? A.) logIn.count("12.4") B.) logIn.clear("12.4") C.) logIn.emplace("12.4") D.) logIn.at("12.4");
B.) materialName.size()
Which XXX generates the output 4? A.) materialName.len() B.) materialName.size() C.) materialName.size("John") D.) materialName.len("John")
C.) eyeColor.erase("Brown"); eyeColor.insert("yellow");
Which XXX gives 14110 as the output? A.) eyeColor.erase("Blue"); eyeColor.insert("yellow"); B.) eyeColor.erase("Blue"); eyeColor.push_back("yellow"); C.) eyeColor.erase("Brown"); eyeColor.insert("yellow"); D.) eyeColor.erase("Green"); eyeColor.push_back("yellow");
A.) if(guestIn.count(name) == 1)
Which XXX returns the seat number of the guest? A.) if(guestIn.count(name) == 1) B.) if(guestIn.count(name).second) C.) if(guestIn.at(name) == 1) D.) if(guestIn.emplace(name).first)
A.) if (numberList[i] % 2 == 0)
Which XXX will complete the algorithm to separate numberList into two lists (even and odd) using an array? A.) if (numberList[i] % 2 == 0) B.) if (numberList[i] % 1 == 0) C.) if (numberList[i] % 1 == 1) D.) if (numberList[i] % 2 == 1)
A.) A set
Which abstract data type (ADT) is best suited to store the names of all currently available smartphone models? A.) A set B.) A linked list C.) A stack D.) An array
A.) record
Which data type is best suited to store the names and grades of students? A.) record B.) stack C.) array D.) graph
D.) x9, x12, x10
Which is a valid path between D and E? A.) x6, x7, x12 B.) x5, x1, x3 C.) x11, x12, x9 D.) x9, x12, x10
A.) A list
Which is an abstract data type (ADT)? A.) A list B.) A string C.) A float D.) A boolean
A.) All NP-complete problems can be solved efficiently
Which is not a characteristic of an NP-complete problem? A.) All NP-complete problems can be solved efficiently. B.) An efficient algorithm to solve an NP-complete problem may be possible. C.) No efficient algorithm has been found to solve an NP-complete problem. D.) If an NP-complete problem has an efficient solution, then all NP-complete problems will have an efficient solution.
B.) ListPrepend(list, newNode) { if (list⇢head == null) { list⇢head = newNode list⇢tail = newNode } else { newNode⇢next = list⇢head list⇢head = newNode } }
Which is the correct code to prepend an item to a list? A.) ListPrepend(list, newNode) { if (list⇢head == null) { list⇢head = newNode list⇢tail = newNode } else { list⇢head⇢next = newNode list⇢head = newNode } } B.) ListPrepend(list, newNode) { if (list⇢head == null) { list⇢head = newNode list⇢tail = newNode } else { newNode⇢next = list⇢head list⇢head = newNode } } C.) ListPrepend(list, newNode) { if (list⇢head == null) { list⇢head = newNode list⇢tail = newNode } else { newNode⇢next = list⇢tail list⇢tail = newNode } } D.) ListPrepend(list, newNode) { if (list⇢head == null) { list⇢head = newNode list⇢tail = newNode } else { list⇢tail⇢next = newNode list⇢tail = newNode } }
D.) A telephone network
Which of the following is best represented by a graph? A.) A file system on a computer B.) The Undo command in a word processor C.) A work scheduling operation D.) A telephone network
A.) All answers given are a correct DFS traversal
Which of the following is not a correct DFS traversal when A is the starting node? A.) All answers given are a correct DFS traversal B.) ADECFB C.) ACFBDE D.) ACEDFB E.) ADCFBE
B.) {11, 22, 33, 11}
Which of the following is not a valid set? A.) {10, 15, 20} B.) {11, 22, 33, 11} C.) {5, 10, 15} D.) {12, 14, 16}
B.) Guest list in a hotel
Which of the following should be a dynamic set? A.) Names of colors B.) Guest list in a hotel C.) Days of week D.) Names of planets in the solar system
D.) Set X is a subset of set Y only if the number of elements in Y
Which of the following statements about the sets is not true? A.) Every set is a subset of itself. B.) SetRemove will operate properly on an empty set. C.) A SetSearch operation returns null, if no such element exists. D.) Set X is a subset of set Y only if the number of elements in Y is greater than X.
D.) Every data structure has a specific algorithm to implement a certain operation.
Which of the following statements is correct? A.) Data structures define only how data is organized and stored. B.) Algorithms cannot utilize data structures to store and organize data. C.) The algorithm to append an item in an array is the same as appending an item to a linked list. D.) Every data structure has a specific algorithm to implement a certain operation.
C.)
Which representation is correct for a doubly-linked list with 2 nodes?
Pre-order
A _______________ traversal would be used if you needed to save the contents of a BST on file with the same shape. This type of traversal would also be used if you wanted to make an exact copy of a BST.
A.) True
A full BST will have the maximum number of nodes possible at every level. A.) True B.) False
B.) itself
A recursive function calls _____. A.) another function B.) itself C.) at least two more functions D.) the main function
A.) focus on higher-level operations as per a program's needs
ADTs allow programmers to _____. A.) focus on higher-level operations as per a program's needs B.) access underlying implementation of a program C.) choose the runtime and memory usage of a program D.) debug a program