Problem Statement
Series-parallel graphs are defined inductively as follows. The simplest kind is denoted (quotes for clarity) "~" and is depicted below.
Definition
- Class:
- SPGraph
- Method:
- getString
- Parameters:
- String[], int, int
- Returns:
- String
- Method signature:
- String getString(String[] graph, int source, int sink)
- (be sure your method is public)
Notes
- As with ASCII, 'P' comes before 'S' which comes before '~'.
Constraints
- graph will contain between 2 and 50 elements inclusive.
- Each element of graph will contain exactly N characters, where N is the number of elements in graph.
- Each character in graph will be 'Y' or 'N'.
- Character i in element i of graph will always be 'N'.
- Character i in element j of graph will equal character j in element i.
- source will be between 0 and N-1 inclusive, where N is the number of elements in graph.
- sink will be between 0 and N-1 inclusive, where N is the number of elements in graph.
- source will not equal sink.
- The given graph will be series-parallel using the given source and sink.
Examples
{ "NY", "YN" }0
1
Returns: "~"
Depicted above.{ "NYN", "YNY", "NYN" }0
2
Returns: "S~~"
Depicted above.{ "NYY", "YNY", "YYN" }0
2
Returns: "PS~~~"
Depicted above.{ "NYNY", "YNYN", "NYNN", "YNNN" }2
3
Returns: "SS~~~"
The graph is depicted below with the vertices numbered.{ "NYYNNNNNNN", "YNNYNNNNNN", "YNNYNNNNNN", "NYYNYYNNNN", "NNNYNNYNNN", "NNNYNNYNNN", "NNNNYYNYYN", "NNNNNNYNNY", "NNNNNNYNNY", "NNNNNNNYYN" }0
9
Returns: "SPS~~S~~SPS~~S~~PS~~S~~"
The graph is depicted below with the vertices numbered.{ "NYNNNNNYY", "YNYNNYYNN", "NYNYYNNNN", "NNYNYNNNN", "NNYYNNYNN", "NYNNNNYNN", "NYNNYYNNY", "YNNNNNNNY", "YNNNNNYYN" }0
8
Returns: "PPSS~PPSS~PS~~~~S~~~~S~~~"
{ "NYNNYNN", "YNNYNNN", "NNNYNYY", "NYYNNNN", "YNNNNNY", "NNYNNNY", "NNYNYYN" }3
1
Returns: "PSSSS~PS~~~~~~~"