Yzm 2116 Bölüm 9 - Heap Binary TreeDeniz KILINÇTam İkili Ağaç
Eksiksiz İkili Ağaç
Dizi Kullanarak İkili Ağaç Gerçekleştirimi
Heap, Max Heap, Min Heap
Öncelik Kuyruğu
HeapSort
Bağli li̇steler (Linked List) – Yiğinlar (Stack) - Kuyruklar Konu Anlatımı Ömer ÖzselçukBu 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.
QueuesLovely Professional UniversityThe document provides an overview of queues as data structures, explaining their classification into primitive and non-primitive types and detailing the operations of inserting and deleting elements (enqueue and dequeue). It describes various types of queues, including circular queues, deques, and priority queues, along with their implementations and applications in computing. Additionally, it highlights the importance of queues in handling processes in operating systems and real-life scenarios like waiting lines.
Лекция 4. Префиксные деревья (Tries, prefix trees)Mikhail KurnosovДокумент представляет собой лекцию о префиксных деревьях (trie), их структуре данных и алгоритмах, связанных с вставкой, поиском и удалением элементов. Обсуждаются примеры применения префиксных деревьев, такие как автозавершение и проверка правописания. Также приводятся детали реализации и вычислительной сложности операций над префиксными деревьями, включая примеры кода на языке C.
GAC DS Priority Queue Presentation 2022.pptCUO VEERANAN VEERANANThis document discusses priority queues and their implementation. It begins by defining different types of queues like simple, circular, priority, and double-ended queues. It then focuses on priority queues, explaining ascending and descending order priority queues. Various data structures for implementing priority queues are covered, including arrays, linked lists, heaps, and binary search trees. Common operations on priority queues like enqueue, dequeue, and peek are also defined. Finally, applications of priority queues in areas like CPU scheduling, graph algorithms, and data compression are mentioned.
Stack and Queue by M.Gomathi Lecturergomathi chlmThis document discusses stacks and queues as abstract data structures. Stacks follow LIFO (last in first out) order, adding and removing elements from one end. Queues follow FIFO (first in first out) order, adding to one end (rear) and removing from the other (front). The document provides examples of stack and queue applications and implementations using arrays.
Data Structure and Algorithms Binary Search TreeManishPrajapati78Binary search trees (BSTs) are data structures that allow for efficient searching, insertion, and deletion. Nodes in a BST are organized so that all left descendants of a node are less than the node's value and all right descendants are greater. This property allows values to be found, inserted, or deleted in O(log n) time on average. Searching involves recursively checking if the target value is less than or greater than the current node's value. Insertion follows the search process and adds the new node in the appropriate place. Deletion handles three cases: removing a leaf, node with one child, or node with two children.
Shell sortRajendran This document discusses Shellsort, an algorithm developed by Donald Shell in 1959 that improves on insertion sort. Shellsort works by comparing elements that are farther apart within an array rather than adjacent elements. It makes multiple passes through a list, sorting subsets of elements using an increment sequence that decreases until the final pass sorts adjacent elements using insertion sort. Shellsort breaks the quadratic time barrier of insertion sort and is faster for medium sized lists but is outperformed by other algorithms like merge, heap, and quick sort for large lists. Examples are provided to illustrate how Shellsort works by sorting a sample list.
single linked listSathasivam RangasamyThis document discusses the implementation of a single linked list data structure. It describes the nodes that make up a linked list, which have an info field to store data and a next field pointing to the next node. The document outlines different ways to represent linked lists, including static arrays and dynamic pointers. It also provides algorithms for common linked list operations like traversing, inserting, and deleting nodes from the beginning, end, or a specified position within the list.
Stack, Queue, Linked List.pptxBharati Vidyapeeth COE, Navi MumbaiThe document discusses various data structures and algorithms. It begins with an overview of common data structures like arrays, lists, stacks, queues, and linked lists. It then provides detailed explanations of stack, queue, circular queue, priority queue, double ended queue, and various linked list implementations including singly linked lists, doubly linked lists, and circular linked lists. For each data structure, it discusses operations like insertion, deletion, traversal, and implementations in C/C++ using structures and pointers.
1.5 binary search treeKrish_ver21) Tree data structures involve nodes that can have zero or more child nodes and at most one parent node. Binary trees restrict nodes to having zero, one, or two children.
2) Binary search trees have the property that all left descendants of a node are less than the node's value and all right descendants are greater. This allows efficient searching in O(log n) time.
3) Common tree operations include insertion, deletion, and traversal. Balanced binary search trees use rotations to maintain balance during these operations.
Singly linked listAmar JukuntlaThis document discusses different operations on linked lists such as insertion, deletion, and traversal. It begins with an introduction to linked lists explaining that each node contains a data field and pointer to the next node. It then covers implementing a basic node structure and various functions like creating a new node, adding a node to the beginning or end of the list, and deleting a node from the beginning, end, or a given position. Traversal and keeping track of previous nodes is important for operations like deletion from within the list. The document provides pseudocode to demonstrate common linked list operations.
Advanced data structures vol. 1Christalin NelsonThe document provides an overview of advanced data structures, detailing various types such as arrays, stacks, queues, linked lists, and hash tables, along with their characteristics and uses. It highlights the importance of selecting appropriate data structures for efficient data management and algorithm design. Specific techniques for collision resolution in hash tables, including open addressing and separate chaining, are also discussed.
DSA Lab Manual C Scheme.pdfBharati Vidyapeeth COE, Navi MumbaiThe document is a laboratory manual for a data structures and analysis course at BVCOE, Navi Mumbai, detailing various experiments focused on programming concepts, array implementations, and linked lists. It outlines specific objectives and operations related to stacks, queues, binary search trees, heaps, graphs, and sorting algorithms, along with theoretical explanations and sample inputs/outputs for practical exercises in C/C++. The manual emphasizes fundamental programming skills and data structure manipulation techniques essential for information technology students.
Singly & Circular Linked listKhulna University of Engineering & TecnologyThis document discusses singly linked lists and circular linked lists. It begins with an introduction to linked lists and their advantages over arrays. It then covers the basic concepts of singly linked lists including their structure, basic operations like creation, insertion, deletion and traversal. It also discusses circular linked lists, their structure and how operations on them are similar to singly linked lists. It lists some applications of linked lists and concludes with discussing the disadvantages of linked lists.
Data structures chapter 1priyavanimurugarajanThe document is an introduction to data structures presented by M. Priyavani. It defines key terms like data, records, fields and files. It classifies data structures as primitive (integer, real, character, boolean) and non-primitive (linear like arrays and linked lists, and non-linear like trees and graphs). It describes common operations on data structures like traversing, searching, inserting and deleting. It also introduces algorithms, complexity analysis, and discusses the time-space tradeoff in choosing appropriate data structures.
Shell sort in Data Structure Using CAshish GaurkhedeShell sort is a sorting algorithm created by Donald Shell in 1959 that improves on insertion sort. It works by comparing elements that are farther apart within the list rather than just adjacent elements. It performs multiple passes over the list, each with a larger increment, sorting subsets of the elements. Shell sort is more efficient than bubble sort and faster than plain insertion sort, with its main advantage being for medium sized lists. The choice of increments can impact its performance and potential issues arise if the increments are not relatively prime.
Circular linked listchauhankapilThis 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.
TreesSelvaraj SeeranganThe document is an educational resource focusing on trees in data structures, particularly binary trees and their implementations. It covers tree traversals, binary search trees, and various types of binary trees, detailing their properties and advantages. The content is structured for a data structures course at Kongu Engineering College, incorporating algorithms, applications, and definitions relevant to tree data structures.
Bağli li̇steler (Linked List) – Yiğinlar (Stack) - Kuyruklar Konu Anlatımı Ömer ÖzselçukBu 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.
QueuesLovely Professional UniversityThe document provides an overview of queues as data structures, explaining their classification into primitive and non-primitive types and detailing the operations of inserting and deleting elements (enqueue and dequeue). It describes various types of queues, including circular queues, deques, and priority queues, along with their implementations and applications in computing. Additionally, it highlights the importance of queues in handling processes in operating systems and real-life scenarios like waiting lines.
Лекция 4. Префиксные деревья (Tries, prefix trees)Mikhail KurnosovДокумент представляет собой лекцию о префиксных деревьях (trie), их структуре данных и алгоритмах, связанных с вставкой, поиском и удалением элементов. Обсуждаются примеры применения префиксных деревьев, такие как автозавершение и проверка правописания. Также приводятся детали реализации и вычислительной сложности операций над префиксными деревьями, включая примеры кода на языке C.
GAC DS Priority Queue Presentation 2022.pptCUO VEERANAN VEERANANThis document discusses priority queues and their implementation. It begins by defining different types of queues like simple, circular, priority, and double-ended queues. It then focuses on priority queues, explaining ascending and descending order priority queues. Various data structures for implementing priority queues are covered, including arrays, linked lists, heaps, and binary search trees. Common operations on priority queues like enqueue, dequeue, and peek are also defined. Finally, applications of priority queues in areas like CPU scheduling, graph algorithms, and data compression are mentioned.
Stack and Queue by M.Gomathi Lecturergomathi chlmThis document discusses stacks and queues as abstract data structures. Stacks follow LIFO (last in first out) order, adding and removing elements from one end. Queues follow FIFO (first in first out) order, adding to one end (rear) and removing from the other (front). The document provides examples of stack and queue applications and implementations using arrays.
Data Structure and Algorithms Binary Search TreeManishPrajapati78Binary search trees (BSTs) are data structures that allow for efficient searching, insertion, and deletion. Nodes in a BST are organized so that all left descendants of a node are less than the node's value and all right descendants are greater. This property allows values to be found, inserted, or deleted in O(log n) time on average. Searching involves recursively checking if the target value is less than or greater than the current node's value. Insertion follows the search process and adds the new node in the appropriate place. Deletion handles three cases: removing a leaf, node with one child, or node with two children.
Shell sortRajendran This document discusses Shellsort, an algorithm developed by Donald Shell in 1959 that improves on insertion sort. Shellsort works by comparing elements that are farther apart within an array rather than adjacent elements. It makes multiple passes through a list, sorting subsets of elements using an increment sequence that decreases until the final pass sorts adjacent elements using insertion sort. Shellsort breaks the quadratic time barrier of insertion sort and is faster for medium sized lists but is outperformed by other algorithms like merge, heap, and quick sort for large lists. Examples are provided to illustrate how Shellsort works by sorting a sample list.
single linked listSathasivam RangasamyThis document discusses the implementation of a single linked list data structure. It describes the nodes that make up a linked list, which have an info field to store data and a next field pointing to the next node. The document outlines different ways to represent linked lists, including static arrays and dynamic pointers. It also provides algorithms for common linked list operations like traversing, inserting, and deleting nodes from the beginning, end, or a specified position within the list.
Stack, Queue, Linked List.pptxBharati Vidyapeeth COE, Navi MumbaiThe document discusses various data structures and algorithms. It begins with an overview of common data structures like arrays, lists, stacks, queues, and linked lists. It then provides detailed explanations of stack, queue, circular queue, priority queue, double ended queue, and various linked list implementations including singly linked lists, doubly linked lists, and circular linked lists. For each data structure, it discusses operations like insertion, deletion, traversal, and implementations in C/C++ using structures and pointers.
1.5 binary search treeKrish_ver21) Tree data structures involve nodes that can have zero or more child nodes and at most one parent node. Binary trees restrict nodes to having zero, one, or two children.
2) Binary search trees have the property that all left descendants of a node are less than the node's value and all right descendants are greater. This allows efficient searching in O(log n) time.
3) Common tree operations include insertion, deletion, and traversal. Balanced binary search trees use rotations to maintain balance during these operations.
Singly linked listAmar JukuntlaThis document discusses different operations on linked lists such as insertion, deletion, and traversal. It begins with an introduction to linked lists explaining that each node contains a data field and pointer to the next node. It then covers implementing a basic node structure and various functions like creating a new node, adding a node to the beginning or end of the list, and deleting a node from the beginning, end, or a given position. Traversal and keeping track of previous nodes is important for operations like deletion from within the list. The document provides pseudocode to demonstrate common linked list operations.
Advanced data structures vol. 1Christalin NelsonThe document provides an overview of advanced data structures, detailing various types such as arrays, stacks, queues, linked lists, and hash tables, along with their characteristics and uses. It highlights the importance of selecting appropriate data structures for efficient data management and algorithm design. Specific techniques for collision resolution in hash tables, including open addressing and separate chaining, are also discussed.
DSA Lab Manual C Scheme.pdfBharati Vidyapeeth COE, Navi MumbaiThe document is a laboratory manual for a data structures and analysis course at BVCOE, Navi Mumbai, detailing various experiments focused on programming concepts, array implementations, and linked lists. It outlines specific objectives and operations related to stacks, queues, binary search trees, heaps, graphs, and sorting algorithms, along with theoretical explanations and sample inputs/outputs for practical exercises in C/C++. The manual emphasizes fundamental programming skills and data structure manipulation techniques essential for information technology students.
Singly & Circular Linked listKhulna University of Engineering & TecnologyThis document discusses singly linked lists and circular linked lists. It begins with an introduction to linked lists and their advantages over arrays. It then covers the basic concepts of singly linked lists including their structure, basic operations like creation, insertion, deletion and traversal. It also discusses circular linked lists, their structure and how operations on them are similar to singly linked lists. It lists some applications of linked lists and concludes with discussing the disadvantages of linked lists.
Data structures chapter 1priyavanimurugarajanThe document is an introduction to data structures presented by M. Priyavani. It defines key terms like data, records, fields and files. It classifies data structures as primitive (integer, real, character, boolean) and non-primitive (linear like arrays and linked lists, and non-linear like trees and graphs). It describes common operations on data structures like traversing, searching, inserting and deleting. It also introduces algorithms, complexity analysis, and discusses the time-space tradeoff in choosing appropriate data structures.
Shell sort in Data Structure Using CAshish GaurkhedeShell sort is a sorting algorithm created by Donald Shell in 1959 that improves on insertion sort. It works by comparing elements that are farther apart within the list rather than just adjacent elements. It performs multiple passes over the list, each with a larger increment, sorting subsets of the elements. Shell sort is more efficient than bubble sort and faster than plain insertion sort, with its main advantage being for medium sized lists. The choice of increments can impact its performance and potential issues arise if the increments are not relatively prime.
Circular linked listchauhankapilThis 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.
TreesSelvaraj SeeranganThe document is an educational resource focusing on trees in data structures, particularly binary trees and their implementations. It covers tree traversals, binary search trees, and various types of binary trees, detailing their properties and advantages. The content is structured for a data structures course at Kongu Engineering College, incorporating algorithms, applications, and definitions relevant to tree data structures.
Yzm 2116 - Bölüm 5 (Queue, Kuyruk, Basit, Dairesel, Öncelikli)
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 - 5
Bu bölümde,
• Kuyruk VY ve ADT
• Basit Kuyruk (Simple Queue)
• Döngüsel Kuyruk (Circular Queue)
• Öncelik Kuyruğu (Priority Queue)
konusuna değinilecektir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
3. Kuyruk Giriş
• Kuyruk, eleman eklemelerin sondan (rear) ve eleman
çıkarmaların bastan (front) yapıldığı, (First In First Out-
İlk Gelen İlk Çıkar – FIFO) olarak modellenen, doğrusal
bir veri saklama yapısıdır.
• Bir elemanın kuyruğa girmesi insert (literatürde put,
add veya enqueue olarak da geçer) işlemi iken listeden
silinmesi remove (delete veya dequeue) işlemidir.
• Insert’ler kuyruğun arkasından yapılırken, remove’lar
kuyruğun önünden yapılırlar.
• Boş bir kuyruktan eleman silmeye çalışmak underflow
hatası üretirken, dolu bir kuyruğa eleman eklemeye
çalışmak overflow hatası üretir.
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
4. Kuyruk Giriş (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Kuyruk yapısı, yığın yapısına oldukça benzemektedir. İkisinde
de eleman ekleme işlemi en sondan yapılmaktadır.
• Aralarındaki fark eleman çıkartmanın yığın yapısında en
sondan, kuyruk yapısında ise en baştan yapılmasıdır.
5. Kuyruk ADT
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Insert(obj) Kuyruğun sonuna (rear) eleman ekler.
obj Remove() Kuyruğun önündeki (front) ilk elemanı yani işi biten
elemanı siler. Kuyruk boşsa hata döner.
obj Peek() Kuyruğun önündeki (front) elemanı geriye döndürür.
bool IsEmpty() Kuyruk boşsa true değilse false döner.
public interface IQueue
{
void Insert(object o);
object Remove();
object Peek();
Boolean IsEmpty();
}
6. Kuyruk Dizi Gerçekleştirim
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Queue dizi implementasyonu için kurallar
• Queue dizi implemetasyonunda dizimizi queue[n] olarak
tanımlarsak,
o n kuyruktaki maksimum eleman sayısıdır.
• Implementasyonda front ve rear olmak üzere 2 tane değişken
tanımlanır.
o front: kuyruğun önündeki elemanı temsil eder.
front = -1 ise kuyruk boştur.
Kuyruktan her eleman çıkartıldığında (REMOVE) front bir
artar.
o rear: kuyruğun sonundaki elemanı temsil eder.
Kuyruğa her eleman eklendiğinde (INSERT) rear bir artar.
7. Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
front ve rear
• Kuyruğa bir eleman eklenince ne olur?
• Kuyruktan bir eleman çıkartılınca (işi bitince ne olur?)
Kuyruk Dizi Gerçekleştirim (devam…)
8. Kuyruk Dizi Gerçekleştirim (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Insert(333)
Delete()
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
10. Kuyruk Dizi Gerçekleştirim (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
ÖRNEK 2:
F için yer kalmadı !!!
2 elemanlık alan kullanılamaz hale geldi !!!
11. Simple Queue
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Simple Queue (basit kuyruk) olarak
adlandırılan bu kuyruk tipi
o hep ileri yönde hareket etmekte ve
o verimsiz alan kullanımına neden olmaktadır.
12. Simple Queue Kaynak Kod
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
//Sınıf Tanımı
public class SimpleArrayTypedQueue: IQueue
//Üye Değişkenleri
private object[] Queue;
private int front = -1;
private int rear = -1;
private int size = 0;
private int count = 0;
//Constructor
public SimpleArrayTypedQueue(int size)
{
this.size = size;
Queue = new object[size];
}
13. Simple Queue Kaynak Kod (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
public void Insert(object o)
{
if ((count == size) || (rear == size -1))
throw new Exception("Queue dolu.");
if (front == -1)
front = 0;
Queue[++rear] = o;
count++;
}
14. Simple Queue Kaynak Kod (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
public object Remove()
{
if (IsEmpty())
throw new Exception("Queue boş.");
object temp = Queue[front];
Queue[front] = null;
front++;
count--;
return temp;
}
public bool IsEmpty()
{
return (count == 0);
}
15. Simple Queue İyileştirmeler
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
Basit kuyruk gerçekleştiriminde çeşitli iyileştirmeler
yapılabilir:
İyileştirme 1: Silme sonucunda kuyrukta hiç eleman
kalmazsa, kuyruk sıfırdan oluşturulmuş gibi ilk durumuna
getirilebilir.
İyileştirme 2: Kaydırma (shift) işlemi yapılarak öndeki
boş yerler kullanıma sokulmak üzere arkaya taşınabilir,
fakat kaydırmalar aşırı zaman alır ve maliyetlidir.
İyileştirme 3: Diğer iyileştirme kuyruğun boşta kalan
öndeki alanlarını kullanmaya yönelik bir geliştirme
yapılabilir (Circular - Döngüsel Kuyruk).
16. Circular Queue
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Basit kuyrukta karşılaşılan ve kuyruğun başında
kalan kullanılamayan alan problemini çözmek
için döngüsel kuyruk veri yapısı geliştirilmiştir.
• Döngüsel kuyrukta,
o Kuyruğun başı ile sonu birleştirilmiştir.
• Önde boşalan yerler,
arkadaymış gibi otomatik
olarak kullanıma sokulur.
17. Döngüsel Kuyruk Dizi Gerçekleştirim
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
ÖRNEK 3:
18. Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
ÖRNEK 3:
Döngüsel Kuyruk Dizi Gerçekleştirim (devam…)
19. Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
ÖRNEK 3:
Döngüsel Kuyruk Dizi Gerçekleştirim (devam…)
20. Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
ÖRNEK 3:
Adım 6 sonrasında oluşan son durumun döngüsel kuyruk ile
gösterimi aşağıdaki gibidir:
Döngüsel Kuyruk Dizi Gerçekleştirim (devam…)
21. Döngüsel Kuyruk Kaynak Kod (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
public void Insert(object o)
{
if ((count == size) || (rear == size -1))
throw new Exception("Queue dolu.");
if (front == -1)
front = 0;
//Circular Code Değişikliği
if (rear == size - 1)
{
rear = 0;
Queue[rear] = o;
}
else
Queue[++rear] = o;
count++;
}
22. Döngüsel Kuyruk Kaynak Kod (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
public object Remove()
{
if (IsEmpty())
throw new Exception("Queue boş.");
object temp = Queue[front];
Queue[front] = null;
//Circular Code Değişikliği
if (front == size - 1)
front = 0;
else
front++;
count--;
return temp;
}
public bool IsEmpty()
{
return (count == 0);
}
23. Priority Queue
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Standart kuyruk veri yapısı önceliklendirme
eksikliği nedeniyle, birçok durumda
(problemde) kullanılmak için uygun
olmayabilir.
• Gerçek hayatta uygulanan kuyruk yapılarında
öncelik durumu dikkate alınır, önceliği yüksek
olanlar önce işlem görürler.
24. Priority Queue (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Örneğin; yazılım bakım sürecinde yazılım
departmanına iletilen hataları düşünelim. İletilen
her hata bir havuza atılır ve sırasıyla uygun
yazılımcıya iletilir. Bazı hatalar diğerlerinden
daha önceliklidir.
• Mesela sistemdeki tüm modülleri etkileyen hatalar
çok daha kritik olup diğerlerinden daha önce
tamamlanmalıdır.
• Aynı şekilde işletim sistemlerinde bazı prosesler
diğerlerinden daha öncelikli olarak çalışmak
durumundadır.
25. Priority Queue (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Öncelik kuyrukları,
• artan ve azalan
olmak üzere ikiye ayrılırlar.
• Diğer veri yapılarında olduğu gibi kuyrukta
bulunan elemanlar, string veya integer gibi
basit veri türünde olabileceği gibi özelliklere
(attribute) sahip bir nesne de olabilir.
• Öncelik kriterinin ne olacağı kuyruktan kuyruğa
değişkenlik gösterir.
• Kuyruğa eklenen elemanın kendisi veya
herhangi bir özelliği, öncelik kriteri olabilir.
26. Priority Queue (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Örneğin; telefon rehberi uygulamasında,
• Kuyruktaki her eleman soyad, ad, adres ve telefon
numarası özelliklerinden oluşmakta ve kuyruk
soyada göre sıralanmaktadır.
• Öncelik kuyrukları;
• Dizi,
• Bağlı Liste
• Binary Heap
kullanılarak implemente edilebilir.
27. PQ Dizi Gerçekleştirim
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
• Artan tipteki öncelik kuyruğunda en küçük
değere sahip eleman en öncelikli olarak
kuyruktan silinir (yani ilk olarak işlem görür).
ÖRNEK 4:
28. PQ Dizi Gerçekleştirim (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
ÖRNEK 4:
29. PQ Dizi Gerçekleştirim (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
ÖRNEK 4:
30. PQ Dizi Gerçekleştirim (devam…)
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
ÖRNEK 4:
31. Priority Queue Kaynak Kod
Celal Bayar Üniversitesi – YZM 2116 Veri Yapıları
public class PriorityQueue: IQueue
private object[] Queue;
private int front = -1;
//Not1: rear değeri hep 0 olduğu için değişmez.
//Not2: size ve count değişkenlerinden birisi
//istenirse kullanılmayabilir
private int size = 0;
private int count = 0;
public PriorityQueue(int size)
{
this.size = size;
Queue = new object[size];
}
32. Priority Queue Kaynak Kod (devam…)
public void Insert(object o)
{
if (count == size)
throw new Exception("Queue is full");
if (IsEmpty())
{
front++;
Queue[front] = o;
}
else
{
int i;
//Not3:
//Son elemandan başlayarak geriye doğru kuyruk kontrol ediliyor
//Eklenecek elemanın pozisyonu belirleniyor
//Var olan elemanlar kaydırılıyor
for (i = count - 1; i >= 0; i--)
{
if ((int)o > (int)Queue[i])
Queue[i + 1] = Queue[i];
else
break;
}
Queue[i + 1] = o;
front++;
}
count++;
}
33. Priority Queue Kaynak Kod (devam…)
public object Remove()
{
if (this.IsEmpty())
{
throw new Exception("Queue is empty...");
}
object temp = Queue[front];
Queue[front] = null;
front--;
count--;
return temp;
}
34. Queue İşlem Karmaşıklığı
İşlem Basit
Kuyruk
Döngüsel
Kuyruk
Öncelik
Kuyruğu
Insert O(1) O(1) O(n)
Remove O(1) O(1) O(1)
Peek O(1) O(1) O(1)
IsEmpty O(1) O(1) O(1)
• Dizi ile implemente edilmiş kuyruk türlerinin
işlem karmaşıklığı aşağıdaki tabloda verilmiştir.
36. 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ı