Chart / Data Algorithm in Java

I am working on the following problem: I have a CSV file with two columns, we can say that the submitted names are “Friends”. Both columns contain letters from A to Z. for example.

A B
B C
A E
D F
E F

Each line has two different letters (no duplication in the line). A is a friend of B, C is a friend of D, etc. If person A is talking to person B and person B, talking to person C, then B and C will become adjacent. Aquintaces are those who have a common friend. I need to guess who has the most chords?

I tried to use two different methods, using different data structures such as hashmap, arraylist, stack, etc., and the other using graph theory (JGraphT library). But I adhere to the logic if I use data strcutres, and I adhere to the graph traversal if I use graph theory.

I have the following questions: -

  • Which is better for data structures or graphics? Or any other better approach / logic / algorithm than this?
  • Does anyone know how to navigate a chart in the JgraphT library. I am not able to do this, they have very limited documentation on the library.

Please any help would be really appreciated.

+3
source share
2 answers

HashMaps . , - , , , - - -, .

, . .csv HashMap , .

+1

-, , . A {B}, B {C}, Z Y W, Z {Y, W}. - .

, -. A → {B, C, F}, B, C, F. ( ) ( ) A , A . - A. .

0

All Articles