CSCI570

Ace your homework & exams now with Quizwiz!

Dense graph

a graph in which the number of edges is E=O(V^2) - number of edges are closet to the max number of edges

Adjacency List

a representation of a graph in which each node has a list of nodes that are adjacent to it, i.e. connected to it by an arc. - used for sparse graphs, E=O(V)

What is meant by finding the shortest path?

a set of edges with the minimum possible sum of their weights, aka Dijkstra's

Hamiltonian path

a simple path that traverses all vertices exactly once - linear time

In a recurrence what does each variable represent: T(n)=aT(n/b)+f(n)

a=number of subproblems b=size of subproblems f(n)= the time complexity of the step

What is the lower bound of sorting algorithms?

always n log n

Is log n slower or faster than n?

always slower

How many trees does a binomial heap have?

at most ceiling(log n) binomial trees in increasing order of size

Insertion for Binary heap vs Binomial heap

binary heap: - offline: all data available, O(n) - online: no data available, O(n log n) binomial heap: - offline & online: O(n), each insert is constant O(1) so for n inserts it costs O(n)

Accounting method

computes the individual cost of each operation, assign different charges to each operation - AC is the amount we charge an operation

Aggregate method

computes the upper bound T(n) on the total cost of n operations. AC is given by T(n)/n

how many binomial trees does a binomial heap with 31 elements contain?

convert 31 to binary--> 11111 so there are 5 binomial trees

What does theta mean?

f(n) = theta(g(n)) --> f(n) = O(g(n)) and f(n) = Omega(g(n))

T/F IN every stable matching, there is a woman who is matched with her highest-ranked man

false

T/F If all edges in a connected undirected graph have distinct positive edge weights, the shortest past between any two vertices is unique

false

T/F Suppose we have a graph where each edge weight value appears at most twice Then there are at most two MST's in the graph

false

T/F log n = omega(n)

false n is not a lower bound of log n

T/F If an operation takes O(1) expected time, then it takes O(1) amortized time

false - amortized time is the upper bound

T/F amortized analysis is used to determine the average runtime complexity of an algorithm?

false - it is used to find the worst cost over a sequence of operations

T/F use binary search for sorting

false - never use for sorting

T/F Let G be an undirected connected graph with distinct edge weight. None of the MST's contain the maximum number

false - the max weighted edge can be in an MST because it connects two parts of the graph

T/F there exists an MST for a weighted directed connected graph

false - this is called an arborescence problem

Binary Search

finds an item in a sorted array by dividing in half and determining which half to look at. recursively do this until the number is found. T(n) = T(n/2)+O(1) O(logn)

What does it mean for a function f(n) = O(g(n))?

g(n) will grow asymptotically larger than f(n) f(n) is big O of g(n)

Eurler's formula

if G is a connected planar graph, V-E+F=2

What is log log n algorithm?

if loop variable is reduced/increased exponentially by constant amount

T/F A dynamic programming algorithm tames the complexity by making sure that no subproblem is solved more than once

it makes sure a subproblem isnt solved more than once - but that doesn't tame the complexity?

How many bits does a binary number have?

log n

What does Omega mean?

lower bound f(n) = omega(g(n)) g(n) is a lower bound of f(n), and f(n) will eventually dominate g(n)

How many spanning trees are in a Kn (complete graph with n vertices) graph?

n^(n-2) spanning trees

What is the complexity of multiplication?

n^2

If a graph is cyclic can you have a topological order?

no, because there exists a cycle

How many binomial trees are in a binomial heap of size n?

number of set bits in binary representation of n

Binary Heap - What is the number of vertices on each level?

power of 2

What does a logarithmic time algorithm mean?

proportional to the number of times n is divided, if loop variable is divided

Consider a max-heap H and a given number X. We want to find whether X is larger than the k-th largest element in the list. Design an O(k) time algorithm to do this.

start at the root r and compare X with, if X < r create two pointers left and right. continue to traverse the max-heap comparing at each level to find if X > k-th largest element, time O(K) at most k nodes are visited

