Graphs are the data structures which are defined as of a set of nodes and a set of edges that connect those nodes. Nodes in a graph are often called vertexes (sometimes vertexes are referred to as nodes or points).

In graph theory, graphs are expressed as G = {E, V} where E is the finite set of edges and V is the finite set of vertexes. Graphs can be directed or undirected. Two vertexes a and b are called adjacent if (a,b) is an edge.

A number of data structures can be chosen to represent a graph. The appropriate choice should be based on the problem definition and on the operation that should be applied to the edges and vertexes.

The two most common representations for graphs are adjacency matrix and adjacency list. Adjacency matrix is an NxN boolean matrix, where N is the number of vertexes in the graph. At this point it is important to mention that a graph is an advanced data structure. You won’t see it very often in the interview questions. But if you are interviewing for a lead or architect position, you certainly should be prepared to solve graph problems.

The example of graph can be internet there all computers are connected into the network.


Answers and Comments

100 Common Interview Questions, audio book