CS 2420 Midterm 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The depth of node 5 is

2

True or False Depth-first search is implemented with a recursive method

False

True or False Dijkstra's algorithm is guaranteed to find the shortest weighted path in a graph for which some edge weights are negative values.

False

True or False For a sparse graph, an adjacency matrix representation is an efficient use of space/memory.

False

What is the Big-O behavior of the get(int index) method in Java's ArrayList for a list of size N, when the value of index is N/2?

O(1)

Consider a balanced BST. What is the running-time behavior of add(x), where x is an item smaller than all of the items currently contained in the BST?Let N be the number of items in the BST. Let h be the height of the BST. Select the most accurate formula to describe the running-time behavior. O(1) O(log N) O(h) O(N)

O(log N)

For a balanced BST, what is the behavior of insertion in the average case

O(log N)

First in, first out

Queue

Evaluate this postfix expression: 4 5 7 2 + - *

-12

Which is a valid topological sort of the graph represented by the following DOT specification? (Select all that apply.) digraph D { 0 -> 000 00 -> 000 } 0 00 000 0 000 00 000 00 0 00 0 000 00 000 0 000 0 00

0 00 000 00 0 000

Evaluate this postfix expression: 1 2 3 2 ^ * +

19

Consider a hash table created like so: HashTable<String, Integer> groceries = new HashTable<String, Integer>(); groceries.put("apples", 3); groceries.put("bread", 1); groceries.put("apples", 4); What should be returned by groceries.size()?

2

postorder

2,5,11,19,16,9,23,27,20

Inorder

2,5,9,11,16,19,20,23,27

level order

20,9,27,5,16,23,2,11,19

preorder

20,9,5,2,16,11,19,27,23

Suppose that the current capacity of a quadratic probing hash table is 101 (i.e., the length of the backing array is 101) and the number of entries is 52. It is time to "double" the capacity of the table. What should the new capacity be?

211

The height of the three

3

How many paths exist from vertex v0 to vertex v6

5

The subtrees are rooted at which nodes?

All nodes expect the root

For which data structure is finding the minimum fastest, in the average case?

Balanced binary search tree

Which of these algorithms solves the weighted, single-source shortest path problem? Breadth-first search Depth-first search Dijkstra's algorithm Topological sort

Dijkstra's algorithm

Level order traversal of a binary tree uses which of the following FIFO queue priority queue stack none of the above

FIFO queue

True or False In a BST, if we are removing a node with two children, we can replace it with the smallest item from its left subtree and it will still be a BST.

False

True or False In a hash table that resolves collisions using separate chaining, rehashing is needed to ensure that all operations perform correctly when the hash table's load factor is large.

False

True or False Separate chaining is an easy option for implementing this assignment, since resizing the hash table and rehashing all existing items isn't required.

False

True or False Suppose we have two key-value pairs: ("hello", 3) and ("world", 390). Placing these two items in the hash table must NOT result in a collision.

False

True or False The graph represented by the following DOT specification is a DAG (i.e., directed acyclic graph).digraph D { 1 -> 2 2 -> 3 3 -> 4 4 -> 5 5 -> 3 1 -> 6 6 -> 7 7 -> 5 2 -> 7 }

False

True or False The hashCode method must return an integer between 0 and X (exclusive), for a hash table with capacity X.

False

Which of the following snippets of Java code does not belong in a method to taverse a linked list Node start = temp; Node temp = start; start = start.next; temp = temp.next; temp.next = temp; while(temp != null_

Node start = temp; start = start.next; temp.next = temp;

Consider a left-heavy BST (i.e., all right children are null). What is the running-time behavior of last()?Let N be the number of items in the BST. Let h be the height of the BST. Select the most accurate formula to describe the running-time behavior. O(1) O(log N) O(h) O(N)

O(1)

Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirst method for a list of size N?

O(1)

What is the Big-O behavior of the add method in Java's ArrayList for a list of size N, when the value of index is N (i.e., when adding to the end of the array/list)? You should assume that, in general, the backing array does not need to grow during a call to add.

O(1)

What is the Big-O behavior of the addLast method in Java's LinkedList class for a list of size N?

O(1)

Consider a left-heavy BST (i.e., all right children are null). What is the running-time behavior of first()?Let N be the number of items in the BST. Let h be the height of the BST. Select the most accurate formula to describe the running-time behavior. O(1) O(log N) O(h) O(N)

O(N)

For any BST, what is the behavior of insertion in the worst case

O(N)

Java's ArrayList class represents a basic array. As a convenience for the user, when the capacity of the backing array is exceeded, the class handles creating a new larger array and copying over the existing items. Its add(int index, E element) method inserts the specified element at the specified position. What is the Big-O behavior of this method for a list of size N, when the value of index is 0 (i.e., when adding to the beginning of the array/list)?

O(N)

What is the Big-O behavior of the get(int index) method in Java's LinkedList class for a list of size N, when the value of index is N/2?

O(N)

Consider any valid BST. What is the running-time behavior of add(x), where x is an item smaller than all of the items currently contained in the BST?Let N be the number of items in the BST. Let h be the height of the BST. Select the most accurate formula to describe the running-time behavior. O(1) O(log N) O(h) O(N)

O(h)

Last in, last out

Stack

True or False Suppose we have two key-value pairs: ("hello", 3) and ("hello", 49). These two items must have the same hash code.

True

True or False The pop operation for a stack has the same Big-O behavior as the dequeue operation for a queue.

True

True or False When a queue is implemented with a basic array, the Big-O behavior of the enqueue operation is the same as when it is implemented with a linked list.

True

True or False When a stack is implemented with a basic array, the Big-O behavior of the push operation is the same as when it is implemented with a linked list.

True

Assume this class definition: class Node { public char data; public Node next; public Node() { this.data = '\0'; this.next = null; } public Node(char data, Node next) { this.data = data; this.next = next;} } Which of the following single Java statements has the same effect as this sequence of Java statements: Node newNode = new Node(); newNode.data = 'n'; newNode.next = curr.next; curr.next = newNode; Node newNode = new NOde('n', curr.next); curr = new Node ('n', curr); curr.next = new Node ('n', curr.next); curr.next = new Node(); None of the above

curr.next = new Node('n', curr.next);

Lazy deletion is required for a hash table with which collision-resolving strategy? linear probing quadratic probing separate chaining

linear probing quadratic probing

For a hash table with which collision-resolving strategy is it possible to have a load factor of λ = 0.4? (Select all that apply.) linear probing quadratic probing separate chaining

linear probing quadratic probing separate chaining

For a hash table with which collision-resolving strategy can a load factor of λ = 0.7 guarantee that adding a new item is O(1)? (Select all that apply.) linear probing quadratic probing separate chaining

separate chaining

For a hash table with which collision-resolving strategy is it possible to have a load factor of λ = 2.5? (Select all that apply.) linear probing quadratic probing separate chaining

separate chaining

The breadth-first search algorithm structure makes use of which abstract data type

stack

Which is a valid topological sort of the graph below? (Select all that apply.) v1 v3 v4 v6 v0 v2 v5 v0 v1 v3 v2 v4 v6 v5 v0 v2 v1 v4 v3 v5 v6

v0 v1 v3 v2 v4 v6 v5


संबंधित स्टडी सेट्स

Contemporary Social Issues Final

View Set

Rivoluzione Francese e Napoleone

View Set

Somatic and autonomic nervous system

View Set

GEOL 4331: Intro To GIS: Exam I Review

View Set

Ch. 6 - Factors Contributing to False Memories

View Set