Zharlykasov B.J. master Abatov N. T. PhD, Associate Professor A. Baitursynov Kostanai State University Kazakhstan, Kostanay BINARY AND RED - BLACK TREES. TIME SEARCH
Nowadays, computerization of the time, we, programmers, often meet with objects of different types in large quantities; whether it be numbers, strings, arrays, and others. When using such data are faced with the problem of sorting the data and search among them. In order to be able to quickly insert and remove objects from the list, the data will be ideal struktruroy tree - map (usually speak and tree -card).
Most programming languages provide built-in support for working with trees - map, such as the class Java TreeSet / TreeMap, as well as the Standard Template Library to work with sets (set) in C ++, but - for the common use, is not quite easy to understand, like all the same, these commands work.
To begin, consider the general concepts used when working with wood, as well as the terms. Just for comparison, consider binary search trees, which, although they are perfectly sorted, but still do not provide effective search and insert new elements. And, of course, look at the red - black trees, which are a kind of binary search trees.
The tree is a data structure that represents the data in a hierarchy. It connects each object to a node in the tree and supports parent / child relationships between the nodes. Any tree node should be designated the root, which is neither whose descendant, and is the starting node to the other end of the tree contain the end nodes of the tree. The maximum depth of any node in the tree is called the height.
A binary tree - a tree with one additional restriction - elements in the tree is stored in a specific order. Formally, each node in a binary search tree has two subtrees, if not available, a node is considered to be zero. All elements in the left subtree is less than the root, and accordingly, the root of fewer elements in the right subtree (Figure 1).
Figure 1. A binary search tree For the use of sets and maps enough to make a detour elements in order. Bypass produced in a binary search tree from left to right are known as symmetrical tree traversal. In the tree, where each node has a value and two pointers to the left and right subtrees balanced bypass can be done as follows: Procedure simmetr_travers(Node n) if(n == nil) return;
simmetr_travers (n.left_subtree);
Print(n.value);
simmetr_travers (n.right_subtree);
simmetr_travers (root);
When adding a new node in a binary search tree, a new node will always be a leaf in a tree, and the insertion should focus on the root of the tree. If the new value of the node is less than the current value of the node, then go to the left - if it is more, then go straight. Reaching the last leaf node, attach the unit to the left edge of the sheet.
Consider an example where you want to insert a node with a value = 4 in the BJP, in Figure 1. To do this, take the following steps:
1. Let the root = 5 is the current node
2. Because the new node is less than the current node, we go to the left, and set as the current node
3. Now a new node greater than the current node, we go directly to the right side, the current node = 3
4. Thus, the reach of the sheet and attach a new node on the right side of the sheet. The tree will look like this:
In general, there are three cases to remove the node n of the binary search
tree.
1. If n has no children, then remove n from the tree (Figure 2)
2. If n is one subtree, we remove n and connect with the parent subtree n n (Figure 3).
3. If n is 2 subtree, then perform the following steps (Figure 4):
a) Find the smallest unit, which would be more than the n, call it m;
b) Remove the m of wood;
c) Replace the n values for m.
Figure 2. Removing the unit, method 1
Figure 3. Removing the unit. method 2
Figure 4. Removing the unit. method 3
When searching for a specific item in a binary search tree, we use elementary navigation, that is, starting from the root of the tree go to the left, if the current node element is more than looking for, otherwise, go to the right. In any case the time element in the tree search operation is performed in O (h), where h-height of the tree. From the above it can be concluded that in the worst case of adding the elements in the tree, it can appear as a linked list, in this case, the element will seek time O (N), where N - number of nodes in the tree.
To avoid such problems, consider a red - black tree.
Red - black trees are a modified kind of binary tree that can keep the balance, while not affecting the complexity of primitive operations. This occurs by staining each node in a red or black while maintaining a set of properties that ensure the best path in the tree depth not greater than twice the shortest.
Red - black tree is a binary search tree with the properties:
a) Each node has a red color. Either black
b) All the leaves (zero nodes) painted black
c) Both the descendant of every red node - black.
d) Every simple path from a given node to any leaf node, being a descendant of his, contains the same number of black nodes. [3]
Figure 5. Red - Ebony Inserting elements in red - black tree consists of two steps:
1. Plain insert an element in a binary search tree
2. Fixing the violation at the time of adding a new element, the re-painting of some nodes.
That is, the total process time is O (log n). Figure 6 shows a tree before and after insertion of the element with the value "4"
о о о о
Figure 6. Insert unit in the red tree -Black When removing made the same steps as for adding a new element. And so the total time for the removal process takes O (log N) time, which meets the requirements of the complexity of primitive operations.
So, during the operation it was found that when working with pre-sorted data, that is, the input data is already arranged in order, the operation speed of binary search trees are much faster than the speed red-black tree, but also revealed that by removing and adding items in the initial array data through rotational operations red-black tree, to work with them much easier.
Bibliography:
1.A. Michael Berman Data Structures via C++: Objects by Evolution OUP: USA 1997, - 496 p.
2.E.Horowitz, S.Sahni, D.P. Mehta Fundamentals in Data Structures in C++, Second Edition, Silicon Pr 2006 - 694 p
3. https://class.coursera.org/algo-004/lecture/76
Абдулина Е.Г. аспирант
кафедра «Бухгалтерского учета и экономического анализа»
Магнитогорский государственный технический университет им. Г.И. Носова
Россия, г. Магнитогорск СПЕЦИФИКА, ПОНИМАЯ СВК ДЛЯ СТРАХОВЫХ КОМПАНИЙ:
ТЕОРИЯ И ПРАКТИКА Статья посвящена системе внутреннего контроля в отечественных страховых организациях. Специфика понимания, теория и практика. Данная тема актуальна тем, что современное законодательство требует внедрения системы внутреннего контроля в страховых организациях. В настоящее время нет конкретного алгоритма построения и работы системы внутреннего контроля в страховых организациях
Ключевые слова: Системы внутреннего контроля, страхование, внутренний контроль.
The article is devoted to the internal control system in the domestic insurance companies. Specificity of understanding, theory and practice. This topic is relevant in that modern legislation requires the implementation of the internal