Home Week-5 Week-7

 

PDSA - Week 6

 

Union-Find data structure

Visualization

https://visualgo.net/en/ufds

Naïve Implementation of Union-Find

Complexity

Improved Implementation of Union-Find

Complexity

 

Improved Kruskal's algorithm using Union-find

Output

Complexity

 

Priority Queue

Need to maintain a collection of items with priorities to optimize the following operations

Heap

Binary tree

A binary tree is a tree data structure in which each node can contain at most 2 children, which are referred to as the left child and the right child.

Heap

Heap is a binary tree, filled level by level, left to right. There are two types of the heap:

We can represent heap using array(list in python)

H = [h0, h1, h2, h3, h4, h5, h6, h7, h8, h9]

left child of H[i] = H[2 * i + 1]

Right child of H[i] = H[2 * i + 2]

Parent of H[i] = H[(i-1) // 2], for i > 0

 

Visualization

https://visualgo.net/en/heap

Implementation of Maxheap

Output

 

Implementation of Minheap

Output

Complexity

Heaps are a tree implementation of priority queues

 

Improve Dijkstra's algorithm using min heap

Old implementation for adjacency matrix

Output

 

Updated Implementation for adjacency matrix using min heap

Output

 

Updated Implementation for adjacency list using min heap

Output

Complexity

Using min-heaps:-

Cumulatively:-

 

Heap Sort

Implementation

Output

Complexity

 

Binary Search Tree(BST)

For dynamic stored data

How can we improve Insert/delete time? - using tree structure?

A binary search tree is a binary tree that is either empty or satisfies the following conditions:

For each node V in the Tree

Visualization

https://visualgo.net/en/bst

Implementation

Output

Complexity