Chapter 4: Q2E (page 132)
Just like the previous problem, but this time with the Bellman-Ford algorithm.
Short Answer
The table that illustrates the Bellman-Ford algorithm’s values:
Chapter 4: Q2E (page 132)
Just like the previous problem, but this time with the Bellman-Ford algorithm.
The table that illustrates the Bellman-Ford algorithm’s values:
All the tools & learning materials you need for study success - in one app.
Get started for freeYou are given a directed graph with (possibly negative) weighted edges, along with a specific node and a tree . Give an algorithm that checks whether T is a shortest-path tree for G with starting point s . Your algorithm should run in linear time.
Professor F. Lake suggests the following algorithm for finding the shortest path from node to node t in a directed graph with some negative edges: add a large constant to each edge weight so that all the weights become positive, then run Dijkstra’s algorithm starting at node s , and return the shortest path found to node t .
Is this a valid method? Either prove that it works correctly, or give a counterexample.
Section 4.5.2 describes a way of storing a complete binary tree of n nodes in an array indexed by 1, 2, K, n .
(a) Consider the node at position j of the array. Show that its parent is at position and its children are at 2 jand 2 j + 1 (if these numbers are ).
(b) What the corresponding indices when a complete d-ary tree is stored in an array?
Figure 4.16 shows pseudocode for a binary heap, modeled on an exposition by R.E. Tarjan. The heap is stored as an array , which is assumed to support two constant-time operations:
The latter can always be achieved by maintaining the values of as an auxiliary array.
(c) Show that themakeheapprocedure takesO(n) time when called on a set of elements. What is the worst-case input? (Hint:Start by showing that the running time is at most ).
(d) What needs to be changed to adapt this pseudocode to d-ary heaps?
You are given a strongly connected directed graph with positive edge weights along with a particular . Give an efficient algorithm for finding shortest paths between all pairs of nodes, with the one restriction that these paths must all pass through .
Squares.Design and analyse an algorithm that takes as input an undirected graph G(V,E) and determines whether graph contains a simple cycle (that is, a cycle which doesn’t intersect itself) of length four. Its running time should be at most time.
You may assume that the input graph is represented either as an adjacency matrix or with adjacency lists, whichever makes your algorithm simpler.
What do you think about this solution?
We value your feedback to improve our textbook solutions.