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.
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.
Binomial queues allow merging of heaps in O(log N) time rather than the usual O(N) time for binary heaps. They use a forest of binomial trees where each tree is used 0 or 1 times. To merge two binomial queues, the corresponding binomial trees are combined level by level. Insertion takes O(log N) time by merging the new node as its own queue. Deletion of the minimum takes O(log N) time by removing the smallest tree and merging its children.
A tree is a nonlinear data structure that consists of a root node and zero or more subtrees. The root node can have any number of child nodes, but each child can only have one parent. Nodes maintain a parent-child relationship, with one node designated as the root and the remaining nodes forming non-empty subtrees below the root. Trees allow for hierarchical categorization of data.
This document discusses trees as a data structure. It defines key tree terminology like root, leaf nodes, ancestors and descendants. It describes different tree representations and traversal techniques including preorder, inorder and postorder sequences. It also covers different types of binary trees and basic tree operations like insertion, deletion and searching. Common applications of trees include representing arithmetic expressions, decision processes and priority queues.
A B+ tree is a self-balancing tree data structure used to store sorted data such as indexes in a database. It improves upon B-trees by storing all data values in the leaves and using a linked list to connect all leaves. This allows efficient traversal and retrieval operations. Keys are stored in the internal nodes and direct searches to the proper leaf node. Data is inserted by splitting full nodes and redistributing keys. Deletion is done by removing keys and merging nodes if necessary to maintain the minimum node occupancy.
Students can learn Trees concept in data structures. various types of data structures like binary trees, expression trees, binary search trees and AVL trees are covered in this PPT.
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.
A graph data structure consists of vertices and edges that relate the vertices. Common graph representations include adjacency matrices and adjacency lists. Depth-first search (DFS) is an algorithm for traversing graphs by going as deep as possible down each branch before backtracking. It uses a stack to remember to explore vertices later.
Bubble sort is a simple sorting algorithm that compares adjacent elements and swaps them if they are not in order. It has a worst-case and average time complexity of O(n2) where n is the number of items, making it inefficient for large data sets. The algorithm makes multiple passes through the array, swapping adjacent elements that are out of order until the array is fully sorted. It is one of the simplest sorting algorithms to implement but does not perform well for large data sets due to its quadratic time complexity.
This document provides an introduction to circular linked lists. It explains that a circular linked list is a variation of a linked list where the first element points to the last element, forming a loop. Both singly and doubly linked lists can be made circular by having the next pointer of the last node point to the first node, and in doubly linked lists the previous pointer of the first node points to the last node. Basic operations like insert, delete, and display are supported. Memory management involves the head pointer storing the address of the first node, and each node storing the address of the next node and last node.
The document discusses AVL trees, which are self-balancing binary search trees. It provides information on AVL tree operations like insertion and deletion of nodes. Insertion may cause imbalance, requiring rotation operations like single, double, left, or right rotations to rebalance the tree. Deletion is similar but can require propagating rotations upward to restore balance. AVL trees provide O(log n) time for operations by staying balanced through rebalancing rotations after inserts and deletes.
A 2-3 tree is a tree data structure where each internal node has either 2 or 3 children. It allows efficient search, insert, and delete operations by balancing the tree through splitting and merging nodes. To insert a new value, it is added to an leaf node. If the leaf contains 3 values, it is split by moving the middle value up to the parent. To delete a value, the target value is removed from its leaf node and neighboring nodes are merged if they become empty to maintain balance. This spreading of operations helps keep the 2-3 tree height balanced.
- A red-black tree is a self-balancing binary search tree where each node is colored red or black. It maintains the properties that the black height of each path is equal and there are no adjacent red nodes, ensuring O(log n) time for operations.
- Common operations like insertion, deletion, and searching on a red-black tree work similarly to a binary search tree but may require rotations and color changes to maintain the red-black properties.
- Red-black trees are widely used in applications that require efficient search structures for frequently updated data like process memory management and functional programming data structures.
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
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.
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.
Binomial queues allow merging of heaps in O(log N) time rather than the usual O(N) time for binary heaps. They use a forest of binomial trees where each tree is used 0 or 1 times. To merge two binomial queues, the corresponding binomial trees are combined level by level. Insertion takes O(log N) time by merging the new node as its own queue. Deletion of the minimum takes O(log N) time by removing the smallest tree and merging its children.
A tree is a nonlinear data structure that consists of a root node and zero or more subtrees. The root node can have any number of child nodes, but each child can only have one parent. Nodes maintain a parent-child relationship, with one node designated as the root and the remaining nodes forming non-empty subtrees below the root. Trees allow for hierarchical categorization of data.
This document discusses trees as a data structure. It defines key tree terminology like root, leaf nodes, ancestors and descendants. It describes different tree representations and traversal techniques including preorder, inorder and postorder sequences. It also covers different types of binary trees and basic tree operations like insertion, deletion and searching. Common applications of trees include representing arithmetic expressions, decision processes and priority queues.
A B+ tree is a self-balancing tree data structure used to store sorted data such as indexes in a database. It improves upon B-trees by storing all data values in the leaves and using a linked list to connect all leaves. This allows efficient traversal and retrieval operations. Keys are stored in the internal nodes and direct searches to the proper leaf node. Data is inserted by splitting full nodes and redistributing keys. Deletion is done by removing keys and merging nodes if necessary to maintain the minimum node occupancy.
Students can learn Trees concept in data structures. various types of data structures like binary trees, expression trees, binary search trees and AVL trees are covered in this PPT.
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.
A graph data structure consists of vertices and edges that relate the vertices. Common graph representations include adjacency matrices and adjacency lists. Depth-first search (DFS) is an algorithm for traversing graphs by going as deep as possible down each branch before backtracking. It uses a stack to remember to explore vertices later.
Bubble sort is a simple sorting algorithm that compares adjacent elements and swaps them if they are not in order. It has a worst-case and average time complexity of O(n2) where n is the number of items, making it inefficient for large data sets. The algorithm makes multiple passes through the array, swapping adjacent elements that are out of order until the array is fully sorted. It is one of the simplest sorting algorithms to implement but does not perform well for large data sets due to its quadratic time complexity.
This document provides an introduction to circular linked lists. It explains that a circular linked list is a variation of a linked list where the first element points to the last element, forming a loop. Both singly and doubly linked lists can be made circular by having the next pointer of the last node point to the first node, and in doubly linked lists the previous pointer of the first node points to the last node. Basic operations like insert, delete, and display are supported. Memory management involves the head pointer storing the address of the first node, and each node storing the address of the next node and last node.
The document discusses AVL trees, which are self-balancing binary search trees. It provides information on AVL tree operations like insertion and deletion of nodes. Insertion may cause imbalance, requiring rotation operations like single, double, left, or right rotations to rebalance the tree. Deletion is similar but can require propagating rotations upward to restore balance. AVL trees provide O(log n) time for operations by staying balanced through rebalancing rotations after inserts and deletes.
A 2-3 tree is a tree data structure where each internal node has either 2 or 3 children. It allows efficient search, insert, and delete operations by balancing the tree through splitting and merging nodes. To insert a new value, it is added to an leaf node. If the leaf contains 3 values, it is split by moving the middle value up to the parent. To delete a value, the target value is removed from its leaf node and neighboring nodes are merged if they become empty to maintain balance. This spreading of operations helps keep the 2-3 tree height balanced.
- A red-black tree is a self-balancing binary search tree where each node is colored red or black. It maintains the properties that the black height of each path is equal and there are no adjacent red nodes, ensuring O(log n) time for operations.
- Common operations like insertion, deletion, and searching on a red-black tree work similarly to a binary search tree but may require rotations and color changes to maintain the red-black properties.
- Red-black trees are widely used in applications that require efficient search structures for frequently updated data like process memory management and functional programming data structures.
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
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 - 10
Bu bölümde,
• Giriş
• Hash Tabloları
• Hash Fonksiyonu
• Çakışma (Collision)
• Ayrık Zincirleme Çözümü
• Linear Probing Çözümü
• Quadratic Probing Çözümü
konusuna değinilecektir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
3. Giriş
• Bilgi getiriminde iki tip bilgi arama ve erişim
stratejisi mevcuttur:
1. Sıralı erişim
2. Direk erişim (Nasıl yaparız?)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
4. Nasıl Yaparız?
• Sıralı erişimde, temel işlem, baştan sona tüm
anahtarları karşılaştırmaktır.
• Bir anahtarın tablo içerisinde bulunduğu
pozisyona ulaşıncaya kadar arama işlemine devam
edilir.
• Hash fonksiyonuyla aranan anahtar elemana
doğrudan erişilebilmektedir.
• Hash fonksiyonu, bir anahtar bilgisinin tabloda
bulunduğu indeksi hesaplamaktadır.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
5. Hash Tabloları
• Hash tablo veri yapısı ile veri arama, ekleme ve
silme işlemleri ortalama olarak sabit zamanda
(O(1)), daha verimli bir biçimde gerçekleştirilir.
• Hash tabloları arama, ekleme ve silme
işlemlerinde ağaçlardan daha hızlı oldukları
(ortalamada) gibi programlanmaları da daha
kolaydır.
• Dezavantajları
o Tablo içerisindeki elemanların sıralanması, en büyük ya da
en küçük elemanın bulunması işlemlerinde verimli değildir.
o En büyük kısıtı ise diziler ile oluşturulmalarıdır.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
6. Hash Tabloları (devam…)
• İdeal bir hash tablo veri yapısı, içerisinde elemanlar
barındıran sabit bir diziden oluşur.
• Dizi içerisindeki elemanlar, index hesaplamasında
kullanılacak anahtar (key) isimli özel bir üye bulundurmak
zorundadırlar.
• Anahtar; integer veya string bir değer olabilir.
• Örneğin: Bir Öğrenci nesnesindeki Öğrenci No veya Öğrenci TC Kimlik
No olabilir.
• Dizinin boyutu TabloBoyutu olup,
• Diziye eklenecek elemanlar 0’dan (TabloBoyutu-1)’e kadar
olan indekslerde saklanırlar.
• AnahtardanIndekse dönüştürme işlemine Hashing, bu
işi yapan fonksiyona Hashing fonksiyonu denir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
7. Örnek
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Hash
Fonksiyonu
İpek 4444
Sibel 3333
Ada 2222
Cem 1111
Elemanlar
Hash
Tablosu
anahtar
anahtar
0
1
2
3
4
5
6
7
8
9
İpek 4444
Sibel 3333
Ada 2222
Cem 1111
8. String Hash Fonksiyon Örneği
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Karakterlerin ASCII değerlerini topla ve mod al.
int hash(const string key, int tableSize)
{
int hasVal = 0;
for (int i = 0; i < key.length(); i++)
hashVal += key[i];
return hashVal % tableSize;
}
• Gerçekleştirimi basit ve hızlı bir algoritmadır.
• Ancak, hash tablosunda eleman sayısı fazla ise fonksiyon
anahtarları iyi dağıtamaz.
• Örn: N =10000, Anahtar uzunluğu <= 8 ise,
• Hash fonksiyonu 0 ve 1016 arasında değer üretir.
9. Hash Fonksiyonu
• Anahtarın dizideki pozisyonu yani indisini
belirlemek için kullanılır.
• Dizinin eleman sayısı N olsun
• Fonksiyon f(x), x anahtarını 0 ve N−1 arasındaki bir
indise dönüştürür
• Örneğin, N=15 ise, anahtar 0 ve MAX_INT arasında
olup, Hash fonksiyonu aşağıdaki gibi olabilir:
f(x) = x % 15
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
10. Hash Fonksiyonu (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
f(x) = x % 15 ise f(x) ?
if x = 25 129 35 2501 47 36
f(x) = 10 9 5 11 2 6
Anahtarların diziye yerleşimi aşağıdaki gibidir:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
_ _ 47 _ _ 35 36 _ _ 129 25 2501 _ _ _
• Silme, ekleme ve arama işlem karmaşıklığı O(1),
ancak bir problem var???
11. Hash Fonksiyonu (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Soru: Eğer x = 65 anahtarını eklemek istersek ne olur?
x = 65
f(x) = 5
Anahtarların diziye yerleşimi:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
_ _ 47 _ _ 35 36 _ _ 129 25 2501 _ _ _
65(?)
• 35 ve 65 anahtarları için f(x) fonksiyonundan aynı
indis değeri döndü.
Çakışma (collision) oldu…
12. Çakışma (Collision)
• Hashing işlemi sonucunda farklı anahtarlara sahip iki
eleman, aynı dizi indeks değeri üretilebilir.
• Eğer en az iki eleman için aynı indeks değeri üretilirse
bu duruma çarpışma denir.
• Çarpışma istenmeyen bir durumdur.
• Çarpışmayı çözmek için iki yöntem vardır:
1. Ayrık zincirleme (Separate chaning)
2. Açık adresleme (Open adressing)
I. Doğrusal ölçüm (Linear probing)
II. Karesel ölçüm (Quadratic probing)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
13. 1.Ayrık Zincirleme Çözümü
• Aynı indis pozisyonuna gelen kayıtlar bağlı
listelerle gösterilir.
• Çarpışma meydana gelirse ikinci eleman bir
bağlı liste ile birinci elemana bağlanır.
• Bağlı listeler tek veya çift yönlü olabilir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
15. 1.Ayrık Zincirleme Çözümü (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Labda gerçekleştirim yapacağız...
16. 1.Ayrık Zincirleme Çözümü
• Avantajları
o Basit çakışma çözümü (bağlı liste üzerinde arama)
o Hash tablosunun maksimum eleman sayısından daha
fazla eleman eklenebilir.
• Dezavantajları
o Tablonun bazı kısımları hiç kullanılmamaktadır.
o Bağlı listeler uzadıkça arama ve silme işlemleri için
gereken zaman uzamaktadır.
o Dizi haricinde ekstra veri yapısı olan bağlı liste
kullanılır.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
17. 2. Açık Adresleme Çözümü
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Açık adresleme çözümünde tüm elemanlar aynı
hash tablosunda (dizide) saklanırlar.
• Çarpışma meydana geldiğinde alternatif boş
indisler denenir.
– Denenecek indisler h0(x), h1(x), h2(x), …
• Genel mantık aşağıdaki gibidir:
– hi(x) = (hash(x) + f(i)) mod TabloBoyutu, with f(0) = 0.
– f fonksiyonu is the çakışma (Collision) çözüm
stratejisidir.
18. 2. Açık Adresleme Çözümü
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
1. Doğrusal Ölçüm (Linear Probing)
2. Karesel Ölçüm (Quadratic Probing)
19. Doğrusal Ölçüm (Linear Probing)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Çakışma meydana geldiğinde, doğrusal arama
mantığıyla, uygun boş yerler sırayla aranırlar.
• f doğrusal bir fonksiyon olup, f(i) = i
• Sırayla deneme işlemi gerçekleştirilir.
• Hash tablosunun sonuna gelindiyse, başa
dönülür.
o Döngüsel Kuyruk mantığında veya döngüsel dizi
20. • TabloBoyutu = 15.
• 65 elemanını eklemek istiyoruz, ancak 5 numaralı
indiste zaten 35 elemanı var.
• Çakışma gerçekleşti, ne yapacağız?
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
_ _ 47 _ _ 35 36 _ _ 129 25 2501 _ _ _
65(?)
Doğrusal Ölçüm (Linear Probing) (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
26. Doğrusal Ölçüm (Linear Probing) (devam…)
Arama İşlemi
• Ekleme işlemindeki benzer algoritma mantığı ile
arama işlemi gerçekleştirilir.
1. Aranacak anahtar, hash fonksiyonuna geçirilir ve
hash tablo indisi bulunur.
2. İndis değerinde eleman olup olmadığı kontrol
edilir. Eleman yoksa, bulma işlemi başarısız
demektir. İndiste eleman varsa, elemanın
anahtarı ile aranan anahtar karşılaştırılır.
i. Eğer anahtarlar eşitse, çıkılır.
ii. Anahtarlar eşit değilse, bir sonraki indise geçilir.
iii. 2 numaralı adım baştan işletilir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
27. Doğrusal Ölçüm (Linear Probing) (devam…)
0
1
2
3
4
5
6
7
8
9
• H(x) = x % 10
• Ekle 47, 57, 68, 18, 67
• Bul 68
• Bul 10
• Sil 47
• Bul 57
47
57
68
18
67
PROBLEM
47’yi gerçekten silersek 57’yi
bulamayız. Nasıl silmeliyiz?
Silme İşlemi
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
28. Doğrusal Ölçüm (Linear Probing) (devam…)
• Tembel Silme (Lazy Deletion)
• Her dizi hücresinin 3 durumu tutulur:
– Aktif (Dolu)
– Boş (Empty)
– Silindi (Deleted)
• Arama ve silme işlemlerinde
– Sadece (durum = Boş) ise işlemi sonlandır. Silindi
durumunda sonraki elemanla devam et.
Silme İşlemi Çözüm
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
29. Doğrusal Ölçüm (Linear Probing) (devam…)
• Ekle
– Hücre: Boş veya Silindi H indise Ekle VE hücre = Aktif
– Hücre: Aktif H = (H + 1) mod N
• Bul / Ara
– Hücre: Boş BULUNAMADI
– Hücre: Silindi H = (H + 1) mod N
– Hücre: Aktif if key == key in hucre -> BULDU
else H = (H + 1) mod N
• Sil
– Hücre: Aktif; key != key H = (H + 1) mod N
– Hücre: Aktif; key == key SİL; hücre = Silindi
– Hücre: Silindi H = (H + 1) mod N
– Hücre: Boş BULUNAMADI
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
30. Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Kümeleme (Clustering) Problemi
• Hash tablosu yeterince büyük olduğunda mutlaka boş
bir hücre bulunabilir.
• Kayıtların yığın şeklinde toplanmasına yani
kümelemeye (clustering) neden olabilir.
• Arama işlemi genelde küme içerisinde gerçekleşir ve
kümeye eklenir.
Doğrusal Ölçüm (Linear Probing) (devam…)
31. Karesel Ölçüm (Quadratic Probing)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Kümeleme problemini önlemek için geliştirilmiştir.
• Genel mantık aşağıdaki gibidir:
– hi(x) = (hash(x) + f(i)) mod TabloBoyutu, with f(0) = 0.
– f fonksiyonu is the çakışma (Collision) çözüm
stratejisidir.
– f karesel bir fonksiyon olup, f(i) = i2
33. • Çözüm: 29 Ekle
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
_ _ 47 _ _ 35 36 _ _ 129 25 2501 _ _ 65
t+1 t
• Toplam 2 deneme yaptık ve uygun yeri bulduk.
29
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Karesel Ölçüm (Quadratic Probing) (devam…)
34. • Hash fonksiyonların güvenlik ve şifreleme alanında da sıkça
kullanılmaktadır.
• Hash fonksiyonları tek yönlü (One Way) çalışır. Yani
algoritmanın ürettiği sonuçtan tekrar asıl metine dönüşün
mümkün değildir.
• Bazı örnek hash fonksiyonları:
– MD5 (Message Digest 5)
– MD6 (Message Digest 6)
– SHA-1 (Secure Hashing Algorithm)
– HAVAL
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Hash Fonksiyonları ve Güvenlik
35. Veritabanında Kullanıcı Bilgisi Saklanması
• Örneğin web sitelerinde kullanıcı bilgilerini veritabanında
saklarken SHA kullanılabilir. Web siteleri sizin şifrenizi tek
yönlü şifreli tutmak zorundadır.
• 160 bitlik SHA algoritması en çok kullanılanıdır.
• SHA'nın birçok türevi vardır.
• Facebook'un kullandığı 384 bitlik versiyon, 160 bitliğe göre
daha güvenlidir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Hash Fonksiyonları ve Güvenlik (devam…)
36. Dosya İndirme Kontrolü
• Hash algoritmaların bir diğer kullanım yeri de internetten
indirdiğiniz herhangi bir dosyanın tam inip inmediğini tespit
etmektir.
• Örneğin, web sitemizde 700 MB'lık bir Ubuntu.ISO dosyasının
linkini koyduk.
• Linkin altına Ubuntu.ISO dosyasının SHA veya MD5
algoritmasından geçirilmiş halini de koyuyoruz.
• Ubuntu.ISO dosyasını sitemizden indiren kullanıcı, kendi
bilgisayarında indirdiği dosyayı MD5 veya SHA'dan geçiriyor,
sitemizdeki ile aynı sonuç çıkarsa, sorunsuz inmiştir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Hash Fonksiyonları ve Güvenlik (devam…)
37. • Hash fonksiyonu
• f(x) = N % 19
• Buna göre, her bir anahtarın aranma
olasılığının eşit olduğu varsayılırsa,
• Başarılı aramalar için ortalama
yoklama sayısı kaç olur?
• Tüm aramalar için ortalama
yoklama sayısı kaç olur?
a ) 0, 8, 1, 4
b) 6 , 1, 8, 2
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Örnek Soru
39. 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ı