Basic idea in making a graph???

I am taking data structure subject on my university. And I got an assignment to make a graph with vertices and edges. And I don't know where to start. Can anyone give me the basic idea on how to implement it so that I can start writing my own code? Thank you.
Are you supposed to do this in console?
Basicly you implement a structure or class containing tuples to represent a graph. I mean, thats what you mathematicly do, or not?

Maikel
closed account (1yR4jE8b)
You could use an adjancency matrix. Basically, you have a two dimensional array of n by n size. Each index [i][j] represents a connection between the edge i and j. If index [i][j] is 0, there is no connection. If [i][j] is >= 1, then there is a connection. Usually a number higher than 1 indicates a 'cost' to travel between those two edges. If you do not need to have costs to travel between edges, than an array of bool types should be sufficient (true for connection, false for none)If it is an undirected graph, then you must set [i][j] to the same value as [j][i]. If you can have different directions in the graph then [i][j] can be different than [j][i].

There is also an adjacency list implementation, where every vertex is represented by a node linked to whichever nodes it is connected to in a list.

These are all things your prof. should have covered in class already. Then again, I've had some horrible profs as well.
Last edited on
I am supposed to make the graph and then print it in the adjacency matrix.

Anyway, I finally understand what I have to do after getting some help from here and there.
Thank you.
Topic archived. No new replies allowed.