• Просмотров 954
  • Скачиваний 188
  • Размер файла 6

Московский Государственный Университет им. Циолковского Студент : Заливнов Олег Группа : 5МС-II-23 Лекция : 8 Тема : Деревья TREES Plan: 1) The tree presenation of data constructions. 2) What is tree? a) definition b) the terminology c) types of trees 3) Tree applications in encoding systems. Elementar data can have different types (string,integer and so on). But if to talk about complex data construction - it have no type. Complex data constructions consist of simple data, and CDC are stored as data searching algorithm. and that is why CDC are the "selectors" - mechanism of searching and accesing of data. Such kinds of data as complex data constructions are need to

organize search. We can describe CDC in different ways. For example we can describe it in the way as it described in the programming language Cobol : 1 University 2 (first fac.) 2 (second fac.) 2 (third fac.) 2 (fourth fac.) 2 fifth fac. 3 PM 4 (Pasha) 4 (Andrey) 3 IT 4 (Zhenia) 4 (Olga) 3 MS 4 (Oleg) 4 (Helen) 4 (Artem). Where the word in brackets (e.g. (Oleg) means the elementary data construction). The most powerful way of description a CDC is a tree. NOW WHAT IS TREE ? Tree is a connected undirected graph with no simple circuits. So a tree cannot contain multile edges or loops, and so tree is a simple graph. Example 1 : D ─────────── A

──────────── C │ │ │ │ │ │ │ B ──── F │ │ │ E H ──── G ───── I ───── J this is a tree ; Example 2 : E ────────── A ────────── B │ │ │ │ │ │ F D─────────── C it is not the tree, because path A-B-C-D is a loop; Example 3 : A ─────── B │ D

────┼──── E ────── F │ C it is not the tree too because this graph is not connected; Also we can select a special vertex and call it a root and assign the direction to each edge. And we call such tree a ROOTED tree. Example 4 : A ──── B A ─── B A ─── B │ │ │ │ D ──── C ──── G D ─── C ─── G D ─── C ─── G │ │ │ │ │ │ │ │ F H F H F H a)Unrooted tree . b) Rooted tree c) Rooted tree with root A . with root C . The unique vertex A is called

PARENT of vertex B if there is a directed edge from A to B. When vertex A is parent of vertex B, vertex B is called a CHILD of vertex A. Vertices with the same parent are called SIBLINGS. The ANCESTORS of a vertex other then th eroot are the vertices in the path from root to this vertix, excluding the vertex itself (that is its parents, parents of its parents and so on...). The DESCENDANTS of a vertex A are those vertices which have A as an ancestor. If a vertex of a tree has no children it is calle a LEAF. If a vertex has children it is called INTERNAL VERTEX. If A is a vertex in a tree, the subgraph of a tree which consists of A and all its descendants and all edges incident to these descendants is called a SUBTREE with a root A. Example 5 : A ─── B │ D