Trees
From Wikibooks, open books for an open world
< Alevel Computing  AQA  Problem Solving, Programming, Operating Systems, Databases and Networking  Programming Concepts
Trees  A tree is a connected undirected graph with no cycles.
Connected means that every node is connected to at least one other node. Undirected means there is no direction associated with an edge, i.e. lines are used, not arrows. A cycle is a circuit (a succession of edges that start and end at the same vertex) in which all the edges are different and all the vertices visited are different (apart from the start and end vertex).
A rooted tree is a tree in which one vertex has been designed as the root and every edge is directed away from the root.
Exercise: Unordered Binary Trees

Exercise: Ordered Binary Trees
Create a binary tree for the following data input: 5, 2, 6, 8, 4, 1, 9, 7, 3 Create a binary tree for the following major city input: Monaco, Paris, Vatican, Rome, Norwich, Lewisham, New York, Partington Create a binary tree for the following list of animals: Elephant, Cat, Dog, Hippo, Giraffe, Lion, Bear Answer : 