








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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The final exam questions and answers for the cosc 2336 course focusing on weighted graphs and algorithms. Topics covered include graph traversal, minimum spanning trees, hashing functions, and linked lists. The exam tests understanding of graph data structures, algorithms for traversing graphs, and various graph-related concepts.
Typology: Exams
1 / 14
This page cannot be seen from the preview
Don't miss anything!
The ____ search of a graph first visits a vertex, then all its adjacent vertices, then all the vertices adjacent to those vertices and so on. ------ CORRECT ANSWER---------------breadth-first True or False: The time complexity of the BFS algorithm is O(|E|+|V|), ------ CORRECT ANSWER---------------True True or false: The WeightedEdge class extends AbstractGraph Edge ------ CORRECT ANSWER---------------True A WeightedEdge object contains the public data fields ______. ------ CORRECT ANSWER---------------u,v,weight The adjacent edge for each vertex in the WeightedGraph class is stored in____ ------CORRECT ANSWER---------------an ArrayList The WeightedGraph is a subtype of ____. ------CORRECT ANSWER--------- ------Abstract Graph and Graph
The addEdge(u,v,w) method performs the following operations: ------ CORRECT ANSWER---------------Invokes super.add(u,v) to add an edge. Adds a weighted edge to the adjacent list ofr vertex u. Adds a weighted edge to the adjacent list ofr vertex v. True of False: A graph may have several minimum spanning tree. ------ CORRECT ANSWER---------------True The MST class is subtype of _____. ------CORRECT ANSWER--------------- AbstractGraph Tree The getMinimumSpanningTree() method returns _____. ------CORRECT ANSWER---------------a MST The ShortestPathTree class is subtype of ______. ------CORRECT ANSWER---------------AbstractGraph Tree The getShortestPath() method returns _________. ------CORRECT ANSWER---------------a ShortestPathTree A reference variable contains the location of an object in memory. True or False? ------CORRECT ANSWER---------------True A recursive solution can have more than one base case. True or False? ---- --CORRECT ANSWER---------------True
The WeightedGraph is a subtype of _________. ------CORRECT ANSWER---------------Graph/AbstractGraph The addEge(u, v, w) method performs the following operations: ------ CORRECT ANSWER---------------Invokes super.add(u, v) to add an edge. Adds a weighed edge to the adjacent list for vertex u. Adds a weighed edge to the adjacent list for vertex v. A hashing function ______. ------CORRECT ANSWER---------------maps a key to an index in the hash table If each key is mapped to a different index in the hash table, it is called _____. ------CORRECT ANSWER---------------perfect hashing A collision occurs _________. ------CORRECT ANSWER---------------when two or more keys are mapped to the same hash value. True or False: Every object has the hasCode() method. ------CORRECT ANSWER---------------True What is the return type for the hashCode() method? ------CORRECT ANSWER---------------int True or False: Two objects are equal if their hashCodes are the same. ------ CORRECT ANSWER---------------False
True or False: Two objects have the same hashCodes if they are equal. ---- --CORRECT ANSWER---------------True If two strings are equal, the two strings have the same hashCodes. ------ CORRECT ANSWER---------------True For an Integer object with value 20, what is its hashCode? ------CORRECT ANSWER--------------- 20 1<<2 is ______. ------CORRECT ANSWER--------------- 4 _______ is to find an open location in the hash table in the event of collision. ------CORRECT ANSWER---------------Open addressing When a collision occurs during the insertion of an entry to a hash table, _________ finds the next available location sequentially. ------CORRECT ANSWER---------------linear probing The ______ places all entries with the same hash index into the same location, rather than finding new locations. ------CORRECT ANSWER-------- -------separate chaining scheme _______ measures how full the hash table is. ------CORRECT ANSWER---- -----------Load factor
If two vertices are connected by two or more edges, these edges are called ------CORRECT ANSWER---------------parallel edge A ____ is the one in which every two pairs of vertices are connected ------ CORRECT ANSWER---------------complete graph What is the number of edges in a complete graph of n vertices? ------ CORRECT ANSWER---------------n(n-1)/ What is the number of edges in a tree of n vertices? ------CORRECT ANSWER---------------n - 1 ___ is graph in which edges are not weighted ------CORRECT ANSWER---- -----------Unweighted Graph ____ is an edge that connects to a vertex itself. ------CORRECT ANSWER- --------------Loop _____ of G is a subgraph of G. The subgraph connects all the vertices in G without cycles. ------CORRECT ANSWER---------------Spanning Tree ____ refers to two or more edges between two vertices. ------CORRECT ANSWER---------------Parallel Edges
_____ is a graph that does not have loops or parallel edges. ------ CORRECT ANSWER---------------Simple Graph _____ is a graph in which edges have no directions ------CORRECT ANSWER---------------Undirected Graph ____ of a vertex is the number of edges connected to the vertex. ------ CORRECT ANSWER---------------Degree ___ refers to a closed path in a graph. ------CORRECT ANSWER--------------
In a reference-based implementation of an ADT list: ------CORRECT ANSWER---------------an item explicitly references the next item An array-based implementation of an ADT list: ------CORRECT ANSWER--- ------------requires less memory to store a data element than a reference- based implementation. A recursive solution that finds the factorial of n (ie. n!) generates how many recursive calls? The base case is fact(0) = 1 ------CORRECT ANSWER---------------n Which of the following statements deletes (ie. marks as garbadge) the first node of a linear linked list? ------CORRECT ANSWER---------------head = head.next Which of the following will be true when the reference variable curr references the last node in a linear linked list? ------CORRECT ANSWER--- ------------curr.next == null Which of the following statements deletes the node that cur references? ---- --CORRECT ANSWER---------------prev.next = curr.next; In a linear linked list: ------CORRECT ANSWER---------------the next reference of the last node has the value null
Which of the following statements is used to insert a new node, referenced by newNode, at the end of a linear linked list? ------CORRECT ANSWER---- -----------newNode.next = curr; prev.next = newNode; Suppose that we have an ordered array of 980 entries. How many elements would need to be moved/shifted if it was determined that an element was to be inserted at position 401? ------CORRECT ANSWER------ --------- 580 A ___________ allows the deletion of a node from a linked list without the need to traverse the list to establish a trailing reference (i.e. a prev reference) ------CORRECT ANSWER---------------precede reference In all circular linked lists: ------CORRECT ANSWER---------------every node references a successor Which of the following is true about all doubly linked lists? ------CORRECT ANSWER---------------Each node references both its predecessor and its successor The correct grammar for the following language L L = {w: w is of the formS^(n)D^(n) for some n>= 0} is ------CORRECT ANSWER---------------<legal-word> = empty string |S <legal-word> D Which of the following is the prefix form of the infix expression (8 + 6) / (16- 4)? ------CORRECT ANSWER---------------/ +86 - 164
When you solve a problem by solving two or more smaller problems, each of the smaller problems must be _________ the base case than the original problem ------CORRECT ANSWER---------------closer to In ______ recursion, there can be multiple activation of the same method existing at the same time ------CORRECT ANSWER---------------Direct ___________- is a problem-solving technique for guessing at a solution recursively and backing up when an impasse is reached ------CORRECT ANSWER---------------Backtracking Comparing recursion and iteration, which of the following is true? ------ CORRECT ANSWER---------------Recursion reduces the size of the code What is the effect of the following recursive Java method, assuming that X and Y are positive integers? public static Int Mystery (Int X, Int Y) { if (X == 0) return Y, else return 1 + Mystery(X-1, Y) } ------CORRECT ANSWER---------------It computes and returns X + Y Consider the following Java program What is output by the program public static void main(void) {
int a, b, result; a = 3; b = 4; result = value (a, b) System.out.printf("%d\n", result); } public static int value(int x, int n) { if ( n> 0) return x * value (x, n-1), else return 1, } ------CORRECT ANSWER--------------- 81