Data Structures Final

Ace your homework & exams now with Quizwiz!

In-Order Traversal

(left, node/root, right)

Post-Order Traversal

(left, right, node/root)

Pre-Order Traversal

(node/root, left, right)

Which of the following can be done in O(logN)? -Raising a number to the Nth power. -Computing the greatest common divisor of some integer N. -Adding two N-digit numbers.

-Raising a number to the Nth power. -Computing the greatest common divisor of some integer N.

Given a following directed weighted graph G=<V,E>, where V = {V0,V1,V2,V3,V4,V5,V6}, and twelve edges, with the edge costs (weight) listed as the third item in the triplet: E = {(V0,V2,4), (V1,V0,2),(V1,V3,3),(V3,V0,1), (V3,V2,2),(V3,V5,8),(V3,V6,4),(V4,V1,10),(V4,V3,2),(V4,V6,7),(V5,V2,2),(V6,V5,1)} What would be the cost of its minimum spanning tree(MST)?

10, if it was an undirected graph.

The following items are inserted into a binary search tree: 3, 6, 5, 2, 4, 7, 1. Which node is the deepest?

4

Which of the following problems is not known to be solvable in linear time? -topological sort -unweighted shortest path in general graphs -weighted shortest path in acyclic graphs -weighted shortest path in cyclic graphs

All are solvable in linear time.

Which of the following algorithms runs in O(n) average time but O(n^2) worst time?

Bucket sort

Let a binary tree with root A. The root has left child B and right child C. B has left child D and right child E. There are no other nodes in the tree. Which traversal is an inorder traversal of the tree?

DBEAC

Which operation is not efficiently supported by (min) binary heaps?

DeleteMax

Which algorithm solves the positive weighted single source shortest path problem?

Dijkstra's algorithm

For the linked list implementation of the queue, where are the enqueues and dequeues performed?

Enqueue after the last element, dequeue the first element.

Which of the following operations is not O(1) if we use a single-linked list? -Accessing the element in the first position. -Remove the first element. -Find an arbitrary element

Find an arbitrary element.

Which of the following can be done in O(N)?

Find an element in an unsorted array.

Which of the following algorithms runs in O(nlogn) for both average and worst time?(does not use massive recursion or multiple arrays)

Heap sort

Which of the following algorithms is non stable?

Heap sort, quick sort, selection sort, shell sort, radix sort

Which operation is efficiently (O(1)) supported by queues?

Insert at the end.

Which of the following algorithms runs in O(n^2) for both average and worst time? (best case is O(n))

Insertion sort

Which of the following algorithms is stable?

Insertion sort, merge sort, and bucket sort

Which algorithm is used to compute minimum spanning trees?

Kruskal's algorithm

Which of the following algorithms requires the most extra space memory(not in place algorithm)?

Merge sort

Which of the following algorithms runs in O(nlogn) for both average and worst time?(slightly faster for larger arrays but uses more memory because of the use of the second array)

Merge sort

What is an out-of-place sorting algorithm?

Merge sort, radix sort, and bucket sort

Let a binary tree with root A. The root has left child B and right child C. B has left child D and right child E. There are no other nodes in the tree. Which of the following traversals yields ABCDE? -In-Order -Post-Order -Pre-Order

None of the traversals yield that result.

The following items are inserted in the given order into an AVL-tree: 6, 1, 4, 3, 5, 2, 7. Which node is in the deepest node?

None. 1, 3, 5, 7 are all the deepest.

Which of a) to d) is false about binary search algorithm? -The input array must be sorted. -Successful searches take logarithmic time. -Unsuccessful searches take logarithmic time. -The worst case for any search is logarithmic.

None. A binary search algorithm requires that the input array be sorted, successful and unsuccessful searches take logarithmic time, and the worst case for any search is logarithmic time.

Which of the following tree traversals requires more than linear time in the worst case? -In-Order -Post-Order -Pre-Order

None. All of them are linear time.

N distinct elements are inserted one by one into an initially empty (min)binary heap. The total running time is

O(NlogN) worst case

The running time complexity of Breath First Search (BFS) algorithm is?

O(V + E). Depending on the input to the graph, O(E) could be between O(1) and O(V^2).

Indicate the runtime complexity of Dijkstra's algorithm when the implementation is not based on a binary min-heap.

O(V^2). Extract Min operation will take O(V) times as the array is usually unsorted and the minimum element has to be found out by scanning every vertex in the worst case.

N elements are inserted from a min-heap with N elements. The total running time is:

O(logn) in the worst-case but is O(1) on average.

What is the worst-case running time complexity of an algorithm with the recurrence relation T(N) = 2T(N/4) + O(N^2)? Hint: Use the Master Theorem.

O(n^2)

Suppose that you have the following algorithm to sort a list of integer numbers. Algorithm: 1. three first step is to build an AVL-tree with the input list of integer numbers. 2. the second step is to incorporate in- order traversal of the AVL-tree. This recursive algorithm allows to print the value of the nodes of the AVL-tree in sorted order. What is the total running time complexity of this algorithm?

O(nlogn)

Which of a) to d) is false about stacks? -ArrayList and LinkedList support stack operations. -Stacks are known as LIFO lists. -Process of removing an element from the stack is called push.

Process of removing an element from the stack is called push.

Programs A and B are analyzed and found to have worst-case running times no greater than NlogN and N, respectively. Which of the following statements does the analysis imply?

Program A is more efficient than program B.

Jobs sent to a printer are generally placed on a

Queue

Which of the following algorithms runs in O(nlogn) average time but O(n^2) worst time?

Quick sort

Which of the following algorithms runs in O(n) for both average and worst time?

Radix sort

Which of the following algorithms runs in O(n^2) for both average and worst time?(best case is O(n^2))

Selection sort

What are some in-place sorting algorithms?

Selection sort, insertion sort, heap sort(hard to implement), quick sort, shell sort

Which of the following algorithms runs in O(n^1.25) average time but O(n^1.5) worst time?

Shell sort

What is the recurrence relation for selection sort?

T(n) = T(n - 1) + O(n). It is found to be equal to O(n^2).

What is the recurrence relation for heap sort?

T(n) = T(n − 1) + log(n). It is found to be equal to O(nlogn).

The Master Theorem

T(n) = aT(n/b) + O(n^d) -T(n) is O(n^d) if a<b^d -T(n) is O(n^dlogn) -T(n) is O(n^(loga with base b))

What is the recurrence relation for merge sort?

T(n)=2T(n/2) + O(n). It is found to be equal to O(nlogn).

Suppose T1(n) = O(f(n)) and T2(n) = O(f(n)). Which of the following are true?

T1(n) + T2(n) = O(f(n))

What is an AVL tree?

a binary search tree with the balance condition.

What is a synonym for an edge?

arc

PercolateUp and PercolateDown are used for

binary heaps

Which algorithm solves the unweighted single source shortest path problem?

breadth first search(BST)

Which of the following statements is true? -a topological ordering exists in every directed graph -every acyclic graph has at least one topological ordering -every acyclic graph has exactly one topological ordering -every acyclic graph has at most one topological ordering

every acyclic graph has at least one topological ordering

Every node in a (min) binary heap (with no duplicate values)

is smaller than its children.

What algorithm does not use a queue?

positive weighted shortest path algorithm

Which of the following is true: The size of a hash table with n keys -should be n for double-hashing -should be a prime number greater than n for linear probing -should be a prime number and less than 2^n for quadratic probing -none of these

should be a prime number greater than n for linear probing. (potentially incorrect)

For minimum spanning tree (MST) construction, Kruskal's algorithm selects an edge

with minimum weight so that cost of MST is always minimum.


Related study sets

Solving Quadratic Equations by Factoring, Set 9

View Set

human form and fucntion chapter 16 post test

View Set

CH 38, 39, 40, 41, and 42 Muscle Skeletal

View Set

exam 4 homework stars and cosmology.

View Set

Life policy, writers, provisions, options, and exclusions Quiz Questions Chapter Three

View Set

ACG 203 CENGAGE CHAP 10, chap 11

View Set

Abnormal Psychology Final: Chapter 18

View Set