Suppose we are given an instance of the Minimum Spanning Tree problem on an undirected graph G. Assume that all edges costs are positive and distinct. Let T be an MST in G. Now suppose that we replace each edge cost ce by its square root, ce 1/2 , thereby creating a new instance of the problem (G') with the same graph but different costs. Prove or disprove: T is still an MST in G'

statement is true, because when finding the MST we will always choose the minimum path and as long as a > b, a^1/2 > b^1/2

What does an algorithm of runtime log n mean?

the max runtime is proportional to the logarithm of n

What is the time complexity of matrix multiplication?

theta(n^3) T(n)=4T(n/2)+theta(n)

T/F A spanning tree of a given undirected, connected graph G(V,E) can be found in O(|E|) time

true

T/F Compared to the worst-case analysis, amortized analysis provides a more accurate upper bound on the performance of an algorithm?

true

T/F If T(n)is Θ(f(n)), then T(n)is both O(f(n))and Ω(f(n))

true

T/F Let G be an undirected connected graph with distinct edge weight. The MST is unique

true

T/F Let G be an undirected connected graph with distinct edge weight. The MST must have the minimum weight edge

true

T/F a connected undirected graph is guaranteed to have at least |V|-1 edges

true

T/F amortized constant time for a dynamic array is still guaranteed if we increase the array size by 5%?

true

T/F g(n) = O(f(n)) is the same as f(n) = Omega(g(n))

true - the first is saying f(n) grows faster than g(n) - the second is saying f(n) will eventually dominate g(n)

T/F (1/3)^n + 100 = theta(1)

true because 1/3 eventually goes to 0

T/F n^2 = omega(n log n)

true n log n is a lower bound of n^2 and n^2 will eventually dominate n log n

T/F Suppose that in an instance of the original Stable Marriage problem with n couples, there is a man M who is first on every woman's list and a woman W who is first on every man's list. If the Gale-Shapley algorithm is run on this instance, then M and W will be paired with each other.

true - but do we need to know this?

T/F A directed graph G is strongly connected if and only if G with its edge directions reversed is strongly connected.

true - by definition

T/F While there are different algorithms to find a minimum spanning tree of an undirected connected weighted graph G, all of these algorithms produce the same result for a given graph with unique edge costs.

true - only because of the unique edge costs

T/F in a binary max-heap with n elements, the worst-case runtime complexity of finding the second largest element is O(1)

true - the second largest element in a max-heap will either be the left or right child of the root

T/F in a binary min-heap with n elements, the worst-case runtime complexity of finding the second smallest element is O(1)

true - the second largest element in a min-heap will either be the left or right child of the root

T/F DFS on an undirected graph with n vertices and at least n edges is guaranteed to find at least one back edge.

true - |V|=|E|

What does a quadratic time algorithm mean?

usually 2 for loops

Give an example of an undirected graph G with positive edge weights and a starting vertex s in G for which Dijkstra's and Prim's algorithm visit nodes in different directions

write it out

Prim's Algorithm

(Minimum Spanning Trees, O(E + V log V), where E is number of edges and V is the number of vertices) Starting from a vertex, grow the rest of the tree one edge at a time until all vertices are included. Greedily select the best local option from all available choices without regard to the global structure. - use a priority queue

Kruskal's Algorithm

(Minimum Spanning Trees, O(E log E + EV) with a union find, which is fast for sparse graphs) -adding edges in a sequence of non-decreasing weights, maintains a forest 1. sort edges in non-decreasing order by weight O(ElogE) 2. start with all vertices. each vertex forms a tree 3. choose the min weight edge and join corresponding tree if it does not create a cycle. otherwise discard edge 4. continue to merge trees until all vertices are connected O(EV)

Ch. 6 Exercise 6

- Let OPT[Pi] be the maximum amount of money to gain after taking i-j jobs not violating Si jobs we cannot take -

ch. 6 Exercise 5 Rope problem, rope of n length, find the maximum product of lengths

- Let OPT[Pi] be the maximum product of lengths from cutting the rope of n length, where 1 <= i < n (must cut at least once) -

connected graph vs simple connected graph

- a graph such that there is a path going from any vertex to any other vertex, undirected - simple connected graph contains no self loops, cycles, or multi edges for a set of two vertices, and all vertices are connected by a path

Binary Heap runtime for - build heap - insert - findMax/findMin - decreaseKey

- build heap: O(n) - insert: O(log n) - findMax/findMin: O(1) - deleteMax/deleteMin(log n) - decreaseKey: O(log n)

Binomial heap - findMin - deleteMin - insert - decreaseKey - merge

- findMin: O(1) - deleteMin: O(log n) - insert: O(1) ac - decreaseKey: O(log n) - merge: O(log n)

Suppose a CS curriculum consists of n courses, all of them mandatory. The prerequisite graph G has a node for each course, and an edge from course v to course w if and only if v is a prerequisite for w. Find an algorithm that works directly with this graph representation, and computes the minimum number of semesters necessary to complete the curriculum (assume that a student can take any number of courses in one semester). The running time of your algorithm should be linear.

- first we will run BFS or DFS to determine if this graph has any cycles, if it does contain cycles then we would not be able to run any of the algorithms we have learned so far O(V+E) - run topological sort to get an order of vertices to complete the graph aka courses O(V+E) - iterate over the list of vertices from the topological sort, if the vertex doesn't have any incoming edges the length = 0, if it does have incoming edges then length(v) = max(length(x) + 1) where x is the previous vertex. we will then get semesters = 1+max(length(v)) total cost O(V+E)

Topological order/sort

- if graph is a DAG, there exists a valid order in which you can complete the tasks - not unique - algorithm is based on traversal - run DFS and return a vertex that has no undiscovered leaving edges, O(V+E)

What type of data structure should we use for greedy algorithms?

- unsorted array - priority queue is a better choice, you are able to access the highest-ranking choice in constant time - sorted array

Breadth First Search

- uses a queue to get the next hop, bookkeeping - adjacent vertex of entire level --> next step - resulting MST are short and busy O(V+E)

Depth First Search

- uses a stack, if the vertex is on the stack do not visit yet, backtracking Explore newest unexplored vertices first. Placed discovered vertices in a stack when you get stuck, look at the stack and pop the vertex O(V+E)

What is the difference between Prim's and Dijkstra's algorithm?

-Prim's stores the min edge weight -Dijkstra's stores the min path weight (sum)

You are given an MST T in a graph, G=(V,E). Suppose we add a new edge without adding a new vertex. Creating a new graph G1, device a linear time algorithm to find an MST of G1

-Traverse T and G' at the same time until we hit the new edge - if the new edge isnt hit then it does not effect our MST and it stays the same - if we do hit the new edge and it leads us to a vertex in out original MST that we have not visited, then we add the edge and remove the edge from before because it is a longer path - continue to traverse the rest of the path to make sure it is still connected O(E)

Why does insert in Binomial trees cost O(1)?

-if the heap contains binomial trees of all orders it will take O(log n), however this doesn't always happen -so we apply AC to see what the worst case is - single insertion takes constant time

Amortized Cost

-in a sequence of operations the worst case does not occur often in each operation

What are the two properties that a greedy algorithm must obey?

-optimal substructure: optimal solution to the original problem contains optimal solutions to all of its subproblems, proved by induction -greedy-choice property, proved by contradiction

Given a DAG G, with nonnegative edge weights and the source s, device a linear time algorithm to find the shortest distances from s to all other vertices

-run topological sort 1) Initialize dist[] = {INF, INF, ....} and dist[s] = 0 where s is the source vertex. 2) Create a toplogical order of all vertices. O(V+E) 3) Do following for every vertex u in topological order O(E) ............Do following for every adjacent vertex v of u ..................if (dist[v] > dist[u] + weight(u, v)) ...........................dist[v] = dist[u] + weight(u, v) O(V+E) total: O((V+E)+(V+E)+O(E)) = O(E+V)

