0

How to implement BFS (Breadth First Search) and DFS (Depth First Search) using an adjacency matrix if the vertices in the graph are specified in string format (not integer)? Available code: https://github.com/surbacim/graph-c-/blob/main/graph

Adam
  • 1
  • 1
  • Store the vertices in a vector and use the index numbers in the search code. – ravenspoint Oct 07 '21 at 16:55
  • @ravenspoint I need exactly using adjacency matrix, no vectors – Adam Oct 07 '21 at 17:00
  • Read the the data from the matrix to populate the vector, then use the vector in the standard search code. – ravenspoint Oct 07 '21 at 17:51
  • @ravenspoint Sorry, but it is possible to do it using only the adjacency matrix? :) Like public static void BFS (int [,]adj, Vertice start) { ... if (adj [start] [i] == 1 && (! Visited [i])) { DFS (i, visited); ... } – Adam Oct 07 '21 at 18:11
  • I suppose it may be, but why bother? A simple transformation of your data gives you access to tested and high performance code. Brewing your own code to pick away at an awkward data structure will be time consuming, error prone and the result will have poor performance. You are barking up the wrong tree. – ravenspoint Oct 07 '21 at 18:24

0 Answers0