Data Structures Module 3
Data Structures Module 3
Ashwini S
Assistant Professor
Ashwini S Data Structures with C++ 25-01-2024
2 PRIORITY QUEUE
• A priority queue is a special type of queue in which each element is associated with a
priority value.
• And, elements are served on the basis of their priority. That is, higher priority elements
are served first.
• However, if elements with the same priority occur, they are served according to their
order in the queue.
Ashwini S Data Structures with C++ 25-01-2024
5
Ashwini S Data Structures with C++ 25-01-2024
6
Ashwini S Data Structures with C++ 25-01-2024
7
Ashwini S Data Structures with C++ 25-01-2024
9 HEAP OPERATIONS
Heapify
• Heapify is the process of creating a heap data structure from a binary tree. It is used to
create a Min-Heap or a Max-Heap.
1. Let the input array be
Ashwini S Data Structures with C++ 25-01-2024
10
11
12 ALGORITHM
Ashwini S Data Structures with C++ 25-01-2024
14
20
Ashwini S Data Structures with C++ 25-01-2024
21
Ashwini S Data Structures with C++ 25-01-2024
22
Ashwini S Data Structures with C++ 25-01-2024
23
Ashwini S Data Structures with C++ 25-01-2024
• Heap Sort
Ashwini S Data Structures with C++ 25-01-2024
26
Ashwini S Data Structures with C++ 25-01-2024
27 BUILD MAX-HEAP
28
Ashwini S Data Structures with C++ 25-01-2024
29
Ashwini S Data Structures with C++ 25-01-2024
1. Since the tree satisfies Max-Heap property, then the largest item is stored at the root node.
2. Swap: Remove the root element and put at the end of the array (nth position) Put the last item
of the tree (heap) at the vacant place.
3. Remove: Reduce the size of the heap by 1.
4. Heapify: Heapify the root element again so that we have the highest element at root.
5. The process is repeated until all the items of the list are sorted.
Ashwini S Data Structures with C++ 25-01-2024
31
Ashwini S Data Structures with C++ 25-01-2024
32
Ashwini S Data Structures with C++ 25-01-2024
33
Ashwini S Data Structures with C++ 25-01-2024
• Deque or Double Ended Queue is a type of queue in which insertion and removal of
elements can either be performed from the front or the rear. Thus, it does not follow
FIFO rule (First In First Out).
Ashwini S Data Structures with C++ 25-01-2024
35 TYPES OF DEQUE
36
Ashwini S Data Structures with C++ 25-01-2024
37
Ashwini S Data Structures with C++ 25-01-2024
38
Ashwini S Data Structures with C++ 25-01-2024
39
Ashwini S Data Structures with C++ 25-01-2024
41 EXTERNAL SORTING
• External sorting is a term for a class of sorting algorithms that can handle massive
amounts of data. External sorting is required when the data being sorted does not fit into
the main memory of a computing device (usually RAM) and instead, must reside in the
slower external memory (usually a hard drive).
• External sorting typically uses a hybrid sort-merge strategy. In the sorting phase, chunks
of data small enough to fit in the main memory are read, sorted, and written out to a
temporary file. In the merge phase, the sorted sub-files are combined into a single larger
file.
Ashwini S Data Structures with C++ 25-01-2024
43 POLYPHASE MERGE
• Polyphase merge is a variation of the bottom-up merge sort algorithm optimized for
external sorting. It uses an uneven distribution of sub-lists in the initial merging phase,
making it more efficient than traditional merge sort when there are fewer than 8 external
working files.
44 MULTIWAY MERGE
• Multiway merge is another external sorting algorithm that merges multiple sorted runs
simultaneously. It requires more storage space than polyphase merge (one input file and one
output file per way) but can be faster for larger datasets and with more available storage
devices.
Finance:
• Fraud detection by analyzing millions of transactions
• Portfolio optimization with large market data sets
• Credit risk assessment from vast credit histories
Healthcare:
• Genomic analysis of DNA sequencing data
• Efficient comparison of medical images for diagnosis
• Tracking and analyzing disease outbreaks
Ashwini S Data Structures with C++ 25-01-2024
46
Other Industries:
• E-commerce: personalizing recommendations, targeted advertising, and fraud detection
• Log analysis: website traffic, server logs, and security issues
• Scientific Computing: analyzing simulations and measurements
Everyday Applications:
• Email sorting algorithms utilize external sorting to organize large inboxes and prioritize
messages based on sender, keywords, and importance.
• Personal finance software may use external sorting to categorize and analyze personal
expenses for budgeting and financial planning.
Ashwini S Data Structures with C++ 25-01-2024
47
THANK YOU