Bağli li̇steler (Linked List) – Yiğinlar (Stack) - Kuyruklar Konu Anlatımı Ömer Özselçuk
Bu sunumda Bağlı Listeler (linked list), Yığınlar (stack), kuyruk veri yapısı (QUEUES) konu anlatımı yapılmış. Örnek C kodları ve örnek algoritmalar ile anlatım desteklenmiştir.
Bağlı Liste (Linked List) Nedir?
Dizilerden sonra en çok kullanılan veri yapısıdır.
Doğrusal Liste (Linear List) yapısı yalnızca öncelik - sonralık ilişkisini yansıtabilecek yapıdadır.
Yığın Veri Yapısı Nedir ( Stack Data Type)
Nesne ekleme ve çıkarmalarının en üstten (top) yapıldığı veri yapısına stack (yığın) adı verilir.
QUEUES (KUYRUK) Veri Yapısı
Kuyruk veri yapısında da veri ekleme (enqueue) ve kuyruktan veri çıkarma (dequeue) şeklinde iki tane işlem tanımlıdır.
Yığınların tersine FIFO (First In First Out) prensibine göre çalışırlar ve ara elemanlara erişim doğrudan yapılamaz.
Tree is a non-linear data structure that can represent hierarchical relationships. It consists of nodes connected by edges. The root node has child nodes, and nodes may be leaf nodes or have child nodes themselves. Binary trees restrict nodes to having at most two children. General trees can be converted to binary trees by making the first child the left child and next siblings the right child. Binary trees can be built from input data by comparing values to determine left or right placement, or from traversal operations.
The document discusses various tree data structures and algorithms related to binary trees. It begins with an introduction to different types of binary trees such as strict binary trees, complete binary trees, and extended binary trees. It then covers tree traversal algorithms including preorder, inorder and postorder traversal. The document also discusses representations of binary trees using arrays and linked lists. Finally, it explains algorithms for operations on binary search trees such as searching, insertion, deletion and rebalancing through rotations in AVL trees.
Red-black trees are a self-balancing binary search tree data structure. They follow several properties including: 1) every node is either red or black, 2) the root is black, 3) every leaf node is black, 4) if a node is red then both its children are black, and 5) for each node, all simple paths from the node to descendant leaf nodes contain the same number of black nodes. Rotations are used to maintain these properties during insertions and deletions. Inserting a new node involves finding the appropriate position and may require recoloring nodes and performing rotations to ensure the red-black tree properties are satisfied. Insertion takes O(log n) time.
red black tree definition,operation,searching,insertion into red black tree,left child,right child,parent,color,key,red,black,nodes,correction,sibling,binary search tree,deletion for red black tree
B-Trees are tree data structures used to store data on disk storage. They allow for efficient retrieval of data compared to binary trees when using disk storage due to reduced height. B-Trees group data into nodes that can have multiple children, reducing the height needed compared to binary trees. Keys are inserted by adding to leaf nodes or splitting nodes and promoting middle keys. Deletion involves removing from leaf nodes, borrowing/promoting keys, or joining nodes.
This document provides an overview of NoSQL databases and compares them to relational databases. It discusses the different types of NoSQL databases including key-value stores, document databases, wide column stores, and graph databases. It also covers some common concepts like eventual consistency, CAP theorem, and MapReduce. While NoSQL databases provide better scalability for massive datasets, relational databases offer more mature tools and strong consistency models.
The document discusses binary search trees and their operations. It defines key concepts like nodes, leaves, root, and tree traversal methods. It then explains how to search, insert, find minimum/maximum elements, and traverse a binary search tree. Searching a BST involves recursively comparing the target key to node keys and traversing left or right. Insertion finds the appropriate position by moving pointers down the tree until reaching an empty node.
1) Trees are hierarchical data structures that store data in nodes connected by edges. They are useful for representing hierarchical relationships.
2) Binary search trees allow quick search, insertion, and deletion of nodes due to the organizational property that the value of each node is greater than all nodes in its left subtree and less than all nodes in its right subtree.
3) Common tree traversal algorithms include preorder, inorder, and postorder traversals, which visit nodes in different orders depending on whether the left/right children or root is visited first.
A red-black tree is a self-balancing binary search tree where each node is colored red or black. It provides logarithmic time bounds for search, insert, and delete operations. It achieves self-balancing by restricting the number of red nodes along any path, ensuring that no path is more than twice as long as any other path. Rotations are used during insertion and deletion operations to rebalance the tree and maintain these properties.
The document discusses different types of tree data structures, including general trees, binary trees, binary search trees, and their traversal methods. General trees allow nodes to have any number of children, while binary trees restrict nodes to having 0, 1, or 2 children. Binary search trees organize nodes so that all left descendants are less than the parent and all right descendants are greater. Common traversal orders for trees include preorder, inorder, and postorder, which differ in whether they process the root node before or after visiting child nodes.
non linear data structure -introduction of treeSiddhi Viradiya
The document defines trees and binary trees. A tree consists of nodes connected by branches, with one root node and zero or more subtrees. A binary tree restricts each node to have at most two children. The document discusses tree terminology like root, child, parent, leaf nodes. It also covers tree traversal methods like preorder, inorder and postorder. Finally, it shows how to construct a binary tree from its traversals.
The right read optimization is actually write optimizationjames tong
Fractal Tree indexes provide a way to optimize both reads and writes for large, growing datasets. They achieve this by combining aspects of log-structured merge trees (LSM trees) and B-trees - buffering data during writes like LSM trees to batch inserts, but maintaining a B-tree structure for efficient queries. This allows fractal tree indexes to have very fast insertion performance like LSM trees while also supporting fast queries like B-tree indexes. However, fractal tree indexes do introduce more complexity in the tree structure that can make concurrency more difficult.
This document discusses binary trees and binary search trees. It defines key tree terms like root, child, parent, leaf nodes. It explains tree traversal methods like preorder, inorder and postorder. It also covers basic BST operations like insertion, search and deletion of nodes. Code snippets are provided to implement these operations and traversal methods on a sample binary search tree. Examples of traversing a sample tree in different orders are given.
stack and queue array implementation in java.CIIT Atd.
This document discusses stack and queue data structures. It provides code examples in Java to demonstrate push and pop operations in a stack and enqueue and dequeue operations in a queue using arrays. Key aspects covered include LIFO and FIFO behavior, stack and queue operations, and sample code to implement stacks and queues in Java with output examples.
This document defines and describes trees and graphs as non-linear data structures. It explains that a tree is similar to a linked list but allows nodes to have multiple children rather than just one. The document defines key tree terms like height, ancestors, size, and different types of binary trees including strict, full, and complete. It provides properties of binary trees such as the number of nodes in full and complete binary trees based on height.
Linked List Static and Dynamic Memory AllocationProf Ansari
Static variables are declared and named while writing the program. (Space for them exists as long as the program, in which they are declared, is running.) Static variables cannot be created or destroyed during execution of the program in which they are declared.
Dynamic variables are created (and may be destroyed) during program execution since dynamic variables do not exist while the program is compiled, but only when it is run, they cannot be assigned names while it is being written. The only way to access dynamic variables is by using pointers. Once it is created, however, a dynamic variable does contain data and must have a type like any other variable. If a dynamic variable is created in a function, then it can continue to exist even after the function terminates.
Linked Linear List
We saw in previous chapters how static representation of linear ordered list through Array leads to wastage of memory and in some cases overflows. Now we don't want to assign memory to any linear list in advance instead we want to allocate memory to elements as they are inserted in list. This requires Dynamic Allocation of memory and it can be achieved by using malloc() or calloc() function.
But memory assigned to elements will not be contiguous, which is a requirement for linear ordered list, and was provided by array representation. How we could achieve this?
Bağli li̇steler (Linked List) – Yiğinlar (Stack) - Kuyruklar Konu Anlatımı Ömer Özselçuk
Bu sunumda Bağlı Listeler (linked list), Yığınlar (stack), kuyruk veri yapısı (QUEUES) konu anlatımı yapılmış. Örnek C kodları ve örnek algoritmalar ile anlatım desteklenmiştir.
Bağlı Liste (Linked List) Nedir?
Dizilerden sonra en çok kullanılan veri yapısıdır.
Doğrusal Liste (Linear List) yapısı yalnızca öncelik - sonralık ilişkisini yansıtabilecek yapıdadır.
Yığın Veri Yapısı Nedir ( Stack Data Type)
Nesne ekleme ve çıkarmalarının en üstten (top) yapıldığı veri yapısına stack (yığın) adı verilir.
QUEUES (KUYRUK) Veri Yapısı
Kuyruk veri yapısında da veri ekleme (enqueue) ve kuyruktan veri çıkarma (dequeue) şeklinde iki tane işlem tanımlıdır.
Yığınların tersine FIFO (First In First Out) prensibine göre çalışırlar ve ara elemanlara erişim doğrudan yapılamaz.
Tree is a non-linear data structure that can represent hierarchical relationships. It consists of nodes connected by edges. The root node has child nodes, and nodes may be leaf nodes or have child nodes themselves. Binary trees restrict nodes to having at most two children. General trees can be converted to binary trees by making the first child the left child and next siblings the right child. Binary trees can be built from input data by comparing values to determine left or right placement, or from traversal operations.
The document discusses various tree data structures and algorithms related to binary trees. It begins with an introduction to different types of binary trees such as strict binary trees, complete binary trees, and extended binary trees. It then covers tree traversal algorithms including preorder, inorder and postorder traversal. The document also discusses representations of binary trees using arrays and linked lists. Finally, it explains algorithms for operations on binary search trees such as searching, insertion, deletion and rebalancing through rotations in AVL trees.
Red-black trees are a self-balancing binary search tree data structure. They follow several properties including: 1) every node is either red or black, 2) the root is black, 3) every leaf node is black, 4) if a node is red then both its children are black, and 5) for each node, all simple paths from the node to descendant leaf nodes contain the same number of black nodes. Rotations are used to maintain these properties during insertions and deletions. Inserting a new node involves finding the appropriate position and may require recoloring nodes and performing rotations to ensure the red-black tree properties are satisfied. Insertion takes O(log n) time.
red black tree definition,operation,searching,insertion into red black tree,left child,right child,parent,color,key,red,black,nodes,correction,sibling,binary search tree,deletion for red black tree
B-Trees are tree data structures used to store data on disk storage. They allow for efficient retrieval of data compared to binary trees when using disk storage due to reduced height. B-Trees group data into nodes that can have multiple children, reducing the height needed compared to binary trees. Keys are inserted by adding to leaf nodes or splitting nodes and promoting middle keys. Deletion involves removing from leaf nodes, borrowing/promoting keys, or joining nodes.
This document provides an overview of NoSQL databases and compares them to relational databases. It discusses the different types of NoSQL databases including key-value stores, document databases, wide column stores, and graph databases. It also covers some common concepts like eventual consistency, CAP theorem, and MapReduce. While NoSQL databases provide better scalability for massive datasets, relational databases offer more mature tools and strong consistency models.
The document discusses binary search trees and their operations. It defines key concepts like nodes, leaves, root, and tree traversal methods. It then explains how to search, insert, find minimum/maximum elements, and traverse a binary search tree. Searching a BST involves recursively comparing the target key to node keys and traversing left or right. Insertion finds the appropriate position by moving pointers down the tree until reaching an empty node.
1) Trees are hierarchical data structures that store data in nodes connected by edges. They are useful for representing hierarchical relationships.
2) Binary search trees allow quick search, insertion, and deletion of nodes due to the organizational property that the value of each node is greater than all nodes in its left subtree and less than all nodes in its right subtree.
3) Common tree traversal algorithms include preorder, inorder, and postorder traversals, which visit nodes in different orders depending on whether the left/right children or root is visited first.
A red-black tree is a self-balancing binary search tree where each node is colored red or black. It provides logarithmic time bounds for search, insert, and delete operations. It achieves self-balancing by restricting the number of red nodes along any path, ensuring that no path is more than twice as long as any other path. Rotations are used during insertion and deletion operations to rebalance the tree and maintain these properties.
The document discusses different types of tree data structures, including general trees, binary trees, binary search trees, and their traversal methods. General trees allow nodes to have any number of children, while binary trees restrict nodes to having 0, 1, or 2 children. Binary search trees organize nodes so that all left descendants are less than the parent and all right descendants are greater. Common traversal orders for trees include preorder, inorder, and postorder, which differ in whether they process the root node before or after visiting child nodes.
non linear data structure -introduction of treeSiddhi Viradiya
The document defines trees and binary trees. A tree consists of nodes connected by branches, with one root node and zero or more subtrees. A binary tree restricts each node to have at most two children. The document discusses tree terminology like root, child, parent, leaf nodes. It also covers tree traversal methods like preorder, inorder and postorder. Finally, it shows how to construct a binary tree from its traversals.
The right read optimization is actually write optimizationjames tong
Fractal Tree indexes provide a way to optimize both reads and writes for large, growing datasets. They achieve this by combining aspects of log-structured merge trees (LSM trees) and B-trees - buffering data during writes like LSM trees to batch inserts, but maintaining a B-tree structure for efficient queries. This allows fractal tree indexes to have very fast insertion performance like LSM trees while also supporting fast queries like B-tree indexes. However, fractal tree indexes do introduce more complexity in the tree structure that can make concurrency more difficult.
This document discusses binary trees and binary search trees. It defines key tree terms like root, child, parent, leaf nodes. It explains tree traversal methods like preorder, inorder and postorder. It also covers basic BST operations like insertion, search and deletion of nodes. Code snippets are provided to implement these operations and traversal methods on a sample binary search tree. Examples of traversing a sample tree in different orders are given.
stack and queue array implementation in java.CIIT Atd.
This document discusses stack and queue data structures. It provides code examples in Java to demonstrate push and pop operations in a stack and enqueue and dequeue operations in a queue using arrays. Key aspects covered include LIFO and FIFO behavior, stack and queue operations, and sample code to implement stacks and queues in Java with output examples.
This document defines and describes trees and graphs as non-linear data structures. It explains that a tree is similar to a linked list but allows nodes to have multiple children rather than just one. The document defines key tree terms like height, ancestors, size, and different types of binary trees including strict, full, and complete. It provides properties of binary trees such as the number of nodes in full and complete binary trees based on height.
Linked List Static and Dynamic Memory AllocationProf Ansari
Static variables are declared and named while writing the program. (Space for them exists as long as the program, in which they are declared, is running.) Static variables cannot be created or destroyed during execution of the program in which they are declared.
Dynamic variables are created (and may be destroyed) during program execution since dynamic variables do not exist while the program is compiled, but only when it is run, they cannot be assigned names while it is being written. The only way to access dynamic variables is by using pointers. Once it is created, however, a dynamic variable does contain data and must have a type like any other variable. If a dynamic variable is created in a function, then it can continue to exist even after the function terminates.
Linked Linear List
We saw in previous chapters how static representation of linear ordered list through Array leads to wastage of memory and in some cases overflows. Now we don't want to assign memory to any linear list in advance instead we want to allocate memory to elements as they are inserted in list. This requires Dynamic Allocation of memory and it can be achieved by using malloc() or calloc() function.
But memory assigned to elements will not be contiguous, which is a requirement for linear ordered list, and was provided by array representation. How we could achieve this?
Yzm 2116 Bölüm 7 - Tree ve Binary tree - İkili Ağaç
1. YZM 2116
Veri Yapıları
Yrd. Doç. Dr. Deniz KILINÇ
Celal Bayar Üniversitesi
Hasan Ferdi Turgutlu Teknoloji Fakültesi
Yazılım Mühendisliği
2. BÖLÜM - 6
Bu bölümde,
• Ağaç (Tree) Veri Yapısı Giriş
• Ağaç VY Temel Kavramlar
• İkili Ağaç (Binary Tree)
• İkili Ağaç Özellikleri
• İkili Ağaç Gerçekleştirim
• İkili Ağaç Üzerinde Gezinme (Traverse)
• Preorder, Inorder, Postorder
• İkili Ağaç Gerçekleştirimine Dair Sorular
konusuna değinilecektir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
3. 3Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Verilerin birbirine sanki bir ağaç yapısı oluşturuyormuş
gibi sanal olarak bağlanmasıyla elde edilen hiyerarşik
yapıya sahip veri yapısıdır.
• Aynı aile soyağacında olduğu gibi hiyerarşik bir yapısı
vardır ve orada geçen birçok kavram buradaki ağaç
veri yapısında da tanımlıdır.
• Örneğin çocuk, kardeş düğüm, aile, ata gibi birçok
kavram ağaç veri yapısında da kullanılır.
• Her biri değişik bir uygulamaya doğal çözüm olan ikili
ağaç, kodlama ağacı, sözlük ağacı, kümeleme ağacı
gibi çeşitli ağaç şekilleri vardır; üstelik uygulamaya
yönelik özel ağaç şekilleri de çıkarılabilir.
Ağaç VY Giriş
4. 4Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Bağlı listeler, yığıtlar ve kuyruklar doğrusal (linear)
veri yapılarıdır.
• Ağaçlar ise doğrusal olmayan belirli niteliklere sahip
iki boyutlu veri yapılarıdır.
• Ağaçlar hiyerarşik ilişkileri göstermek için kullanılır.
• Her ağaç düğümlerden (node) ve kenarlardan (edge)
oluşur.
• Her düğüm bir nesneyi gösterir.
• Her kenar (bağlantı) iki node arasındaki ilişkiyi
gösterir.
• Arama işlemi bağlı listelere göre çok hızlı yapılır.
Ağaç VY Giriş (devam…)
5. 5Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Ağaç VY Giriş (devam…)
• Ağacın düğümlerindeki bilgiler sayılardan oluşmuştur. Her
düğümdeki sol ve sağ bağlar yardımı ile diğer düğümlere ulaşılır.
Sol ve sağ bağlar NULL olabilir.
• Düğüm yapıları değişik türlerde bilgiler içeren veya birden fazla bilgi
içeren ağaçlar da olabilir.
6. 6Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Ağaç veri yapısı / modeli aşağıdaki yazılım
uygulamalarında kullanılırlar:
o İşletim sisteminin dosya sistemini modellemekte
o Oyunlar için farklı hamleleri ele almakta
o Ağ routing (yönlendirme) algoritmalarında
o Trie adı verilen VY ile sözlük oluşturmakta ve
dinamik yazım kontrolü gibi alanlarda
o Huffman sıkıştırma kodlamasında ve
o Derleyicilerde matematiksel ifadeleri modellemede
kullanılırlar.
Ağaç VY Kullanılan Yazılım Uygulamaları
7. 7Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Örnek Ağaç Yapısı – Dosya Sistemi
/yazilim
kitaplar kodlar dersler
yzm219 yzm112 ...
1.pdf 2.pdf 1.pdf
2015-2016 eskia.java b.java
yzm2116 yzm317 yzm215 ...
1.ppt 1.doc 1.Pdf
9. 9Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Ağaç VY Temel Kavramlar
Level - Seviye
0
1
2
3
A
B C
D E F
G
Kök (root)
Yaprak
Düğüm
Aile / Ara
Düğüm
Yaprak
Düğüm
7 düğümlü ağaç
Çocuk Düğümler
• A düğümü kök olmak
üzere 7 düğümden (n)
oluşmaktadır.
• Toplam 6 kenar (n-1)
vardır.
• Sol alt ağaç, B kökü
ile başlamakta ve sağ
alt ağaç da C kökü ile
başlamaktadır.
• A’dan solda B’ye giden
ve sağda C'ye giden iki
dal (branch)
çıkmaktadır.
10. 10Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Ağaç VY Temel Kavramlar (devam…)
• Düğüm (Node): Ağacın her elemanına verilen isim.
• Kök (Root): Ağacın başlangıç düğümüdür.
• Çocuk (Child): Bir düğüme doğrudan bağlı olan
düğümlere o çocukları denilir.
• Kardeş Düğüm (Sibling): Aynı düğüme bağlı düğümlere
kardeş düğüm veya kısaca kardeş denir.
• Aile (Parent): Düğümlerin doğrudan bağlı oldukları
düğüm aile olarak adlandırılır; diğer bir deyişle aile,
kardeşlerin bağlı olduğu düğümdür.
• Ata (Ancestor): Aile düğümünün daha üstünde kalan
düğümlere denir.
• Torun (Dedscendant): Bir düğümün çocuğuna bağlı olan
düğümlere denir.
11. 11Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Ağaç VY Temel Kavramlar (devam…)
• Yaprak (Leaf): Ağacın en altında bulunan ve çocukları
olmayan düğümlerdir.
• Derece (Degree): Bir düğümden alt hiyerarşiye yapılan
bağlantıların sayısıdır; yani çocuk veya alt ağaç sayısıdır.
• Seviye (Level): Hiyerarşik sıradır (rank). Kök düğüm seviye
= 0.
• Derinlik (Depth): Bir düğümün köke olan uzaklığı
derinliktir. Kök düğüm derinlik = 0.
• Yükseklik (Height): Bir düğümün kendi silsilesinden en
uzak yaprak düğüme olan uzaklığıdır. Yaprak düğümlerin
yükseliği = 0. (Kök yüksekliği = Ağaç Yükesekliği)
• Yol (Path): Bir düğümün aşağıya doğru (çocukları üzerinden)
bir başka düğüme gidebilmek için üzerinden geçilmesi
gereken düğümlerin listesidir.
12. 12Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Ağaç VY Temel Kavramlar (devam…)
A
B C
D E F
G
Kök (Root) Tanım Kök B D
Çocuk/Derece 2 0 0
Kardeş 1 2 3
Seviye 0 1 2
Aile yok Kök C
Ata yok yok Kök
Yol A A, B A,C,D
Derinlik 0 1 2
Yükseklik 3 0 0
13. 13Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Ağaç VY Temel Kavramlar (devam…)
Düğüm sayısı:
Yükseklik:
Kök düğüm:
Yapraklar:
Seviye sayısı:
H'nin ataları:
B'nin torunları:
E'nin kardeşleri:
9
4
A
C, D, F, H, I
4
E, B, A
G, H, I
D, F
14. 14Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Ağaçlara Özyinelemeli Yaklaşım
• Rekürsif mantıkla bir ağaç, bir kök (root) ve alt-ağaçlar
şeklinde tanımlanır.
• 1 düğümü 2 ve 3 alt-ağaçlarından oluşur
• 2 düğümü 4,6 ve 5 (5-9-10) olmak üzere üç alt-ağaçtan
oluşur.
16. 16Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç (Binary Tree)
• Her düğümün en fazla iki çocuk düğüme sahip olduğu
ağaç yapısına BT denir.
• BT, bilgisayar bilimlerinde en çok kullanılan ağaç
veri yapılarından olup, sıralı olması durumunda
arama, ekleme ve silme işlemlerini çabuklaştırırlar.
• Bir BT
o Boş tek bir düğümden oluşabileceği gibi,
o Sol alt ağaç ve sağ alt ağaç olmak üzere köke ait iki adet
ikili ağaçtan da oluşabilir.
• BT için gerek şart ilgili BT düğümünün en fazla iki
çocuğa (alt ağaca) sahip olabileceğidir.
17. 17Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç (Binary Tree) (devam…)
A
C D
Z I
K
Kök
P
M
Sağ alt ağaç
A
B
A
B
İki farklı ikili ağaç
18. 18Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Katı İkili Ağaç (Strict Binary Tree)
• Yaprak düğümler haricindeki tüm düğümler sıfır veya
iki çocuğa sahip ise katı ikili ağaç olarak adlandırılır.
Katı İkili AğaçKatı Olmayan İkili Ağaç
19. 19Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Tam İkili Ağaç (Full Binary Tree)
• Her bir düğümün (i)net olarak iki çocuk düğüme
sahip olduğu ve (ii)yaprak düğümlerin aynı
seviyede olduğu iki ağaçtır.
• Her düğüm eşit şekilde sağ ve sol alt-ağaçlara
sahiptir.
20. 20Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Eksiksiz İkili Ağaç (Complete Binary Tree)
• Son seviye dışındaki tüm seviyelerin tam (full)
olduğu ikili ağaç türüdür.
• Düğümleri sol taraftan (düğüme göre) doldurulur.
• Yeni bir derinliğe soldan sağa doğru ekleme
başlanır.
21. 21Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Eksiksiz İkili Ağaç (Complete Binary Tree)
• Aşağıdaki örnekler, eksiksiz ikili ağaç kriterlerine
uyuyor mu?
22. 22Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Özellikleri – Özellik 1
• Her k seviyesinde, maksimum düğüm sayısı 2k dır.
• Kök düğümde k=0 olduğu için düğüm sayısı 1 olurken,
• k=2 için maksimum düğüm sayısı 4 olur.
23. 23Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Özellikleri – Özellik 2
• h yüksekliğindeki ikili ağacın maksimum düğüm sayısı =
2h+1 - 1 olarak hesaplanır.
• Aşağıdaki ağaç için h = 3 olduğundan maksimum düğüm
sayısı 16 – 1 = 15 bulunur.
24. 24Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Özellikleri – Özellik 3
• h yüksekliğindeki ikili ağacın
o minimum düğüm sayısı = h + 1 olarak hesaplanır.
• Kök düğümün h = 0 da olduğuna dikkat ediniz.
A
C
P
P
A
C
P
P
25. 25Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Özellikleri – Özellik 4
• En az iki düğüme sahip, n elemanlı bir ikili ağaçta,
kenar sayısı = (n - 1) olarak hesaplanır.
• Aşağıdaki örneklerde 4’er düğüm ve 3’er kenar
mevcuttur.
A
C
P
P
A
C
P
P
26. 26Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Özellikleri – Özellik 5
• n yaprak düğüme sahip, eksiksiz bir ikili ağaçta
(complete), kenar sayısı (k) = 2(n-1)’dir.
27. 27Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Gerçekleştirimi
• İki türlü gerçekleştirimi mümkündür:
o Dizi kullanarak
o Bağlı liste kullanarak
29. 29Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Bağlı Liste İkili Ağaç Gerçekleştirimi (devam…)
4
6 12
45 7
kök
1
30. 30Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Bağlı Liste İkili Ağaç Gerçekleştirimi (devam…)
4
6 12
45 7
kök
1
• Soru: Kökten itibaren düğümleri elimizde olan ikili
ağaç üzerinde nasıl dolaşırız?
31. 31Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Üzerinde Gezinme (Traverse)
• Bir ağacı bir düğüme sadece bir defa uğrayacak
şekilde gezmeye gezinme/geçiş denir.
• Gezinme, ağacın sakladığı bilgi türüne göre bir bilgiye
ulaşma, listeleme ve başka amaçlarla gerçekleştirilir.
• Doğrusal veri yapılarında baştan sona doğru
dolaşmak kolaydır.
• Ağaçlar ise düğümleri doğrusal olmayan veri
yapılarıdır. Bu nedenle farklı algoritmalar uygulanır.
• Örneğin; düğümlerin matematiksel operatörler ve
oparandlar olduğu bir ikili ağacın gezinme işlemi,
infix-postfix gibi bir notasyonu elde etmemizi sağlar.
32. 32Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Üzerinde Gezinme (devam…)
• İkili ağacın üzerinde gezinilmesi sırasında
bağımsız olarak 3 grup ikili ağaç parçasının
1. Kök
2. Sol alt ağaç
3. Sağ alt ağaç
değişik sıralarda gezilmesiyle ile gerçekleşir.
33. 33Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Üzerinde Gezinme (devam…)
• İkili ağaç üzerinde dolaşmak için 3 temel yol
vardır. Bunlar:
• Önce-kök/ziyaret (Preorder - NLR):
Kök/ziyaret, Sol, Sağ
Önce kök, sonra sol alt ağaç ve ardından sağ alt ağaç
• Ortada-kök/ziyaret (Inorder - LNR):
Sol, Kök/ziyaret, Sağ
Önce sol alt ağaç, kök ve sağ alt ağaç
• Sonra-kök/ziyaret (Postorder - LRN):
Sol, Sağ, Kök/ziyaret
Önce sol alt ağaç, sağ alt ağaç ve kök.
34. 34Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
İkili Ağaç Üzerinde Gezinme (devam…)
A
B
C
Q M
H
K
L X
P
Örnek Ağaç
35. 35Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Preorder ile Gezinme
1. Düğümü ziyaret et
2. Sol alt ağaçta gezin
3. Sağ alt ağaçta gezin
Preorder Gezinme:
a, b, d, c, e
37. 37Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
A
B
C
Q M
H
K
L X
P
Preorder ile Gezinme (devam…)
Preorder Gezinme:
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
38. 38Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Inorder ile Gezinme
1. Sol alt ağaçta gezin
2. Düğümü ziyaret et
3. Sağ alt ağaçta gezin
Inorder Gezinme:
b, d, a, e, c
40. 40Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Inorder ile Gezinme (devam…)
A
B
C
Q M
H
K
L X
P
Inorder Gezinme:
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
41. 41Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Postorder ile Gezinme
1. Sol alt ağaçta gezin
2. Sağ alt ağaçta gezin
3. Düğümü ziyaret et
Postorder Gezinme:
d, b, e, c, a
46. 46
Gezinmeler Ne İşe Yarar?
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Preorder:
• Ağacın kopyasını elde etme
• Düğümleri sayma
• Yaprakları sayma
• Matematiksel ifadeler için prefix gösterimini elde etme
Postorder:
• İkili ağacı silme
• Fonksiyonel dil derleyicilerinde
• Hesap makinesi programlarında
• Postfix matematiksel ifadelerinin oluşturulmasında
Inorder:
• İkili Arama Ağacında (Binary Search Tree) ağaçtaki bilgiyi sıralı
halde yazdırmada
47. 47
İkili Ağaç Uygulamaları
• Binary Search Tree (İkili Arama Ağacı): Birçok arama
uygulamasında,
• Binary Space Partition: Hemen hemen tüm 3D video
oyunlarında, hangi nesnelerin render edilmesi gerektiğini
belirlemede,
• Binary Tries: Yüksek bant genişliğine sahip router
cihazların router-tablolarını saklamada,
• Hash Trees: P2P programlarında, imza doğrulamada
• Heaps: Öncelik kuyruklarının daha etkin/verimli
gerçekleştiriminde kullanılır. Öncelik kuyrukları işletim
sisteminde prosesleri planlamak için kullanılır. Yapay zeka
uygulamalarında A* yol bulma (path finding)
algoritmasının gerçekleştiriminde
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
48. 48
İkili Ağaç Uygulamaları (devam…)
• GGM Trees: Bir çok şifreleme uygulamasında, sözde
rastgele sayıların ağacının oluşturulmasında
• Treap: Kablosuz ağlarda ve bellek tahsisinde
• T-tree: Bellek içi veritabanlarına (Datablitz, EXtremeDB,
MySQL Cluster, Oracle TimesTen) ait işlemlerinde
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Stackoverflow tartışmasına bakınız…
49. 49
İkili Ağaç Gerçekleştirimine Dair Sorular
• Ağaçtaki düğüm sayısını nasıl bulurum?
• Ağaçtaki yaprak sayısını nasıl bulurum?
• Ağaç yüksekliğini nasıl bulurum?
• İkili ağacın katı (strict) ikili ağaç olup olmadığını
nasıl anlarım?
• İkili ağaçtaki 2 yaprak düğümün en küçük ortak
atasını nasıl bulurum (LCA – Lowest Common
Ancestor)?
• Inorder ve Preorder gezinme sonuçları verilen ikili
ağacı nasıl oluştururum?
• Inorder ve Postorder gezinme sonuçları verilen ikili
ağacı nasıl oluştururum?
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
52. 52
İki Gezinme Sonucundan Ağaç Elde Etme
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Eğer Preorder sonuç verildiyse ilk düğüm köktür.
• Eğer Postorder sonuç verildiyse son düğüm
köktür.
• Kök bulunduktan sonra, Inorder gezinmeye göre,
kökün sol ve sağ tarafındaki düğümler; sol ve sağ
alt ağaç olarak belirlenirler.
• Aynı teknik yeni bulunan sol ve sağ alt ağaç için
özyinelemeli (recursive) olarak uygulanır.
• Gezinme sonuçlarından birisi mutlaka Inorder
olmalıdır. Diğeri Preorder veya Postorder olabilir.
53. 53
İki Gezinme Sonucundan Ağaç Elde Etme (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Inorder gezinme: 20 30 35 40 45 50 55 60 7
Preorder gezinme: 50 40 30 20 35 45 60 55 70
Soru: İkili ağacı elde ediniz.
55. Yararlanılan Kaynaklar
• Ders Kitabı:
• Data Structures through JAVA, V.V.Muniswamy
• Yardımcı Okumalar:
• Data Structures and Algorithms in Java, Narashima
Karumanchi
• Data Structures, Algorithms and Applications in Java,
Sartaj Sahni
• Algorithms, Robert Sedgewick
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları