Introduction to Analysis of Algorithms

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is a Euler circuit?

A Euler circuit is a Euler path that returns to its start.

What is a Euler path?

A Euler path is a path using every edge of the graph G exactly once.

Give the name of the most efficient algorithm for single shortest-path problem in a graph with negative weights but no negative-weight cycles and its worst-case time complexity.

Bellman-Ford algorithm O( V * E )

Name an efficient algorithm for solving the single-source shortest-path problem in an unweighted graph. State its worst-case complexity. Assume the graph is sparse.

Breadth First Search O( E + V)

What is the purpose of lines 5 through 7 of the Bellman-Ford algorithm?

Check negative cycles.

Give the name of the most efficient algorithm for topological sort of a directed acyclic graph and its worst-case time complexity.

Depth First Search O( V + E )

Name four P problems.

Eulerian circuit problem. Minimal spanning tree problem. Shortest path problem. Fractional knapsack problem.

Suppose T is a shortest paths tree for Dijkstra's algorithm. After adding c > 0 to every edge in the graph, T is still a shortest paths tree for the modified graph.

False

The best-case complexity of merge sort is O(n).

False

There is an algorithm that solves the Hamiltonian Cycle problem and the related Traveling Salesman problem in less than exponential time.

False

n ∈ ω( n log n )

False

Briefly, describe the Hamiltonian cycle problem and give a very simple example of an instance of the problem.

Hamiltonian Path is a path in an undirected or directed graph that visits each vertex exactly once.

Name four NP-complete problems.

Hamiltonian circuit problem. Traveling salesman problem. Longest path problem. 0/1 knapsack problem.

Give the name of the most efficient algorithm for comparison-based sorting of an array of n integers and its worst-case time complexity.

HeapSort O( n log ( n ) )

The Hamiltonian cycle problem is an NP-complete problem. If we prove that it is polynomial-time reducible to the Traveling Salesman problem, what does this prove about the Traveling Salesman problem?

It proves that the Traveling Salesman Problem is also an NP-complete problem.

Name three divide-and-conquer algorithms.

Merge Sort Quick Sort Quick Hull

What does it mean to say that a problem is in the complexity class NP?

NP is the class of decision problem that can be solved in polynomial time by a nondeterministic algorithm.

What does it mean to say that a problem is in the complexity class P?

P is the class of decision problems that are solvable in polynomial time if using a deterministic algorithm.

Give the name of the most efficient algorithm for the selection problem and its worst-case time complexity.

QuickSelection O( n )

Give the name of the most efficient algorithm for sorting a large array of 12-digit numbers and its worst-case time complexity.

RadixSort O( n )

n + n log n = θ(________________)

n + n log n = θ( n log n )

Interpolation Search - give its average-case asymptotic complexity using big-Theta notation.

θ( log ( log ( n ) )

Radix Sort - give its average-case asymptotic complexity using big-Theta notation.

θ( n )

The most famous open problem in all of theoretical computer science is the question of whether P = NP. Why do most computer scientists believe that these classes are not the same, that is, that there are problems in the class NP that are not in the class P? What evidence do they have for this belief?

Because if we find one solution for any NP-complete problem is in P, all other NP-complete will have a solution in P. After years of study, no one has found any polynomial solution for any NP-complete problem.

Give the name of the most efficient algorithm for sorting an array of numbers where the numbers are uniformly distributed over a range and its worst-case time complexity.

BucketSort O( n )

Give the name of the most efficient algorithm for single-source shortest-path problem in a graph with non-negative edge weights and its worst-case time complexity.

Dijkstra's Algorithm (Sparse) Binary: O( E log V ) (Dense) Adjacency Matrix: O( V² )

Why is it important for the sorting subroutine called by Radix sort to be a stable sort? What is the name of a stable sorting algorithm that could be used by radix sort? (Keep in mind that the overall running time of radix sort should be linear.)

It's important for it to be stable because it must be able to handle duplicate values and place them in the same order as when they were input.

Selection Sort (Give worst-case complexity and whether it is "in-place" or not).

O( n² ) "In-place".

Prove that the Hamiltonian cycle problem is in the complexity class NP by describing a nondeterministic polynomial-time algorithm that solves it.

Step 1: find a path using nondeterministic polynomial time algorithm. Step 2: verify the path to see if it includes all vertices exactly once.

What does it mean to say that a problem is NP-complete?

The problem P is in NP. P is a decision problem, and a solution can be verified in polynomial time.

What does it mean for a problem to be intractable?

The problem grows large and we are unable to solve them in reasonable time. Problems that cannot be solved by a polynomial-time algorithm are said to be intractable.

12n² + 6n ∈ o( n³ )

True

2ⁿ⁺¹ = O( 2ⁿ )

True

A function f( n ) can be both O( n² ) and Ω( n² )

True

In any heap (considered as a tree) any two leaf nodes have either the same depth or depths differing by one.

True

There is an algorithm that tests whether a graph G = ( V, E ) is acyclic that has worst-case time complexity O( V + E ).

True

Using the median of medians algorithm to select a pivot, the Quickselect algorithm runs in worst case θ(n) time.

True

n + log n ∈ θ( n )

True

n + log( n ) = O( n )

True

n log( n ) = O( n )

True

As part of a new game show, contestants take turns making several integer guesses between 0 and 1000000 (inclusive). In scoring each round, the show's host, Professor Bulldog, needs to know which two guesses were closest to each other. Provide an asymptotically time-optimal algorithm that answers this question, argue that it is correct, and give and explain its time complexity.

Use Radix Sort. It's a stable sort that will sort large integers in O( n ).

Is there a greed algorithm for decided the order in which to answer the questions on the exam in order to maximize you grade? Name it. What is the most closely related problem?

Vᵢ = Pᵢ/tᵢ The greedy algorithm is always picking the bigger Vᵢ in the text. This is related to the fractional knapsack problem.

Name three dynamic programming algorithms.

0-1 knapsack Longest Common Subsequence Hanoi

Prove that the CLIQUE problem is in the complexity class NP by describing a nondeterministic polynomial-time algorithm that solves it.

1. Find a k CLIQUE. 2. Test if k CLIQUE is valid or not.

What are three important characteristics of any dynamic programming algorithm?

1. There is a table to store subproblem solutions. 2. Original problem can be divided into subproblems. 3. Subproblems have overlap.

Name three NP-complete problems.

Boolean Satisfiability Problem Knapsack Problem Hamiltonian Path Problem

Give the name of the most efficient algorithm for single-source shortest-path problem in an unweighted graph and its worst-case time complexity.

Breadth First Search O( V + E )

Give the name of the most efficient algorithm for the Boolean satisfiability problem and its worst-case time complexity.

Brute-force algorithm O( 2ⁿ )

What is the Eulerian cycle problem and how is it related to the Hamiltonian cycle problem?

Eulerian cycle problem is to find a cycle in a graph that visits every edge exactly once. Eulerian cycle is in class P. Hamiltonian cycle problem is in class NP.

1 + 2 + 3 + ... + ( n - 1 ) + n = O( n )

False

A Hamilton circuit is a Hamilton path that does not return to its start.

False

A Hamiltonian circuit is easier to find than a Eulerian circuit.

False

A breadth-first search algorithm uses a stack.

False

An NP-complete is a problem that has been proved impossible to solve in deterministic polynomial time.

False

Every directed acyclic graph has one and only one topological ordering.

False

If a problem is NP-hard, it is also NP-complete.

False

If a problem that is in the class NP has a polynomial time solution, then P is equal to NP-complete.

False

Quicksort is a stable sorting algorithm.

False

Radix sort is a comparison-based sorting algorithm.

False

Describe a deterministic (brute-force) algorithm that solves the Boolean satisfiability problem. What is the worst-case complexity of this algorithm?

For each variable, try all the possible combinations. Time complexity: O( n² ) n is the number of variables.

What algorithm uses depth-first search to find the strongly-connected components of a directed graph?

Kosaraju's Algorithm Θ( V + E )

What is the time complexity of the Bellman-Ford algorithm?

O( V*E )

What is the asymptotic complexity of the Longest Common Subsequence dynamic programming algorithm as a function of n, the length of the first sequence, and m, the length of the second sequence?

O( m * n )

Merge Sort (Give worst-case complexity and whether it is "in-place" or not).

O( n log n) Not "in-place".

Give the name of the most efficient algorithm for the minimal spanning tree problem for an undirected graph and its worst-case time complexity.

Prim's algorithm O( E log V )

Which of the following graphs has a Euler circuit?

The first 1: ( a, e, c, d, e, b, a )

Which of the following graphs has a Euler path?

The first 1: (a, e, c, d, e, b, a ) The third 1: (a, c, d, e, b, d, a, b )

Suppose you are given a directed graph that has negative weights on some of the edges. The Bellman-Ford algorithm solves the single-source shortest path problem for some starting vertex s, if there are no negative weight cycles. Suppose you don't know if the given graph has negative-weight cycles. One way to check for negative cycles is to run Bellman-Ford for n iterations, where n is the number of vertices, instead of n-1 iterations. Explain. Also what is the asymptotic time complexity of the Bellman-Ford algorithm?

The outermost loop of the Bellman-Ford Algorithm is designed to catch instances where there are negative weight cycles in the graph. The asymptotic time complexity of the Bellman-Ford algorithm is: O( V*E )

The outermost loop in line 2 of Bellman-Ford performs |V[G]| - 1 iterations. Under what conditions is it possible to detect convergence after fewer iterations than this?

There are no negative edges left.

A Hamilton path in a graph G is a path which visits every vertex in G exactly once.

True

A connected multigraph has a Euler circuit IFF each of its vertices has an even degree.

True

A connected multigraph has a Euler path but not a Euler circuit IFF it has exactly two vertices of odd degree.

True

A fast algorithm for the Hamiltonian cycle problem implies P = NP.

True

Any problem that is in the complexity class P is also in the complexity class NP, even if P != NP.

True

Given and undirected and unweighted graph G, with n vertices, m edges, and a source node s, the single-source shortest path problem can be solved in O( m + n ) time.

True

Heapsort is an in-place sorting algorithm

True

If T(n) = ω( g( n ) ) then T( n ) =Ω ( g( n ) ).

True

In an undirected graph with unit edge costs, a shortest-path tree found by breadth-first search is also a minimum spanning tree.

True

Suppose there is a polynomial-time reduction from problem A to problem B. If there is a polynomial-time algorithm that solves problem B, then there is a polynomial-time algorithm that solves problem A.

True

Suppose there is a polynomial-time reduction from problem A to problem B. If there is no polynomial-time algorithm that solves problem B, then there is no polynomial-time algorithm that solves problem A.

True

The Boolean satisfiability problem can be solved by a deterministic polynomial-time algorithm if and only if P = NP.

True

The Eulerian Circuit problem can be solved in low-order polynomial time, that is, it is tractable.

True

n! + n² = θ(________________)

n! + n² = θ( n! )

n³log n = θ(________________)

n³log n = θ( n³log n )

The shortest path between two vertices in a minimum spanning tree is always a shortest path between the two vertices in the full graph.

False

n! = Ω( nⁿ )

False

n³ - n² ∈ O( n² )

False

n¹.¹ ∈ O( n log n )

False

If a heap is used to represent at priority queue, and the first element is removed, the heap property is restored by moving the last element to the root of the tree and then running MAX-HEAPIFY on the new root element. What is the worst-case complexity of restoring the heap property in this way?

O( lg n)

Insertion Sort (Give worst-case complexity and whether it is "in-place" or not).

O( n² ) "In-place".

What is the relationship between the worst-case complexity of Prim's algorithm and the worst-case complexity of Dijkstra's algorithm.

Same: O( E log V )

Explain what it means to say the recursive function gcd( a, b ) shown above is a tail-recursive function.

Tail-recursive means an algorithm uses linear recursion and the algorithm makes a recursive call as its very last operation. In the gdc( a, b), the last operation is called gcd( b, a mod b).

Counting sort is a stable sorting algorithm.

True

The bisection method is an iterative algorithm that improves the accuracy of its approximation of the root of an equation f(x) = 0 by a factor of two in each iteration.

True

Divide-and-conquer and dynamic programming are two different strategies for designing algorithms. Describe an important similarity between them and an important difference.

Similar: Both have subproblems. Difference: dynamic programming subproblems overlap (re-use information).

Introsort - give its average-case asymptotic complexity using big-Theta notation.

θ( n log n )

Merge Hull - give its average-case asymptotic complexity using big-Theta notation.

θ( n log n )

Quick Hull - give its average-case asymptotic complexity using big-Theta notation.

θ( n log n )

Quick Sort - give its average-case asymptotic complexity using big-Theta notation.

θ( n log n )

Binary Search - give its average-case asymptotic complexity using big-Theta notation.

θ( log ( n ) )

Karatsuba's divide-and-conquer algorithm for multiplication.

θ( log₂ 3 )

Bucket Search - give its average-case asymptotic complexity using big-Theta notation.

θ( n )

Quick Select - give its average-case asymptotic complexity using big-Theta notation.

θ( n )

What is the worst-case complexity of Prim's algorithm for each storage type?

Adjacency Matrix: O( V² ) Binary Heap: O( E log V )

Name an efficient algorithm for solving the single-source shortest-path problem in a negative weights but no negative-weight cycles. State its worst-case complexity. Assume the graph is sparse.

Bellman Ford O( E*V )

Name an efficient algorithm for solving the single-source shortest-path problem in a graph with non-negative edge weights. State its worst-case complexity. Assume the graph is sparse.

Dijkstra's Algorithm O(V lg V)

If its priority queue is implemented as a binary heap, the worst-case complexity of Dijkstra's algorithm in a dense graph is O( V² ).

False

If its priority queue is implemented as a binary heap, the worst-case complexity of Dijkstra's algorithm in a dense graph is O( V²).

False

In solving the convex hull problem, Quick Hull is asymptotically faster than Merge Hull in the worst case.

False

Karatsuba's divide-and-conquer multiplication algorithm is the (asymptotically) fastest multiplication algorithm developed so far.

False

Mergesort is an "in-place" sorting algorithm.

False

What is the bit complexity of the traditional grade-school algorithm for multiplying two n bit numbers?

O( n² )

Quick Sort (Give worst-case complexity and whether it is "in-place" or not).

O( n² ) "In-place".

A graph G = ( V, E ) is said to be dense if E = O( V² ).

True

A graph G = ( V, E ) is said to be sparse if E = O(V).

True

A graph G = ( V, E ) is said to be sparse if E is O(V).

True

Given an unsorted array of n integers, the median element in the array can be found in O(n) time in the worst case.

True

If an undirected graph G = ( V, E ) has the same weight for every edge, then both the single-source shortest path problem and the minimal spanning tree problem for the graph can be solved in linear time.

True

Interpolation search solves the same problem as binary search, but requires knowledge of the distribution of elements in an array.

True

Prim's algorithm can only find a minimal spanning tree of a graph if the graph is undirected.

True

Suppose that e is a minimum weight edge of a weighted undirected graph G, and all the edge weights are distinct. Then e is always contained in the minimum spanning tree of G.

True

The greedy algorithm for the fractional knapsack problem takes a fractional amount of at most one item.

True

The worst-case asymptotic complexity of Dijkstra's algorithm in a dense graph is O( V²).

True

Your firm has been hired to build a fiber-optic network connecting several hundred different buildings on the grounds of a large research lab. You want to minimize the total cost of this job. Suppose that you can find out the cost of connecting any given pair of buildings. (In some cases that might be the distance times the cost of the cable per meter, but in other cases it might be more, if say there are roads to dig up before burying the cable.) What algorithm(s) that we studied might be relevant and how would you apply them? ( Your answer should not be more than two sentences. )

Use Prim's algorithm to find a Minimal Spanning Tree.


Kaugnay na mga set ng pag-aaral

12 Basic Functions - Domain and Range

View Set

Skeletal System - Shapes of Bones

View Set

Organizational Behavior SB Ch 4, 5, 6

View Set

Med/Surg-Chapters 7, 33, and 61 Exam

View Set

Infrastructure - All Lab Questions

View Set