开发者

Transposing on a Directed Graph

开发者 https://www.devze.com 2023-01-25 15:54 出处:网络
I\'ve been assigned the following problem, but am having issues figuring it out. I know what I\'d like to accomplish, but given the skeleton code he\'s outlined for us, I\'m not sure where to start...

I've been assigned the following problem, but am having issues figuring it out. I know what I'd like to accomplish, but given the skeleton code he's outlined for us, I'm not sure where to start...I drew a pic to illustrate what I'd like to accomplish (I think...)

http://i802.photobucket.com/albums/yy304/Growler2009/Transposing-1.jpg

This is what I need to do:

Consider a directed graph G(V;A). The transpose of G written GT (V;AT ) is nothing more than G where all the arcs have been transposed, i.e., the origin of the arc becomes the end and the end becomes the origin. In a sense, GT is the \backward" version of G. For this question you must implement an algorithm which, given a directed graph, produces its transpose. The API of the algorithm is given by the following interface:

public interface Transpose<VT,AT> {
public DIGraph<VT,AT> doIt(DIGraph<VT,AT> src);
}

Implement the transpose algorithm given above. You have no restrictions on how to do this (except that it must operate on a graph represented as an adjacency list and it cannot modify the original graph. Report (in the comments) the space and time complexities in big O notation and brie y justify. (i.e., how long does it take and how much space does it uses to transpose a graph with n vertices and m arcs).

Any help开发者_开发技巧 you can offer to get me started would be great.

Thanks!


in pseudolanguagecode:

create new empty set of edges E
for I in all edges:
    (X,Y) = vertices of edge I ;
    insert edge (Y,X) to E;
result is in E.

Space complexity: no requirements

Time complexity: O(num. of edges)

0

精彩评论

暂无评论...
验证码 换一张
取 消