Open a map app in Dhaka and ask for the way from Farmgate to Motijheel. In a second a route appears, and if a road is blocked the app quietly draws another one. Now open Facebook. It suggests "People you may know": someone you have never met, who shares three friends with you. The two apps do very different jobs, yet a programmer sees the same picture under both, dots joined by lines. On the map the dots are junctions and the lines are roads. On Facebook the dots are people and the lines are friendships. The links between web pages, the flights of Biman, the power lines between the substations of a district: all of them are the same picture.
In the last few chapters we kept data in lines (arrays, lists, stacks, queues) and in trees (the search tree, AVL, the heap). A tree has a strict rule: from the top there is exactly one way to any node, and you can never walk in a circle. Roads and friendships do not obey it. There are many ways from Farmgate to Motijheel, and a friend of a friend of a friend can be you. Drop the rule and what is left is the most general structure in this subject, the graph. Every list and every tree is just a graph with a rule added; in this chapter we work without the rule.