The document discusses heap data structures and their use in priority queues and heapsort. It defines a heap as a complete binary tree stored in an array. Each node stores a value, with the heap property being that a node's value is greater than or equal to its children's values (for a max heap). Algorithms like Max-Heapify, Build-Max-Heap, Heap-Extract-Max, and Heap-Increase-Key are presented to maintain the heap property during operations. Priority queues use heaps to efficiently retrieve the maximum element, while heapsort sorts an array by building a max heap and repeatedly extracting elements.
It is related to Analysis and Design Of Algorithms Subject.Basically it describe basic of topological sorting, it's algorithm and step by step process to solve the example of topological sort.
It is related to Analysis and Design Of Algorithms Subject.Basically it describe basic of topological sorting, it's algorithm and step by step process to solve the example of topological sort.
hashing is encryption process mostly used in programming language for security purpose.
This presentation will you understand all about hashing and also different techniques used in it for encryption process
This PPT is all about the Tree basic on fundamentals of B and B+ Tree with it's Various (Search,Insert and Delete) Operations performed on it and their Examples...
Traversal is a process to visit all the nodes of a tree and may print their values too. Because, all nodes are connected via edges (links) we always start from the root (head) node. That is, we cannot randomly access a node in a tree.
a. Concept and Definition
b. Binary Tree
c. Introduction and application
d. Operation
e. Types of Binary Tree
• Complete
• Strictly
• Almost Complete
f. Huffman algorithm
g. Binary Search Tree
• Insertion
• Deletion
• Searching
h. Tree Traversal
• Pre-order traversal
• In-order traversal
• Post-order traversal
Slides at myblog
http://www.ashimlamichhane.com.np/2016/07/tree-slide-for-data-structure-and-algorithm/
Assignments at github
https://github.com/ashim888/dataStructureAndAlgorithm/tree/dev/Assignments/assignment_7
HEAP SORT ILLUSTRATED WITH HEAPIFY, BUILD HEAP FOR DYNAMIC ARRAYS.
Heap sort is a comparison-based sorting technique based on Binary Heap data structure. It is similar to the selection sort where we first find the minimum element and place the minimum element at the beginning. Repeat the same process for the remaining elements.
hashing is encryption process mostly used in programming language for security purpose.
This presentation will you understand all about hashing and also different techniques used in it for encryption process
This PPT is all about the Tree basic on fundamentals of B and B+ Tree with it's Various (Search,Insert and Delete) Operations performed on it and their Examples...
Traversal is a process to visit all the nodes of a tree and may print their values too. Because, all nodes are connected via edges (links) we always start from the root (head) node. That is, we cannot randomly access a node in a tree.
a. Concept and Definition
b. Binary Tree
c. Introduction and application
d. Operation
e. Types of Binary Tree
• Complete
• Strictly
• Almost Complete
f. Huffman algorithm
g. Binary Search Tree
• Insertion
• Deletion
• Searching
h. Tree Traversal
• Pre-order traversal
• In-order traversal
• Post-order traversal
Slides at myblog
http://www.ashimlamichhane.com.np/2016/07/tree-slide-for-data-structure-and-algorithm/
Assignments at github
https://github.com/ashim888/dataStructureAndAlgorithm/tree/dev/Assignments/assignment_7
HEAP SORT ILLUSTRATED WITH HEAPIFY, BUILD HEAP FOR DYNAMIC ARRAYS.
Heap sort is a comparison-based sorting technique based on Binary Heap data structure. It is similar to the selection sort where we first find the minimum element and place the minimum element at the beginning. Repeat the same process for the remaining elements.
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic ProgammingTraian Rebedea
Course 4 for the Algorithm Design and Complexity course at the Faculty of Engineering in Foreign Languages - Politehnica University of Bucharest, Romania
Using a circularly-linked list made the solution trivial. The solution would have been more difficult if an array had been used. This illustrates the fact that the choice of the appropriate data structures can significantly simplify an algorithm. It can make the algorithm much faster and efficient.
Frequency and similarity aware partitioning for cloud storage based on space ...redpel dot com
Frequency and similarity aware partitioning for cloud storage based on space time utility maximization model.
for more ieee paper / full abstract / implementation , just visit www.redpel.com
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
1. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heap Data Structure
Zahoor Jan
2. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
A (binary) heap data structure is an array object that can be
viewed as a complete binary tree
Each node of the tree corresponds to an element of the array that
stores the value in the node
A complete binary tree is one where all the internal nodes have
exactly 2 children, and all the leaves are on the same level.
The tree is completely filled on all levels except possibly the
lowest, which is filled from left to right up to a point
Leaf nodes are nodes without children.
Leaf node
Interior node
Edge
3. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
Height of a node: The number of edges starting at that node, and going
down to the furthest leaf.
Height of the heap: The maximum number of edges from the root to a leaf.
Root
Height of blue
node = 1
Height of root = 3
4. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
Complete binary tree– if not full, then the only
unfilled level is filled in from left to right.
2 3
4 5 6 7
8 9 10 11 12 13
1
2 3
4 5 6
127 8 9 10 11
1
Parent(i)
return i/2
Left(i)
return 2i
Right(i)
return 2i + 1
5. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
The heap property of a tree is a condition that must be true for
the tree to be considered a heap.
Min-heap property: for min-heaps, requires
A[parent(i)] ≤ A[i]
So, the root of any sub-tree holds the least value in that sub-tree.
Max-heap property: for max-heaps, requires
A[parent(i)] ≥ A[i]
The root of any sub-tree holds the greatest value in the sub-tree.
6. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
Looks like a max heap, but max-heap property is violated at
indices 11 and 12. Why?
because those nodes’ parents have smaller values than their
children.
2
8
3
8
4
8
5
7
6
8
7
1
8
6
9
7
10
5
11
8
12
9
1
9
7. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
Assume we are given a tree represented by a linear array A, and
such that i ≤ length[A], and the trees rooted at Left(i) and
Right(i) are heaps. Then, to create a heap rooted at A[i], use
procedure Max-Heapify(A,i):
Max-Heapify(A,i)
1. l Left(i)
2. r Right(i)
3. if l ≤ heap-size[A] and A[l] > A[i]
4. then largest l
5. else largest i
6. if r ≤ heap-size[A] and A[r] > A[largest]
7. then largest r
8. if largest ≠ i
9. then swap( A[i], A[largest])
Max-Heapify(A, largest)
20
9
19 18
6 7
17 16 17 16 1
10
8. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
If either child of A[i] is greater than A[i], the greatest child
is exchanged with A[i]. So, A[i] moves down in the heap.
The move of A[i] may have caused a violation of the max-
heap property at it’s new location.
So, we must recursively call Max-Heapify(A,i) at the
location i where the node “lands”.
The above is the top-down approach of Max-Heapify(A,i)
20
9
19 18
6 7
17 16 17 16 1
10
10. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Run Time of Max-Heapify()
Run time of Max-Heapify().
How many nodes, in terms of n, is in the sub-tree with the most nodes?
2 n / 3
So, worst case would follow a path that included the most nodes
T(n) = T(2n/3) + Θ(1)
Why Θ(1)? Note that all the work in lines 1-7 is simple assignments or
comparisons, so they are constant time, or Θ(1).
2
1
2 3
4 5 6 7
8 9 10 11
1
2 3
4 5
1
2(2) / 3 = 2
1 ≤ 2 2(5) / 3 = 3
3 ≤ 3 2(11) / 3 = 8
7 ≤ 8
11. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
So, what must we do to build a heap?
We call Max-Heapify(A,i) for every i starting at last node
and going to the root.
Why Bottom-up?
Because Max-Heapify() moves the larger node upward
into the root. If we start at the top and go to larger
node indices, the highest a node can move is to the root
of that sub-tree. But what if there is a violation between
the sub-tree’s root and its parent?
So, we must start from the bottom and go towards the
root to fix the problems caused by moving larger nodes
into the root of sub-trees.
12. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
Bad-Build-Max-Heap(A)
1. heap-size[A] length[A]
2. for i length[A] downto 1
3. do Max-Heapify(A,i)
Can this implementation be improved?
Sure can!
2
3
4 5
6 7
8 9 10 11
1
13. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heaps
Without going through a formal proof, notice that there is no
need to call Max-Heapify() on leaf nodes. At most, the
internal node with the largest index is at most equal to
length[A]/2.
Since this may be odd, should we use the floor or the ceiling?
In the case below, it is clear that we really need the floor
of length[A]/2 which is 5, and not the ceiling, which is 6.
Build-Max-Heap(A)
1. heap-size[A] length[A]
2. for i length[A]/2 downto 1
3. do Max-Heapify(A,i)
2 3
4 5 6 7
8 9 10 11
1
14. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: building a heap (1)
4 1 3 2 16 9 10 14 8 7
1 2 3 4 5 6 7 8 9 10
4
1
2 16
7814
3
9 10
1
2 3
4 5 6 7
8 9 10
15. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: building a heap (2)
4
1
2 16
7814
3
9 10
1
2 3
4 5 6 7
8 9 10
16. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: building a heap (4)
4
1
14 16
782
3
9 10
1
2 3
4 5 6 7
8 9 10
17. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: building a heap (5)
4
1
14 16
782
10
9 3
1
2 3
4 5 6 7
8 9 10
18. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: building a heap (6)
4
16
14 7
182
10
9 3
1
2 3
4 5 6 7
8 9 10
19. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: building a heap (7)
16
14
8 7
142
10
9 3
1
2 3
4 5 6 7
8 9 10
20. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Priority Queues
A priority queue is a data structure for maintaining a set S of elements, each with
an associated value called a key.
We will only consider a max-priority queue.
If we give the key a meaning, such as priority, so that elements with the highest
priority have the highest value of key, then we can use the heap structure to
extract the element with the highest priority.
21. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Priority Queues
Max priority queue supports the following operations:
Max-Heap-Insert(A,key): insert key into heap, maintaining heap property
Heap-Maximum(A): returns the heap element with the largest key
Heap-Extract-Max(A): returns and removes the heap element with the largest key,
and maintains the heap property
Heap-Increase-Key(A,i,key): used (at least) by
Max-Heap-Insert() to set A[i] A[key], and then maintaining the heap property.
22. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Priority Queues
Heap-Maximum(A)
1. return A[1]
Heap-Extract-Max(A)
1. if heap-size[A] < 1
2. then error “heap underflow”
3. max A[1]
4. A[1] A[heap-size[A] ]
5. heap-size[A] heap-size[A] - 1
6. Max-Heapify(A,1)
7. return max
23. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Priority Queues
Heap-Increase-Key(A,i,key)
1. if key < A[i]
2. then error “new key is smaller than current key”
3. A[i] key
4. while i > 1 and A[Parent(i)] < A[i]
5. do exchange A[i] A[Parent(i)]
6. i Parent(i)
Max-Heap-Insert(A,key)
1. heap-size[A] heap-size[A]+1
2. A[heap-size[A]] – ∞
3. Heap-Increase-Key(A, heap-size[A], key)
24. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: increase key (1)
16
14
8 7
142
10
9 3
1
2 3
4 5 6 7
8 9 10
increase 4 to 15
25. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: increase key (2)
16
14
8 7
1152
10
9 3
1
2 3
4 5 6 7
8 9 10
26. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: increase key (3)
16
14
15 7
182
10
9 3
1
2 3
4 5 6 7
8 9 10
27. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: increase key (4)
16
15
14 7
182
10
9 3
1
2 3
4 5 6 7
8 9 10
28. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heap Sort
Finally, how can we get the keys sorted in an array A? We know that a heap is
not necessarily sorted as the following sequence illustrates:
A = < 100, 50, 25, 40, 30 >
Use the algorithm Heapsort():
Heapsort(A)
1. Build-Max-Heap(A)
2. for i length[A] downto 2
3. do exchange A[1] ↔ A[i]
4. heap-size[A] heap-size[A]-1
5. Max-Heapify(A,1)
Build-Max-Heap() is O(n), Max-Heapify() is O(lg n), but is executed n times,
so runtime for Heapsort(A) is O(nlgn).
29. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Heapsort
Heapsort(A)
1. Build-Max-Heap(A)
2. for i length[A] downto 2
3. do exchange A[1] ↔ A[i]
4. heap-size[A] heap-size[A]-1
5. Max-Heapify(A,1)
On line 1, we create the heap. Keep in mind that the largest element is at the
root. So, why not put the element that is currently in the root at the last index
of A[]?
We will exchange the last element in A, based on the value of heap-size[A],
with A[1], as per line 3.
Then we will reduce heap-size[A] by one so that we can make sure that
putting A[heap-size] into A[1] from line 3 doesn’t violate the heap property. But
we don’t want to touch the max element, so that’s why heap-size is reduced.
Continue in this fashion until i=2. Why don’t we care about i=1? It’s already done
30. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort
16
14
8 7
142
10
9 3
1
2 3
4 5 6 7
8 9 10
16 14 10 8 7 9 3 2 4 1
31. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort (2)
14
8
4 7
1612
10
9 3
1
2 3
4 5 6 7
8 9 10
32. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort (3)
10
8
4 7
16142
9
1 3
1
2 3
4 5 6 7
8 9 10
33. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort (4)
9
8
4 7
161410
3
1 2
1
2 3
4 5 6 7
8 9 10
34. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort (4)
8
7
4 2
161410
1
2 3
4 5 6 7
8 9 10
9
3
1
35. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort (5)
7
4
1 2
161410
3
8 9
1
2 3
4 5 6 7
8 9 10
36. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort (6)
4
2
1 7
161410
3
8 9
1
2 3
4 5 6 7
8 9 10
37. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort (7)
3
2
4 7
161410
1
8 9
1
2 3
4 5 6 7
8 9 10
38. Department of Computer Science University of Peshawar
Heap Data Structure Advance Algorithms (Spring 2009)
Example: Heap-Sort (8)
2
1
4 7
161410
3
8 9
1
2 3
4 5 6 7
8 9 10
1 2 3 4 7 8 9 10 14 16