简体   繁体   中英

Transposing on a Directed Graph

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, ie, 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. (ie, 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM