Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

DS & Al - MCS103 - Module 3- Heaps and Balanced Search Trees

Rating
-
Sold
-
Pages
71
Grade
A+
Uploaded on
25-02-2026
Written in
2025/2026

DS & Al - MCS103 - Module 3- Heaps and Balanced Search Trees

Institution
Course

Content preview

lOMoARcPSD|44613495




DS & Al- MCS103 - Module 3Notes


Data Structure and Algorithms for Problem solving (Visvesvaraya Technological
University)




Scan to open on Studocu




Studocu is not sponsored or endorsed by any college or university
Downloaded by Samuel Wachira ndiang'ui ()

, lOMoARcPSD|44613495




Data Structures & Algorithms for Problem Solving – MCS103 2024-25



Module 3
Heaps




Heap
A Heap is a complete binary tree that follows the heap-order property,
meaning:
 Max-Heap: The parent node is always greater than or equal to its
children.
 Min-Heap: The parent node is always smaller than or equal to its
children.
Properties of Heap:
1. Complete Binary Tree: All levels are completely filled except possibly
the last.
2. Heap-Order Property: The value of each parent node is either greater
(Max-Heap) or smaller (Min-Heap) than its children.
Applications: Used in priority queues, Dijkstra’s algorithm, and heapsort.


Balanced Search Trees as Heaps
In data structures, both Balanced Search Trees and Heaps are used for efficient
data retrieval, but they serve different purposes. However, a connection can be
established between them in terms of heap-order property and balanced height.
1. Balanced Search Trees
A Balanced Search Tree is a binary search tree (BST) that maintains a height
close to O (log n), ensuring efficient operations like insertion, deletion, and
searching. Examples include:
 AVL Trees (maintaining balance using height difference)
 Red-Black Trees (balancing using colour properties)
 B-Trees (used in databases, keeping nodes balanced)

Page 1 of 70


Downloaded by Samuel Wachira ndiang'ui ()

, lOMoARcPSD|44613495




Data Structures & Algorithms for Problem Solving – MCS103 2024-25



2. Heaps
A Heap is a specialized binary tree that follows the heap-order property:
 Max-Heap: The parent node is always greater than or equal to its
children.
 Min-Heap: The parent node is always smaller than or equal to its
children.
It supports efficient priority queue operations, with O (1) access to the root and
O (log n) insertions/deletions.
3. Balanced Search Trees vs. Heaps
Feature Balanced Search Tree Heap
Structure Binary Search Tree with Complete Binary Tree
balance constraints
Order Property In-order traversal gives No strict order, only
sorted elements heap property
Search Complexity O (log n) O (n) in the worst case
Insert/Delete O (log n) O (log n)
Complexity
Application Database indexing, Priority Queues,
efficient searching Scheduling

4. Balanced Search Trees as Heaps
Although Balanced Search Trees are mainly used for ordered retrieval, they can
simulate a Heap-like structure by:
1. Using the Root Node as a Min/Max Element: In a balanced BST, the
leftmost node contains the smallest element, similar to a Min-Heap. The
rightmost node contains the largest element, similar to a Max-Heap.
2. Heapifying a BST: If we maintain a complete binary tree property along
with a heap-order property, a BST can behave like a Heap.
3. Priority Queue Implementation: A balanced search tree like a Treap (Tree
+ Heap) combines the properties of a BST and a Heap, where the
structure follows a BST, and the values follow the heap property.
5. Balanced Search Trees and Heaps are closely related in terms of logarithmic
time complexity for insertions and deletions. However, Heaps prioritize
efficient root access, while Balanced Search Trees focus on ordered traversal.


Page 2 of 70


Downloaded by Samuel Wachira ndiang'ui ()

, lOMoARcPSD|44613495




Data Structures & Algorithms for Problem Solving – MCS103 2024-25



typedef struct { key_t key;
object_t *object;
}heap_el_t;
typedef struct { heap_el_t current_min;
tree_node_t *tree;
}heap_t;




heap_t *create_heap(void)
{
heap_t *hp;
hp = (heap_t *) malloc( sizeof(heap_t) );
hp->tree = create_tree();
return( hp );
}
int heap_empty(heap_t *hp)
{
return( hp->tree->left == NULL );
}
heap_el_t find_min(heap_t *hp)
{
return( hp->current_min );
}
void insert_heap( key_t new_key, object_t *new_obj, heap_t *hp)
{
If (hp->tree->left == NULL || new_key < hp->current_min.key )
{


Page 3 of 70


Downloaded by Samuel Wachira ndiang'ui ()

Written for

Institution
Study
Course

Document information

Uploaded on
February 25, 2026
Number of pages
71
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

22.99 $
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Writewise Chamberlain College Of Nursing
Follow You need to be logged in order to follow users or courses
Sold
50
Member since
1 year
Number of followers
5
Documents
1828
Last sold
1 day ago
Writewise - Stuvia US

Writewise - Stuvia US Certified tutor, offering accurate, reliable, and current study materials to support students in their exam preparation and assignments. Aiming to provide the best resources, such as summaries, nursing exam test. Up-to-date exams and assignments, Detailed test banks with verified questions and answers, Elaborate exam solutions, Case studies and discussions Customized package deals tailored to your needs. I’m committed to providing only high-quality documents to ensure the best outcomes. Get instant access to expertly prepared materials designed to help you excel in your academic journey. Reach out today and take a step closer to achieving your goals! Always be Encouraged to leave a review after sale, all complements and comments, positive &amp; Negative are appreciated to guide for better changes.

Read more Read less
3.0

4 reviews

5
1
4
0
3
2
2
0
1
1

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions