Module-5 Graphs
Module-5 Graphs
MODULE - 5
Graphs: Definitions, Terminologies, Matrix and Adjacency List Representation Of Graphs,
Elementary Graph operations, Traversal methods: Breadth First Search and Depth First Search.
Sorting and Searching: Insertion Sort, Radix sort, Address Calculation Sort.
Hashing: Hash Table organizations, Hashing Functions, Static and Dynamic Hashing.
Files and Their Organization: Data Hierarchy, File Attributes Text Files and Binary Files, Basic
File Operations, File Organizations and Indexing.
2. Multigraph: A graph with self-loops or parallel edges(multiple edge) between any two vertices is
called a multigraph.
3. Complete graph: A graph is said to be a complete graph, if there exists an edge between every
pair of vertices.
4. Weighted graph: A graph in which a number is assigned to each edge in graph is called weighted
graph. Weight typically shows cost or distance of traversing.
Example: weights are distances between cities.
Unweighted graph: A graph in which a number is not assigned to edge in graph is called
unweighted. Edges simply show connections.
Path: sequence of vertices in which each pair of successive vertices is connected by an edge.
Example: Traverse the following graph by BFS and print all the vertices reachable from start vertex
a.
5.6 Sorting
Sorting means arranging the elements of an array so that they are placed in some relevant order
which may be either ascending or descending.
Example: Sort the following list using insertion sort – 77, 33, 44, 11, 88, 22, 66, 55
To insert an element A[K] in a sorted list A[0], A[1], ..., A[K–1], we need to compare A[K] with
A[K–1], then with A[K–2], A[K–3], and so on until we meet an element A[J] such that A[J] <=
Example: Sort the following list using Radix sort – 348, 143, 361, 423, 538, 128, 321, 543,366
Sorted numbers are- 128, 143, 321, 348, 361, 366, 423, 538, 543.
Difference between Graph and Tree
2. Mid square method: In this method firstly key is squared and then mid part of the result is taken
as the index.
H(key) = Key2 = mid(key)
For example: consider that if we want to place a record of 3101 and the size of table is 1000. So
3101*3101=9616201 i.e. h (3101) = 162 (middle 3 digit).
Collision
It is a situation in which the hash function returns the same hash key for more than one
record, it is called as collision. Sometimes when we are going to resolve the collision it may
lead to a overflow condition and this overflow and collision condition makes the poor hash func-
tion.
Collision resolution technique
If there is a problem of collision occurs then it can be handled by apply some technique. These
techniques are called as collision resolution techniques.
1) Chaining: It is a method in which additional field with data i.e. chain is introduced. A chain is
maintained at the home bucket. In this when a collision occurs then a linked list is maintained for
colliding data.
Example: Let us consider a hash table of size 10 and we apply a hash function of H(key)=key %
size of table. Let us take the keys to be inserted are 31,33,77,61. In the above diagram we can see at
same bucket 1 there are two records which are maintained by linked list or we can say by chaining
method.
Dr. Sreenivasa B R, Dept. of IS&E 12
DATA STRUCTURES AND APPLICATIONS
2) Linear probing: It is very easy and simple method to resolve or to handle the collision. In this
collision can be solved by placing the second record linearly down, whenever the empty place is
found. In this method there is a problem of clustering which means at some place block of a data is
formed in a hash table.
Example: Let us consider a hash table of size 10 and hash function is defined as H(key)=key % ta -
ble size. Consider that following keys are to be inserted that are 56,64,36,71.
In this diagram we can see that 56 and 36 need to be placed at same bucket but by linear probing
technique the records linearly placed downward if place is empty i.e. it can be seen 36 is placed
at index 7.
Dynamic Hashing: This is the process of mapping large amounts of data into a table whose size is
assigned during run time.
File Attributes:
File attributes are settings associated with computer files that grant or deny certain rights to how a
user or the operating system can access that file. For example, IBM compatible computers running
MS-DOS or Microsoft Windows have capabilities of having read, archive, system, and hidden
attributes.
Read-only - Allows a file to be read, but nothing can be written to the file or changed.
Archive - Tells Windows Backup to backup the file.
System - System file.
Hidden - File is not shown when doing a regular directory from DOS.
QUESTION BANK