0% found this document useful (0 votes)
11 views153 pages

DAA Module-3-2

Uploaded by

Suurya KS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views153 pages

DAA Module-3-2

Uploaded by

Suurya KS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 153

Module-3

Minimum cost spanning trees


Prim’s, Kruskal’s Algorithm & Single source
shortest paths: Dijkstra's Algorithm.
Kruskal’s Algorithm for
Minimum Spanning Tree
The applications of Kruskal's algorithm are -

 Kruskal's algorithm can be used to layout electrical wiring among cities.

 It can be used to lay down LAN connections.


0 0 0 50 1
0 023

0 1 2 3 4 5
DAA Lab PRG-5
Transform and Conquer
Approach: Heaps and Heap Sort
Heap Sort Algorithm
Heap sort processes the elements by creating the min-heap or max-heap using
the elements of the given array. Min-heap or max-heap represents the
ordering of array in which the root element represents the minimum or
maximum element of the array.

Heap sort basically recursively performs two main operations -


•Build a heap H, using the elements of array.
•Repeatedly delete the root element of the heap formed in 1st phase.

Before knowing more about the heap sort, let's first see a brief description
of Heap.
What is a heap?-
A heap is a complete binary tree
The binary tree is a tree in which the node can have the utmost two children.
A complete binary tree is a binary tree in which all the levels except the last level,
i.e., leaf node, should be completely filled, and all the nodes should be left-justified.

What is heap sort?


Heapsort is a popular and efficient sorting algorithm. The concept of heap sort is to
eliminate the elements one by one from the heap part of the list, and then insert
them into the sorted part of the list.

Heapsort is the in-place sorting algorithm.


Heap sort is one of the sorting algorithms used to arrange a list of elements in order. Heapsort
algorithm uses one of the tree concepts called Heap Tree. In this sorting algorithm, we use Max
Heap to arrange list of elements in Descending order and Min Heap to arrange list elements in
Ascending order.
Step by Step Process
The Heap sort algorithm to arrange a list of elements in ascending order is performed using
following steps...
Step 1 - Construct a Binary Tree with given list of Elements.
Step 2 - Transform the Binary Tree into Min Heap.
Step 3 - Delete the root element from Min Heap using Heapify method.
Step 4 - Put the deleted element into the Sorted list.
Step 5 - Repeat the same until Min Heap becomes empty.
Step 6 - Display the sorted list.
4 1

4 9

You might also like