Check if graph is connected











up vote
-1
down vote

favorite












I need to make a program where I got an input file then make a graph of it and check if it's connected.



For example (the input file):
R - root
L - leafs (can be G - green or B - brown)
N - nuts (R - ripe or U - unripe)




1;R;2;3

2;R;4

3;L;G

4;N;U




And the output file should be:



if the tree is connected




S: Connected

L;Z;1
L;H;0
O;Z;0
O;N;1




if the tree is not connected




S: Not Connected




This is what I got so far



public class Main {
public static void main(String args) throws IOException {
FileReader fileReader = null;
try {
fileReader = new FileReader("input.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(fileReader);
String strLine = bufferedReader.readLine();
// Repeat until there's no more lines to read
while (strLine != null) {
String values = strLine.split(";");
Tree treeId = new Tree(values[0]);
Tree next = new Tree(values[1]);


Tree.class



 public class Tree {
String data = null;
public Tree(String data) {
this.data = data;
}


Please help me.










share|improve this question
























  • The above code may not be related to the algorithm as such. Can you post the core algorithm you tried?
    – Sid
    yesterday










  • @Sid I don't have it, that's why I need your help
    – TheDumbest
    yesterday










  • There are graph libraries for Java that implement algorithms like connectivity checks ... use JGraphT and map you data to a Graph - then use the corresponding algorithm. Those algorithms have been tested
    – AKSW
    yesterday












  • I understand. The hope at StackOverflow is to help people find issues in their programs rather than provide complete solutions to tasks. As AKSW mentioned, it may help to refer to libraries.
    – Sid
    yesterday










  • Just run a simple DFS/BFS from a single node and check if all nodes are visited. If so, graph is connected.
    – Maras
    yesterday

















up vote
-1
down vote

favorite












I need to make a program where I got an input file then make a graph of it and check if it's connected.



For example (the input file):
R - root
L - leafs (can be G - green or B - brown)
N - nuts (R - ripe or U - unripe)




1;R;2;3

2;R;4

3;L;G

4;N;U




And the output file should be:



if the tree is connected




S: Connected

L;Z;1
L;H;0
O;Z;0
O;N;1




if the tree is not connected




S: Not Connected




This is what I got so far



public class Main {
public static void main(String args) throws IOException {
FileReader fileReader = null;
try {
fileReader = new FileReader("input.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(fileReader);
String strLine = bufferedReader.readLine();
// Repeat until there's no more lines to read
while (strLine != null) {
String values = strLine.split(";");
Tree treeId = new Tree(values[0]);
Tree next = new Tree(values[1]);


Tree.class



 public class Tree {
String data = null;
public Tree(String data) {
this.data = data;
}


Please help me.










share|improve this question
























  • The above code may not be related to the algorithm as such. Can you post the core algorithm you tried?
    – Sid
    yesterday










  • @Sid I don't have it, that's why I need your help
    – TheDumbest
    yesterday










  • There are graph libraries for Java that implement algorithms like connectivity checks ... use JGraphT and map you data to a Graph - then use the corresponding algorithm. Those algorithms have been tested
    – AKSW
    yesterday












  • I understand. The hope at StackOverflow is to help people find issues in their programs rather than provide complete solutions to tasks. As AKSW mentioned, it may help to refer to libraries.
    – Sid
    yesterday










  • Just run a simple DFS/BFS from a single node and check if all nodes are visited. If so, graph is connected.
    – Maras
    yesterday















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I need to make a program where I got an input file then make a graph of it and check if it's connected.



For example (the input file):
R - root
L - leafs (can be G - green or B - brown)
N - nuts (R - ripe or U - unripe)




1;R;2;3

2;R;4

3;L;G

4;N;U




And the output file should be:



if the tree is connected




S: Connected

L;Z;1
L;H;0
O;Z;0
O;N;1




if the tree is not connected




S: Not Connected




This is what I got so far



public class Main {
public static void main(String args) throws IOException {
FileReader fileReader = null;
try {
fileReader = new FileReader("input.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(fileReader);
String strLine = bufferedReader.readLine();
// Repeat until there's no more lines to read
while (strLine != null) {
String values = strLine.split(";");
Tree treeId = new Tree(values[0]);
Tree next = new Tree(values[1]);


Tree.class



 public class Tree {
String data = null;
public Tree(String data) {
this.data = data;
}


Please help me.










share|improve this question















I need to make a program where I got an input file then make a graph of it and check if it's connected.



For example (the input file):
R - root
L - leafs (can be G - green or B - brown)
N - nuts (R - ripe or U - unripe)




1;R;2;3

2;R;4

3;L;G

4;N;U




And the output file should be:



if the tree is connected




S: Connected

L;Z;1
L;H;0
O;Z;0
O;N;1




if the tree is not connected




S: Not Connected




This is what I got so far



public class Main {
public static void main(String args) throws IOException {
FileReader fileReader = null;
try {
fileReader = new FileReader("input.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(fileReader);
String strLine = bufferedReader.readLine();
// Repeat until there's no more lines to read
while (strLine != null) {
String values = strLine.split(";");
Tree treeId = new Tree(values[0]);
Tree next = new Tree(values[1]);


Tree.class



 public class Tree {
String data = null;
public Tree(String data) {
this.data = data;
}


Please help me.







java graph-theory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Dominique Fortin

1,433816




1,433816










asked yesterday









TheDumbest

13




13












  • The above code may not be related to the algorithm as such. Can you post the core algorithm you tried?
    – Sid
    yesterday










  • @Sid I don't have it, that's why I need your help
    – TheDumbest
    yesterday










  • There are graph libraries for Java that implement algorithms like connectivity checks ... use JGraphT and map you data to a Graph - then use the corresponding algorithm. Those algorithms have been tested
    – AKSW
    yesterday












  • I understand. The hope at StackOverflow is to help people find issues in their programs rather than provide complete solutions to tasks. As AKSW mentioned, it may help to refer to libraries.
    – Sid
    yesterday










  • Just run a simple DFS/BFS from a single node and check if all nodes are visited. If so, graph is connected.
    – Maras
    yesterday




















  • The above code may not be related to the algorithm as such. Can you post the core algorithm you tried?
    – Sid
    yesterday










  • @Sid I don't have it, that's why I need your help
    – TheDumbest
    yesterday










  • There are graph libraries for Java that implement algorithms like connectivity checks ... use JGraphT and map you data to a Graph - then use the corresponding algorithm. Those algorithms have been tested
    – AKSW
    yesterday












  • I understand. The hope at StackOverflow is to help people find issues in their programs rather than provide complete solutions to tasks. As AKSW mentioned, it may help to refer to libraries.
    – Sid
    yesterday










  • Just run a simple DFS/BFS from a single node and check if all nodes are visited. If so, graph is connected.
    – Maras
    yesterday


















The above code may not be related to the algorithm as such. Can you post the core algorithm you tried?
– Sid
yesterday




The above code may not be related to the algorithm as such. Can you post the core algorithm you tried?
– Sid
yesterday












@Sid I don't have it, that's why I need your help
– TheDumbest
yesterday




@Sid I don't have it, that's why I need your help
– TheDumbest
yesterday












There are graph libraries for Java that implement algorithms like connectivity checks ... use JGraphT and map you data to a Graph - then use the corresponding algorithm. Those algorithms have been tested
– AKSW
yesterday






There are graph libraries for Java that implement algorithms like connectivity checks ... use JGraphT and map you data to a Graph - then use the corresponding algorithm. Those algorithms have been tested
– AKSW
yesterday














I understand. The hope at StackOverflow is to help people find issues in their programs rather than provide complete solutions to tasks. As AKSW mentioned, it may help to refer to libraries.
– Sid
yesterday




I understand. The hope at StackOverflow is to help people find issues in their programs rather than provide complete solutions to tasks. As AKSW mentioned, it may help to refer to libraries.
– Sid
yesterday












Just run a simple DFS/BFS from a single node and check if all nodes are visited. If so, graph is connected.
– Maras
yesterday






Just run a simple DFS/BFS from a single node and check if all nodes are visited. If so, graph is connected.
– Maras
yesterday



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237877%2fcheck-if-graph-is-connected%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237877%2fcheck-if-graph-is-connected%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation