Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

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

Beoordeling
-
Verkocht
-
Pagina's
71
Cijfer
A+
Geüpload op
25-02-2026
Geschreven in
2025/2026

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

Instelling
Vak

Voorbeeld van de inhoud

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 ()

Geschreven voor

Instelling
Studie
Vak

Documentinformatie

Geüpload op
25 februari 2026
Aantal pagina's
71
Geschreven in
2025/2026
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

€20,40
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
Writewise Chamberlain College Of Nursing
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
52
Lid sinds
1 jaar
Aantal volgers
5
Documenten
1826
Laatst verkocht
1 dag geleden
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.

Lees meer Lees minder
3,0

4 beoordelingen

5
1
4
0
3
2
2
0
1
1

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen