Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
34 views57 pages

Module 2 AAD

Module 2 covers advanced data structures, focusing on AVL trees and graph algorithms. An AVL tree is a height-balanced binary search tree, while graphs consist of vertices and edges, represented using adjacency matrices or lists. The document also explains Depth First Search (DFS) as a traversal method for graphs, highlighting its similarities to tree traversal and the potential for cycles in graphs.

Uploaded by

danishmongam
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)
34 views57 pages

Module 2 AAD

Module 2 covers advanced data structures, focusing on AVL trees and graph algorithms. An AVL tree is a height-balanced binary search tree, while graphs consist of vertices and edges, represented using adjacency matrices or lists. The document also explains Depth First Search (DFS) as a traversal method for graphs, highlighting its similarities to tree traversal and the potential for cycles in graphs.

Uploaded by

danishmongam
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/ 57

Module 2

ADVANED DATA STRUCTURES


&
GRAPH ALGORITHMS
AVL Trees
• AVL Tree is invented by GM Adelson - Velsky and EM Landis in 1962.
• The tree is named AVL in honour of its inventors.
• AVL Tree can be defined as height balanced binary search tree in
which each node is associated with a balance factor.
GRAPH
• Graph is a data structure that consists of following two components:
• 1. A finite set of vertices also called as nodes.
• 2. A finite set of ordered pair of the form (u, v) called as edge.

• Generally, a graph G is represented as G = ( V , E ), where V is set of


vertices and E is set of edges.
• Following two are the most commonly used representations of graph.
• 1. Adjacency Matrix
• 2. Adjacency List
Adjacency Matrix:
• Adjacency Matrix is a 2D array of size V x V where V is the number of
vertices in a graph.
• Let the 2D array be adj[][], a slot adj[i][j] = 1 indicates that there is an
edge from vertex i to vertex j.
• Adjacency matrix for undirected graph is always symmetric.
• Adjacency Matrix is also used to represent weighted graphs.
• If adj[i][j] = w, then there is an edge from vertex i to vertex j with
weight w.
Adjacency List:
• An array of linked lists is used.
• Size of the array is equal to number of vertices.
• Let the array be array[].
• An entry array[i] represents the linked list of vertices adjacent to the
ith vertex.
• This representation can also be used to represent a weighted graph.
• The weights of edges can be stored in nodes of linked lists.
• Following is adjacency list representation of the above graph.
DFS
• In Depth First Search (or DFS) for a graph, we traverse
all adjacent vertices one by one.
• When we traverse an adjacent vertex, we completely
finish the traversal of all vertices reachable through that
adjacent vertex.
• This is similar to a tree, where we first completely
traverse the left subtree and then move to the right
subtree.
• The key difference is that, unlike trees, graphs may
contain cycles (a node may be visited more than once).

You might also like