What are advantages of D&C algorithms?

-simple proofs of correctness. closely follows inductive proof -efficiency -parallelism: independnce of subproblems

What are the two important properties of traversal

1. it visits all the vertices in the connected component 2. edges labeled by traversal form a tree of the connected component

Master Theorem, case 1, 2, and 3

1. log base b of a > f(n): T(n) = theta (n^log base b of a) 2. log base b of a = f(n) or differ by log n = theta(f(n) +logn) 3. log base b of a < f(n): T(n) = theta(f(n))

Theorem, in any simple connected planar graph with at least 3 avertices, E <= _______

3V-6

T/F Whereas there could be many optimal solutions to a combinatorial optimization problem, the value associated with them will be unique

?

T/F Considering amortized and actual cost analysis of heap operations {insert, extract- min, union, decrease-key, delete-key} on heap data structures we have studied. Actual cost of any operation in a Fibonacci heap data structure takes at most O(log n) time

? AC O(1) for most operations except delete-min? What is the actual cost of any operation?

T/F If a problem can be solved correctly using the greedy strategy, there will only be one greedy choice (such as "choose the object with the highest value to weight ratio") for that problem that leads to the optimal solution

? False - there can be multiple greedy solutions for a problem

Strongly connected graph

A directed graph is strongly connected if there is a path from every node to every other node. - to determine if a graph is strongly connected you need to run traversal from all vertices, O(V(V+E)) = O(V+E) since V+E > V^2

Bipartite graph

A graph consisting of two sets of vertices, X and Y. The edges only join vertices in X to vertices in Y, not vertices within a set.

Sparse graph

A graph in which the number of edges is close to the minimal number of edges. Sparse graphs can be a disconnected E = O(V) ex: facebook

Adjacency Matrix

A matrix which records the number of direct links between vertices - can answer if vertices are adjacent in O(1) time, just look up index - used for dense graphs, E=omega(V^2)

Dijkstra's algorithm

An algorithm for finding the shortest paths between nodes in a weighted graph. it can also be used for finding the shortest paths from a single node to a single destination node by stopping the algorithm once the shortest path to the destination node has been determined. - start at a given vertex s, add to an empty tree T - expand T by adding a vertex from V|T having the min path length from vertex s (GREEDY) - update distances from vertex s to adjacent vertices in V|T (RELAX) - continue until you get all vertices Its time complexity is O(ElogV + VlogV)

If 𝐺 is a simple connected graph, then 𝐸 ≤ 𝑉(𝑉 − 1) /2

Base Case: - V = 1, E = 0 the forumla holds - V = 2, E = 1 the formula holds Inductive Hypothesis: For all V-1 edges the formula holds 𝐸 ≤ 𝑉(𝑉 − 1)/ 2 Inductive Step: -

Planar Graphs

Can be drawn so no edges meet except at vertices.

Consider the following Change problem, the input is an integer L. Output should be the minimum cardinality collection of coins required to make L. Our coins are 1,5,10,20,25,50. What is another type of solution, other than greedy, that can work? What is the runtime

Dynamic Programming - let OPT[c] be the minimum number of coins needed to make integer L. - use DP to create a table that will give us the optimum minimum number to create L

T/F Consider the interval scheduling problem. A greedy algorithm, which is designed to always select the available request that starts the earliest, returns an optimal set A.

False

is it true that 2^f(n) = O(2^(g(n))?

False f(n) = 2n g(n) = n 2n < c*n, if c = 5 however, 2^2n = 4^n > 2^n

T/F Since Fibonacci heaps guarantee amortized cost and not worst case cost, the run time complexity of Dijkstra's algorithm using Fibonacci heaps may be worse than that of a binary heap implementation.

False - For Fibonacci heaps with n entries, the amortized running time of delete min is O(log n) and the amortized running time for decrease key is O(1). Thus for every sequence of extract mins/decrease keys with (A extract mins and B decrease keys in total), the worst case running time is bounded by O(B+A log n). When applied to the implement the priority queue in Dijkstra, A is O(B), that is the number of vertices visited is asymptotically bounded by the number of edges relaxed. A binary heap implementation would take at least Theta(B log n) time since decreasy key takes Theta(log n) time. Thus, the Fibonacci heap implementation is faster even in the worst case.

T/F For a search starting at node s in graph G, the DFS Tree is never as the same as the BFS tree.

False - G being a tree

T/F Any divide and conquer algorithm will run in best case Ω(n log n )time because the height of the recursion tree is at least log n.

False - binary search O(n)

T/F The divide step in the divide and conquer algorithm always takes less time than the combine step, therefore, the complexity of a divide and conquer algorithm is never dependent on the divide step.

False - binary search in a singly liked list the divide time takes longer

T/F Considering amortized and actual cost analysis of heap operations {insert, extract- min, union, decrease-key, delete-key} on heap data structures we have studied. Actual cost of any operation in a Binomial heap data structure takes at most O(log n) time

False - build heap takes O(n) DOUBLE CHECK

T/F Considering amortized and actual cost analysis of heap operations {insert, extract- min, union, decrease-key, delete-key} on heap data structures we have studied. Actual cost of any operation in a Binary heap data structure takes at most O(log n) time

False - build heap takes O(n) all other operations take O(log n) time

T/F Consider a directed graph G in which every edge has a positive edge weight. Suppose you create a new graph G' by replacing the weight of each edge by the negation of its weight in G. For a given source vertex s, you compute all shortest path from s in G' using Dijkstra's algorithm. True or False: the resulting paths in G' are the longest (i.e., highest cost) simple paths from s in G

False - cannot use Dijkstra's with negative edge weights

T/F Implementations of Dijkstra's and Kruskal's algorithms are identical except for the relaxation steps.

False - instance, at a generic stage in Kruskal's we could have multiple disconnected components (a forest) while Dijkstra's always grows a tree.

T/F BFS can be used to find the shortest path between two nodes in a weighted graph

False - it can find the shortest path in an undirected, unweighted graph because it's look for the shortest path from the previous node, it does not consider weight. It can find the shortest path between starting vertex v and another vertex u if unweighted

T/F The amortized cost of a sequence of n operations (i.e. the sum over all operations, of the amortized cost per operation) gives a lower bound on the total actual cost of the sequence

False - it gives the upper bound

T/F The total amortized cost of a sequence of n operations gives a lower bound on the total cost of the sequence?

False - it gives the upper bound, always big O

T/F DFS can be used to find the shortest path between any two nodes in a non-weighted graph.

False - it visits the deeper nodes first, so it doesn't guarantee shortest path between two nodes

T/F Every DAG has only one topological ordering of its vertices

False - topological ordering is not unique

T/F Considering an undirected graph G=(V,E) suppose all edge weights are different. Then the shortest path from A to B is unique

False - you can create a graph where there exists two shortest paths from A to B that equal the same length, therefore it is not unique

T/F let G be a directed weight graph, and let u, v be two vertices. Then a shortest path from u to v remains the shortest path when 1 is added to every edge weight

False, if there are multiple vertices in between u and v that were chosen on the first shortest path by adding 1 we can get a larger path than a path with less veritces

T/F the memoization approach in DP has the disadvantage that sometimes one may solve subproblems that are not really needed

False, this is actually tabulation

T/F A bipartite graph cannot contain a cycle of length 3 or greater.

False. Consider the graph which is also a cycle with 4 vertices. It is bipartite contradicting the assertion in question.

T/F If the vertex set of a weighted undirected graph can be partitioned into two, such that the minimum weight edge crossing the partition is not unique, then the graph has at least two MSTs.

False. Consider the graph with edge set {(a,b),(b,c),(c,d)} where all edge weights are identical. ({a,d},{b,c}) is a partition that does not have a unique minimum weight edge crossing it, however the graph (being a tree) has a unique MST.

Consider the following Change problem, the input is an integer L. Output should be the minimum cardinality collection of coins required to make L. Our coins are 1,5,10,20,25,50. Does the following greedy algorithm solve the problem? -Take as many coins as possible from the highest denomination

It does solve the problem, but it's solution is not optimal in some cases, example: L = 40 greedy algorithm output: 25,10,5 --> 3 coins better solution output: 20,20 --> 2 coins

What is the amortized cost of flipping a bit?

O(2) - constant

What is the runtime of binary search?

O(log n)

What is the worst-case runtime complexity of searching in a binomial heap?

O(log n)

What is the worst-case runtime complexity of finding the largest item in a binary min-heap?

O(n) - traverse the entire min-heap to find the largest item

Comparison based sorting - what is the worst time complexity?

Omega(n log n) operate on the input by comparing pairs of elements, for example mergesort and insertion sort

given a sorted array of frequencies of size n, devise a linear time algorithm for building a huffman tree

Since the array is already sorted we can use two queues -initially enqueue all the nodes into the first queue Q1 in the same order alg: -dequeue the two min values from both queues, follow these steps twice: --if Q1 is empty take from Q2 --if Q2 is empty take from Q1 --else compare the two and dequeue min create a new internal node as the sum of the two min nodes, make the first dequeued node left child and second dequeued right child and enqueue to Q2 - do this until only one node remains

Merge sort

T(n)=2T(n/2)+O(n) O(nlogn) splitting in half, until down to two numbers and sort those two numbers

Suppose we are given an instance of the Shortest Path problem with source vertex s on a directed graph G. Assume that all edges costs are positive and distinct. Let P be a minimum cost path from s to t. Now suppose that we replace each edge cost ce by its square root, ce 1/2 , thereby creating a new instance of the problem with the same graph but different costs. Prove or disprove: P still a minimum-cost s - t path for this new instance.

The statement can be disproved by giving a counterexample as follows. G=(V, E); V={s, a, t}; E={(s, a), (a, t), (s, t)}; cost((s, a))=9; cost((a, t))=16; cost((s, t))=36. It is obvious that the minimum-cost s - t path is s - a - t. By replacing each edge cost ce by its square. root, ce 1/2, the costs become: cost((s, a))=3; cost((a, t))=4; cost((s, t))=6. Now the the minimum-cost s - t path is s - t, not s - a - t anymore

T/F Considering an undirected graph G=(V,E) suppose all edge weights are distinct. Then the shortest edge must be in the minimum spanning tree.

True

T/F given a connected, undirected graph G with distinct edge weights, then the edge e with the second smallest weight is included in the MST

True

T/F Considering an undirected graph G=(V,E) suppose all edge weights are different. Then the MST is unique

True - Suppose there are two minimum trees, 𝐴A and 𝐵B. Let 𝑒e be the edge in just one of 𝐴,𝐵A,B with the smallest cost. Suppose it is in 𝐴A but not 𝐵B. Suppose 𝑒e is the edge 𝑃𝑄PQ. Then 𝐵B must contain a path from 𝑃P to 𝑄Q which is not simply the edge 𝑒e. So if we add 𝑒e to 𝐵B, then we get a cycle. If all the other edges in the cycle were in 𝐴A, then 𝐴A would contain a cycle, which it cannot. So the cycle must contain an edge 𝑓f not in 𝐴A. Hence, by the definition of 𝑒e (and the fact that all edge-costs are different) the cost of 𝑓f must be greater than the cost of 𝑒e. So if we replace 𝑓f by 𝑒e we get a spanning tree with smaller total cost. Contradiction.

T/F Considering an undirected graph G=(V,E) suppose all edge weights are different. Then the longest edge cannot be in the MST

True - any MST algorithm will choose the smallest weight edge

T/F The number of binomial trees in a binomial heap with n elements is at most O(log n).

True - example if we have 31 elements we will have 5 binomial trees in a binary heap which is about log 31 = 5

T/F a greedy algorithm finds an optimal solution by making a sequence of choices and at each decision in the algorithm, the choice that seems best at the moment is chosen

True - it makes the decision that looks like the best choice at that time

T/F every sorting algorithm requires omega(n log n) in the worst case to sort n cases

True - omega(n log n) means lower bound which is true, no sorting algorithm can be faster than n log n

T/F Every DAG has at least one source

True - start at an arbitrary vertex v, and repeatedly go backwards in the graph. If there is no source, you can keep going forever which means a vertex will be visited twice and we have a cycle. Therefore, it cannot be a DAG

T/F if a weighted undirected graph has two MSTs, then its vertex set can be partitioned into two, such that the minimum weight edge crossing the partition is not unique.

True, Let T1 and T2 be two distinct MSTs. Let e1 be an edge that is in T1 but not in T2. Removing e1 from T1 partitions the vertex set into two connected components. There is a unique edge (call it e2) that is in T2 that crosses this partition. By optimality of T1 and T2, both e1 and e2 should be of the same weight and further should be of the minimum weight among all edges crossing this partition .

Given the graph G = (V,E) with nonnegative edge weights and two vertices s and t. Find the shortest path from s to t with an odd number of edges. Algorithm must have a runtime similar to Dijkstra's

Use Dijkstra's but maintain two sets of min distances with even and odd number of edges - once you reach the right vertex choose the path with the even or odd number of edges Given a graph G = (V, E), create a new graph G' = (V', E'), with V' a new set of vertices v_even and v_odd for every vertex v in V and E' the set of vertices as follows: If (u, v) is an edge in G, then (u_odd, v_even) and (u_even, v_odd) are edges in G', with the same weight. Obviously, the new graph has twice as many edges and vertices as the original graph. Now, if you wanted to find the shortest path between s and t in G, simply run Dijkstra's on G' to find the shortest path between s_even and t_even. The running time is still O(|V| log |E|).

Theorem, in an undirected graph G=(V,E), there are at most _____ edges.

V(V-1)/2 edges

In Internet routing, there are delays on lines but also, more significantly, delays at routers. Suppose that in addition to having edge lengths {le : e E}, a graph also has vertex costs {cv : v V}. Now define the cost of a path to be the sum of its edge lengths, plus the costs of all vertices on the path (including the endpoints). Give an efficient algorithm for the following problem. Input: A directed graph G = (V; E); positive edge lengths le and positive vertex costs cv; a starting vertex s V . Output: An array cost such that for every vertex u, cost[u] is the least cost of any path from s to u (i.e., the cost of the cheapest path), under the definition above. Notice that cost[s] = cs.

We will change the input for this problem and define that for every edge (u,v) in E, l(u,v) = l(u,v) + c[v] meaning add the cost of the vertex to that edge from u to v

What does a linear time algorithm mean?

You do something for each item once, for total of n items - O(n)

Suppose you are choosing between the following three algorithms:I) - Algorithm A solves problems by dividing them in constant time into five subproblems of half the size, recursively solving each subproblem, and then combining the solutions in linear time.II) - Algorithm B solves problems of size n by dividing in constant time and recursively solving two subproblems of size n-1 and then combining the solutions in constant time.III) - Algorithm C solves problems of size n by dividing them in constant time into nine subproblems of size n/3, recursively solving each subproblem, and then combining the solutions in O(n2 ) time.What are the running times of each of these algorithms (in big-O notation), and which would you choose?

a = O(n^log base 2 of 5) b = O(2^n) c = O(n^2 log n) choose c


Related study sets

Mastering Ex. 37: Respiratory System Physiology

View Set

DRUGS AFFECTING THE M/F REPRODUCTIVE SYSTEM

View Set

3.2 Multiplexing and De-multiplexingtransport-layer multiplexing and demultiplexing

View Set

Abnormal Psychology: Chapter 7 WSCC

View Set

Barrons GRE Wordlist 4,759 words

View Set

Astronomy-Chapter 3-Lens and Telescopes

View Set