D0012E A

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

Dijkstra's algorithm for the single-source shortest-paths problem works correctly on any weighted, directed graph with no negative-weight cycles. True or False?

False (Tänk ba att en nonnegative cycle kan fortfarande ha ett negativ kant )

Prim's and Kruskal's algorithm will always return the same minimum spanning tree (i.e, the same set of vertices and the same set of edges)?. True or false?

False,

200 · n^2 + 9 · (n^3 /log n ) − 1 + 12 · n = Ω(n3)

False.

In a hash table of size m with n elements in which collisions are resolved by chaining, a search operation takes average-case constant time, under the assumption of simple uniform hashing. True of False?

False.

The difference between the heights of any two leaves in a 2-3-4 tree is atleast 1 and at most 2.

False.

What type of algorithm does not work for shortest paths

Greedy methods

What is the running time of a binary searh tree?

it is O(h) , where h is the height of the tree.

A d-ary heap (d > 2) is like a binary heap, but (with one possible exception) non-leaf nodes have d-children instead of 2 children. The operations INSERT and DECREASEKEY can be done in Θ(log_d * n) time while DELETEMIN takes Θ(d*log_d *n) time in the worst case.

Θ(n*d*log_d*n + m* log_d * n) or Θ(n×cost(INSERT)+n×cost(DELETEMIN)+m×cost(DECREASEKEY))= Θ(n ×logd n + n ×d ·logd n + m ×logd n) = Θ((n ×d + m) ×logd n)

If a graph is represented by its adjency matrix. then the running time of a depth-first search equals Θ(?)

Θ(n^2)

log^10 *n + (2*n^2)^3 + 10^64 = Θ(?)

Θ(n^6)

Suppose that a graph G = (V,E) is represented by its adjacency matrix. Give the running time of Prim's minimum spanning tree (in Θ(·) notation).

Θ(|V|^2)

2^(2n) = O(2^n)

Claim: 2^(2n) != O(2^n) Proof by contradiction: Assume: 2^(2n) = O(2^n) Which means, there exists c>0 and n_0 s.t. 2^(2n) <= c * 2^n for all n >= n_0 Dividing both sides by 2^n, we get: 2^n <= c * 1 Contradiction! 2^n is not bounded by a constant c. Therefore 2^(2n) != O(2^n)

Let A be an algorrithm that solves a given problem of size n in Θ(n^3) in the worst case. Which of the following statements is NOT true? a. A takes at most n^3 time on every input of size n b. A takes at least b * n^3 time on some input of size n, where b > 0 is a constant.

A

If there is a negative-weight cycle in the input connected undirected graph, Dijkstra's single-source shortest-paths algorithm will a. terminate and return a spanning tree b. terminate and return a minimum spanning tree c. terminate and return the shortest paths d. loop forever

A. Terminate and return a spanning tree

Let f(n), g(n) and h(n) be positive integer functions. Suppose that f(n) = O(h(n)) and g(n) = O(h(n)). Which of the following are true? No justification is needed. (a) f(n) = O(g(n)) (b) f(n) g(n) = O(1) (c) Either f(n) = O(g(n)) or g(n) = O(f(n)) is true. (d) If the running time of an algorithm A is f(n) in the average case, then the worst-case complexity of A is O(n × f(n)).

All of them are false

Which data structure is used in breadth-first search of a graph to hold nodes? a. tree b. queue c. stack d. heap

B.

FlervalsAlternativ: - The worst-case time complexity of the binary search algorithm on an unsorted sequence of length n is.... a. Θ(n) b. Θ(log n) c. Θ(n log n) d. Θ(n^2)

B. Θ(log n)

How does the prims algorithm start. How does it choose its path and what type of paths?

Beforehand we have a starting vertex were we will begin from. It does work on negative edge weights. And it utilizes a priority min queue , exploring all the possiblities to choose a path without creating a cycle.

InsertionSort

Best : O(n) Average:Θ(n^2) Worst: Θ(n^2)

SelectionSort

Best : O(n^2) ((Omega n^2)) Average:Θ(n^2) Worst: Θ(n^2)

Time complexity say best to worse

Best to worse: 1. O (1) 2.O(log n) 3.O(n) 4.O(n log n) 5.O(n^2) 6.O(2^n) 7.(n!)

Which of the following statements is NOT true about binary search tree? a. Deletion can be done in O(n log n) time in the worst case b. Deletion can be done in O(n^2) time in the worst case c. Insertion can be done in O(log n ) time in the worst case d. Insertion can be done in Omega(log n) time in the worst case.

C

Which of the following statements is NOT true about sorting algorithms? a. Heapsort is an in-place algorithm. b. Countingsort is stable. c. Insertionsort runs in linear time in the average case. d. Bucketsort runs in linear time in the average case.

C.

The worst-case run time for mergesort to sort a sorted array of length n is a. Θ(n) b. Θ(log n) c. Θ(n log n) d. Θ(n2)

C. Θ(n log n)

Given a weighted directed acyclic graph G = (V,E) represented by its adjacency lists, we can compute shortest paths from a single source in Θ(V + E) time by a. doing a breadth-first search on G. b. running Dijkstra's algorithm on G. c. running Bellman-Ford's algorithm on G. d. relaxing the edges of G according to a topological sort of its vertices.

D.

Let A be an algorithm that solves a given problem of size n in Ω(n3) in the worst case. Which of the following statements is true? a. A takes at most c × n3 time on every input of size n, where c > 0 is a constant. b. A takes at most c × n3 time on some input of size n, where c > 0 is a constant. c. A takes at least c × n3 time on every input of size n, where c > 0 is a constant. d. A takes at least c × n3 time on some input of size n, where c > 0 is a constant.

D.

RadixSort works correctly when using the following sorting algorithm (instead of countingSort) to sort a digit: a. Heapsort since it is an in-place algorithm. b. MergeSort since it is of divide-and-conquer approach c. BucketSort since it runs in linear time in the average case d. InsertionSort since it is a stable sorting algorithm

D. InsertionSort

Given a hash table of size m with n keys using double hashing. Then, the minimum key in the tablecan be found in O(1) time in the average case. True or false?

False

Other time complexities for dijkstras with two other methods. Which two others are they and what time complexity?

Linear array for priority queue : O(v^2) By binary heap : O((E+V) log V) (The fastest -fibonacci heap O(E + V log V)

Dijkstra's algorithm Time complexity in Adjency list/matrix

List: O(E + V log v) Matrix: O(V^2)

why is it that Shortest paths tree /= (not) Minimum spanning tree

Path between a pair of vertices in a MST of an undirected graph is not necessarily a minimum - cost path.

Dijkstra's algorithm works similar to two other algorithms, which ones and how?

Resembles the breadth-first search in that set S corresponds to the set of black vertices. Just as a vertices in S have their final shortest path weights, so do black vertices in a BFS have their correct Bredth first distance. Prims MST by them both utilizing a min-priority queue to find the smallest vertex path.

What is the difference between the BST property and the min-heap property? Can the min-heap property be used to print out the keys of an n-node in sorted order in O(n) time?

The binary-search-tree property guarantees that all nodes in the left subtree are smaller, and all nodes in the right subtree are larger. The min-heap property only guarantees the general child-larger-than-parent relation, but doesn't distinguish between left and right children. For this reason, the min-heap property can't be used to print out the keys in sorted order in linear time because we have no way of knowing which subtree contains the next smallest element.

Explain a d-ary heap

They ar elike a binary heap but with one possible exception, that non-leaf nodes have d-children instead of 2.

Prims algorithm what is the time complexity ? and how to also improve that ?

Total running time is O(E log V) and could improve to O(E + V log V) with fibonacci heap. In matrix it is O(V^2)

Consider binary search trees on n elements. The difference between the heights of any red-black tree and any AVL tree is at most c · log n, where c > 0 is a constant. True or False?

True.

Given a weighted, directed graph G = (V,E) with no negative-weight cycles. Suppose that the number of edges on any single-source shortest path from the source s is at most k. Then, we can terminate Bellman-Ford after k passes and return the shortest paths. True or False? What is the running time (in Θ(·) notation)?

True. The run time is Θ(k ·|E|).

Time complexity for operations in a BST

Worst:O(n)Average:O(logn)


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

Chapter 6 A First Look at Classes Java

View Set

Financial Leverage and Capital Structure Policy

View Set

Genetics Ch 15 Gene Regulation in Eukaryotes via Translation and Transcription

View Set

Quiz #3: CH. 2 Cognitive Neuroscience

View Set

Managerial Cost Accounting - ch. 11

View Set

Final Exam (Chapters 7-12, 17, 19)

View Set

26.; The child with GI dysfunction

View Set