0% found this document useful (0 votes)
8 views24 pages

manan ds 6,7,10

The document outlines an experiment focused on tree data structures, specifically binary search trees, including their creation, traversal methods (in-order, pre-order, post-order), and applications in various fields such as databases and file systems. It provides detailed programming examples in C for creating and traversing a binary search tree, along with a theoretical background on tree operations. Additionally, it introduces a subsequent experiment on graph data structures, including breadth-first search (BFS) and depth-first search (DFS) algorithms, with programming implementations and applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views24 pages

manan ds 6,7,10

The document outlines an experiment focused on tree data structures, specifically binary search trees, including their creation, traversal methods (in-order, pre-order, post-order), and applications in various fields such as databases and file systems. It provides detailed programming examples in C for creating and traversing a binary search tree, along with a theoretical background on tree operations. Additionally, it introduces a subsequent experiment on graph data structures, including breadth-first search (BFS) and depth-first search (DFS) algorithms, with programming implementations and applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Data Structure (3130702) 230170132038

Experiment No: 6

AIM : Tree

6.1 Write a program which create binary search tree.


6.2 Implement recursive tree traversing methods in-order, pre-order and post-order
traversal.
6.3 Identify widely used applications which use Tree data structure for implementation
of its important feature.

Date: / / 2024

Competency and Practical Skills: Logic building and programming

Relevant CO: CO3, CO5

Objectives: (a) To understand the concepts of Tree


(b) To analyze different algorithms on Tree
(c) To implement various operations on Tree

Equipment/Instruments: Computer System with turbo C/C++

Safety and necessary Precautions:

 Operate computer system carefully and responsibly.


 Use required lab resources cautiously

Theory:

Binary Search Tree

A binary search tree is a binary tree in which each node possessed a key that satisfy the
following conditions

1. All key (if any) in the left sub tree of the root precedes the key in the root.
2. The key in the root precedes all key (if any) in the right sub tree.
3. The left and right sub tree sub trees of the root are again search trees.

Operations on tree

The most common operations performed on tree structure are that of traversal. This is a procedure
by which each node in the tree is processed exactly once in a systematic manner.

There are three ways of traversing a binary tree.

1. Pre-order Traversal
Page No
Data Structure (3130702) 230170132038
2. In-order Traversal
3. Post-order Traversal
Pre-order

 Pre-order traversal of a binary tree is defined as follow


 Process the root node
 Traverse the left sub tree in pre-order
 Traverse the right sub tree in pre-order
 If particular sub tree is empty (i.e., node has no left or right descendant) the traversal is
performed by doing nothing, In other words, a null sub tree is considered to be fully
traversed when it is encountered.

In-order

 The In-order traversal of a binary tree is given by following steps,


 Traverse the left sub tree in In-order
 Process the root node
 Traverse the right sub tree in In-order

Post-order

 The post-order traversal is given by


 Traverse the left sub tree in post-order
 Traverse the right sub tree in post-order
 Process the root node

6.1 Write a program which create binary search tree.

Program:

#include <stdio.h>
#include <stdlib.h>

struct Node
{ int data;
struct Node* left;
struct Node* right;
};

struct Node* createNode(int data) {


struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}

Page No
Data Structure (3130702) 230170132038
struct Node* insertNode(struct Node* root, int data) {

if (root == NULL) {
return createNode(data);
}
if (data < root->data) {
root->left = insertNode(root->left, data);
} else if (data > root->data) {
root->right = insertNode(root->right, data);
}
return root;
}

void inorderTraversal(struct Node* root)


{ if (root != NULL) {
inorderTraversal(root->left);
printf("%d ", root->data);
inorderTraversal(root->right);
}
}

int main() {
struct Node* root = NULL;
int n, value;

printf("Enter the number of nodes you want to insert: ");


scanf("%d", &n);

for (int i = 0; i < n; i++) {


printf("Enter value for node %d: ", i+1);
scanf("%d", &value);
root = insertNode(root, value);
}

printf("Inorder Traversal of the Binary Search Tree: ");


inorderTraversal(root);
printf("\n");

return 0;
}

Output:

Page No
Data Structure (3130702) 230170132038

Enter the number of nodes you want to insert: 5


Enter value for node 1: 50
Enter value for node 2: 30
Enter value for node 3: 70
Enter value for node 4: 20
Enter value for node 5: 40

Inorder Traversal of the Binary Search Tree: 20 30 40 50 70

6.2 Implement recursive tree traversing methods in-order, preorder and post-order
traversal.

Program:

#include <stdio.h>
#include <stdlib.h>

struct Node
{ int data;
struct Node* left;
struct Node* right;
};

struct Node* createNode(int data) {


struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}

struct Node* insertNode(struct Node* root, int data)


{ if (root == NULL) {
return createNode(data);
}
if (data < root->data) {
root->left = insertNode(root->left, data);
} else if (data > root->data) {
root->right = insertNode(root->right, data);
}
return root;
}

void inorderTraversal(struct Node* root)


{ if (root != NULL) {
inorderTraversal(root->left);
Page No
Data Structure (3130702) 230170132038
printf("%d ", root->data);
inorderTraversal(root->right);
}
}

void preorderTraversal(struct Node* root)


{ if (root != NULL) {
printf("%d ", root->data);
preorderTraversal(root->left);
preorderTraversal(root->right);
}
}

void postorderTraversal(struct Node* root) {


if (root != NULL) {
postorderTraversal(root->left);
postorderTraversal(root->right);
printf("%d ", root->data);
}
}

int main() {
struct Node* root = NULL;
int n, value;

printf("Enter the number of nodes you want to insert: ");


scanf("%d", &n);

for (int i = 0; i < n; i++) {


printf("Enter value for node %d: ", i + 1);
scanf("%d", &value);
root = insertNode(root, value);
}

printf("\nIn-order Traversal: ");


inorderTraversal(root); printf("\
n");

printf("Pre-order Traversal: ");


preorderTraversal(root); printf("\
n");

printf("Post-order Traversal: ");

Page No
Data Structure (3130702) 230170132038
postorderTraversal(root);
printf("\n");

return 0;
}

Output:

Enter the number of nodes you want to insert: 5


Enter value for node 1: 50
Enter value for node 2: 30
Enter value for node 3: 70
Enter value for node 4: 20
Enter value for node 5: 40

In-order Traversal: 20 30 40 50 70
Pre-order Traversal: 50 30 20 40 70
Post-order Traversal: 20 40 30 70 50

6.3 Identify widely used applications which use Tree data structure for implementation
of its important feature.

a) Binary Search Trees (BST) in Databases:


 BSTs are used in database indexing systems such as B-trees and AVL trees.
b) File Systems:
 Most operating systems (e.g., Windows, Linux) use a tree structure to represent the
hierarchical organization of files and directories. This allows for efficient navigation and
access to files.
c) Expression Trees in Compilers:
 Compilers use expression trees (a type of binary tree) to parse mathematical expressions
and generate machine-level instructions.
d) XML/HTML Document Object Model (DOM):
 Web browsers and parsers represent XML and HTML documents as tree structures (DOM
trees).
e) Trie in Auto-Complete:
 Tries (prefix trees) are used in search engines and text editors for fast retrieval of strings or
prefixes.
f) Routing Algorithms in Networking:
 Tree-based algorithms, such as spanning trees, are used in computer networks to optimize
routing and prevent loops in the network.
g) Artificial Intelligence and Decision Trees:
 Decision trees are commonly used in machine learning for classification and regression tasks.

Observations:

Page No
Data Structure (3130702) 230170132038

Efficiency
Flexibility
Scalability
Hierarchical Nature
Application-specific Optimizations

Conclusion:

Tree data structures play a crucial role in the implementation of many widely used
applications due to their efficiency, flexibility, and hierarchical nature. From databases and file
systems to networking and artificial intelligence, trees provide a foundation for efficient data
organization, retrieval, and manipulation. The versatility of trees enables them to be used in a
variety of fields, from search engines that utilize tries for auto-completion to machine learning
algorithms that rely on decision trees for classification and decision-making tasks. The ability of
trees to scale and adapt to different data types makes them indispensable in modern computing.

Quiz:

(1) Define binary search tree


(2) Explain pre-order, in-order and post order traversal techniques
(3) Which are the applications of binary search tree?

Suggested Reference:

3. An Introduction to Data Structures with Applications. by Jean-Paul Tremblay & Paul G.


Sorenson Publisher-Tata McGraw Hill.
4. Data Structures using C & C++ -By Ten Baum Publisher – Prenctice-Hall International
5. Fundamentals of Computer Algorithms by Horowitz, Sahni,Galgotia Pub. 2001 ed.
6. http://www.geeksforgeeks.org/data-structures/
7. http://www.coursera.org/specializations/data-structures-algorithms

References used by the students:

1. Paul G. Sorenson Publisher-Tata McGraw Hill.

Rubric-wise marks obtained:

Problem Coding Completeness


Logic
Understanding Standards and accuracy Q&A
Rubrics Building (2) Total
(2) (2) (2)
Avg. Good Avg. Good Avg. Good Avg. Good Avg. Good
(1) (2) (1) (2) (1) (2) (1) (2) (1) (2)
Marks

Page No
Data Structure (3130702) 230170132038

Experiment No: 7

AIM : Graph

7.1 Write a program to perform BFS and DFS on given graph.


7.2 Identify widely used applications which use graphs data structure for implementation
of its important feature.

Date:

Competency and Practical Skills: Logic building and programming

Relevant CO: CO3, CO5

Objectives: (a) To understand the concepts of graphs


(b) To analyze different algorithms on graphs
(c) To implement various operations on graphs

Equipment/Instruments: Computer System with turbo C/C++

Safety and necessary Precautions:

 Operate computer system carefully and responsibly.


 Use required lab resources cautiously

Theory:

Graph:

A graph G can be defined as a non-empty set of vertices or nodes (V) and a set of edges (E) that
represents the relationship or connection between those nodes. The edges can be defined as a
mapping from E to pairs of elements of V. A graph can be represented as G = (V, E), where V
represents the set of nodes and E represents the set of edges. Each edge of the graph G can be
associated with a pair of nodes of the graph. If an edge X belongs to E and is associated with a pair
of nodes (u, v), where u and v belong to V, then we say that edge X connects node u and node v.

Depth First Search (DFS):

DFS is a graph traversal algorithm that is similar to the preorder traversal of a tree. The traversal
can start from any vertex vi of the graph. Initially, the vertex vi is visited, and then all the adjacent
vertices to vi are traversed recursively using DFS. As a graph can have cycles, we need to avoid
revisiting a node. To achieve this, when a vertex V is visited, it is marked as visited and should not
be selected for traversal again.

Page No
Data Structure (3130702) 230170132038

Breadth First Search (BFS)

 Breadth First Search (BFS) starts from a vertex v0 and marks it as visited. Then, all the
vertices adjacent to v0 are visited next.
 Let the vertices adjacent to v0 be v1, v2, v3, and v4. These vertices are marked as visited.
 All unvisited vertices adjacent to v1, v2, v3, and v4 are visited next.
 The above process continues until all vertices are visited.
 The algorithm for BFS maintains a list of vertices that have been visited but not explored
for adjacent vertices. This list is stored in a queue.
 The queue initially contains the starting vertex.
 In each iteration, a vertex is removed from the queue, and its adjacent vertices, which have
not been visited yet, are added to the queue.
 The algorithm terminates when the queue becomes empty.

7.1 Write a program to perform BFS and DFS on given graph.

Program:
#include <stdio.h>
#include <stdlib.h>

#define MAX 100

struct Node {
int vertex;
struct Node* next;
};

struct Graph {
int numVertices;
struct Node** adjLists;
int* visited;
};
struct Node* createNode(int v) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->vertex = v;
newNode->next = NULL;
return newNode;
}

struct Graph* createGraph(int vertices) {


struct Graph* graph = (struct Graph*)malloc(sizeof(struct Graph));
graph->numVertices = vertices;

graph->adjLists = (struct Node**)malloc(vertices * sizeof(struct Node*));


graph->visited = (int*)malloc(vertices * sizeof(int));

Page No
Data Structure (3130702) 230170132038

int i;
for (i = 0; i < vertices; i++)
{ graph->adjLists[i] =
NULL; graph->visited[i] =
0;
}

return graph;
}
void addEdge(struct Graph* graph, int src, int dest)
{ struct Node* newNode = createNode(dest);
newNode->next = graph->adjLists[src];
graph->adjLists[src] = newNode;

newNode = createNode(src);
newNode->next = graph->adjLists[dest];
graph->adjLists[dest] = newNode;
}

void BFS(struct Graph* graph, int startVertex) {


int queue[MAX], front = 0, rear = -1;
int i;

graph->visited[startVertex] = 1;
queue[++rear] = startVertex;

printf("BFS Traversal: ");

while (front <= rear) {


int currentVertex = queue[front++];
printf("%d ", currentVertex);

struct Node* temp = graph->adjLists[currentVertex];

while (temp) {
int adjVertex = temp->vertex;
if (graph->visited[adjVertex] == 0)
{ queue[++rear] = adjVertex;
graph->visited[adjVertex] = 1;
}
temp = temp->next;
}
}
printf("\n");

Page No
Data Structure (3130702) 230170132038
}

// DFS algorithm
void DFS(struct Graph* graph, int vertex)
{ struct Node* adjList = graph->adjLists[vertex];
struct Node* temp = adjList;

graph->visited[vertex] = 1;
printf("%d ", vertex);

while (temp != NULL) {


int connectedVertex = temp->vertex;

if (graph->visited[connectedVertex] == 0)
{ DFS(graph, connectedVertex);
}
temp = temp->next;
}
}

void resetVisited(struct Graph* graph)


{ int i;
for (i = 0; i < graph->numVertices; i++)
{ graph->visited[i] = 0;
}
}

int main() {
struct Graph* graph = createGraph(6);

addEdge(graph, 0, 1);
addEdge(graph, 0, 2);
addEdge(graph, 1, 2);
addEdge(graph, 1, 3);
addEdge(graph, 2, 4);
addEdge(graph, 3, 4);
addEdge(graph, 3, 5);

BFS(graph, 0);

DFS
resetVisited(graph);

printf("DFS Traversal: ");


DFS(graph, 0);
printf("\n");

Page No
Data Structure (3130702) 230170132038

return 0;
}
Output:

BFS Traversal: 0 1 2 3 4 5
DFS Traversal: 0 1 3 4 5 2

7.2 Identify widely used applications which use graphs data structure for implementation
of its important feature.

1) Social Networks
 Feature: Graph algorithms are used for finding mutual friends, recommending new
connections, and identifying communities within the network.
 Example: Facebook’s “People You May Know” feature is built on graph traversal
algorithms to recommend friends based on mutual connections.
2) Google Maps and GPS Navigation Systems
 Feature: Graph algorithms like Dijkstra's and A* are used to find the shortest path
between locations.
 Example: Google Maps uses graph data structures to calculate the quickest route,
taking into account factors like distance, traffic, and alternate routes.
3) Recommendation Systems
 Feature: These systems use collaborative filtering and content-based filtering
techniques, where users and products are represented as nodes and interactions (e.g.,
purchases, ratings) as edges.
 Example: Netflix recommends movies to users based on their viewing history and the
preferences of similar users, all of which is modeled using a graph.
4) Web Page Ranking (Google's PageRank)
 Feature: Google’s PageRank algorithm is based on graph traversal to rank the
importance of web pages based on their inbound and outbound links.
 Example: PageRank uses the graph structure of the web to determine which pages are
more relevant to a given search query.
5) Computer Networks (Routing Algorithms)
 Feature: Routing algorithms like Open Shortest Path First (OSPF) and Border
Gateway Protocol (BGP) use graphs to find optimal paths for data transmission.
 Example: Routers use graph algorithms to efficiently forward data packets across the
internet by finding the shortest or least congested path.
6) Artificial Intelligence (AI) and Machine Learning (ML)
 Feature: Graph Neural Networks (GNN) and knowledge graphs help in tasks like
natural language processing, recommendation systems, and fraud detection.
 Example: Knowledge graphs are used in semantic search engines like Google Search
to understand user queries in a more meaningful way by connecting related concepts.
7) Transport and Logistics
 Feature: Graph algorithms are used for vehicle routing problems, minimizing costs
and delivery time.
 Example: Amazon uses graph-based optimization to deliver packages efficiently by

Page No
Data Structure (3130702) 230170132038
reducing travel time and fuel consumption.
8) Compiler Design
 Feature: Data-flow analysis, dead code elimination, and instruction scheduling are
graph-based features in modern compilers.
 Example: Compilers build a control flow graph (CFG) to optimize code execution
paths and detect possible optimizations.

Observations:
Complex Relationships
Optimization
Scalability
Flexibility
AI Integration

Conclusion:

Graphs are a foundational data structure in computer science, with applications spanning
across various domains, from social networks to AI. They are invaluable in any scenario where
relationships between data points must be modeled, analyzed, and optimized.

Quiz:

(1) Define Directed Acyclic Graph (DAG).


(2) Differentiate DFS and BFS.
(3) State the applications of graph.

Suggested Reference:

1. An Introduction to Data Structures with Applications. by Jean-Paul Tremblay & Paul G.


Sorenson Publisher-Tata McGraw Hill.
2. Data Structures using C & C++ -By Ten Baum Publisher – Prenctice-Hall International
3. Fundamentals of Computer Algorithms by Horowitz, Sahni,Galgotia Pub. 2001 ed.
4. http://www.geeksforgeeks.org/data-structures/
5. http://www.coursera.org/specializations/data-structures-algorithms

References used by the students:

1. Paul G. Sorenson Publisher-Tata McGraw Hill.

Rubric-wise marks obtained:

Problem Logic Coding Completeness


Rubrics Q&A Total
Understanding Building (2) Standards and accuracy

Page No
Data Structure (3130702) 230170132038
(2) (2) (2)

Avg. Good Avg. Good Avg. Good Avg. Good Avg. Good
(1) (2) (1) (2) (1) (2) (1) (2) (1) (2)
Marks

Page No
Data Structure (3130702) 230170132038
Experiment No: 10

AIM : Hashing and File Structure

10.1 Write a program to create hash table and handle the collision using linear probing.
10.2 Write a program to demonstrate the file primitives such as fopen, fclose, fprintf.
10.3 Identify widely used applications which use Hashing technique for implementation of
its important feature.

Date:

Competency and Practical Skills: Logic building and programming

Relevant CO: CO4, CO5

Objectives: (a) To understand the concepts of Hashing techniques


(b) To implement various file operations

Equipment/Instruments: Computer System with turbo C/C++

Safety and necessary Precautions:

 Operate computer system carefully and responsibly.


 Use required lab resources cautiously

Theory:

Hashing

Hashing is a method used to map a large number of data items to a smaller table by utilizing a
hashing function. This technique transforms a range of key values into a range of indexes of an
array.There are two different forms of hashing.

1. Open hashing or external hashing: Open or external hashing, allows records to be stored
in unlimited space (could be a hard disk). It places no limitation on the size of the tables.
2. Close hashing or internal hashing: Closed or internal hashing, uses a fixed space for
storage and thus limits the size of hash table.

Hashing Functions

Characteristics of a Good Hash Function


 A good hash function avoids collisions.
 A good hash function tends to spread keys evenly in the array.
 A good hash function is easy to compute.

Page No
Data Structure (3130702) 230170132038
Different hashing functions

1. Division-Method
2. Folding Method
3. Algebraic Coding
4. Multiplicative Hashing
5. Digit Analysis
6. Mid-square Methods
7. Length Dependent Method

Collision Resolution Strategies

 Collision resolution is the main problem in hashing.


 If the element to be inserted is mapped to the same location, where an element is already
inserted then we have a collision and it must be resolved.
 There are several strategies for collision resolution. The most commonly used are :
1. Separate chaining - used with open hashing
2. Open addressing - used with closed hashing

File

In computing, a file is a group of records, where each record comprises one or more fields that have
the same sequence. Typically, each field has a predetermined length.

Different file organizations

1. Sequential files
2. Direct files
3. Index files
4. Indexed Sequential files
5. Relative files

Primitive Operations on a File

1. Creation
2. Insertion
3. Deletion
4. Updation
5. Reading
6. Searching

Page No
Data Structure (3130702) 230170132038

10.1 Write a program to create hash table and handle the collision using linear probing.

Program:

#include <stdio.h>
#include <stdlib.h>

#define TABLE_SIZE 10

struct HashTableEntry {
int key;
int value;
};

void initializeTable(struct HashTableEntry table[])


{ for (int i = 0; i < TABLE_SIZE; i++) {
table[i].key = -1; // -1 indicates that the slot is empty
table[i].value = 0;
}
}

int hashFunction(int key)


{ return key %
TABLE_SIZE;
}

void insert(struct HashTableEntry table[], int key, int value)


{ int index = hashFunction(key);
int originalIndex = index;

while (table[index].key != -1 && table[index].key != key)


{ index = (index + 1) % TABLE_SIZE;
if (index == originalIndex)
{ printf("Hash table is full!\
n"); return;
}
}

table[index].key = key;
table[index].value = value;
}

int search(struct HashTableEntry table[], int key)


Page No
Data Structure (3130702) 230170132038
{ int index = hashFunction(key);

Page No
Data Structure (3130702) 230170132038
int originalIndex = index;

while (table[index].key != -1)


{ if (table[index].key == key)
{ return table[index].value;
}
index = (index + 1) % TABLE_SIZE;
if (index == originalIndex) {
break;
}
}

return -1; // Key not found


}
void displayTable(struct HashTableEntry table[]) { printf("Index\tKey\
tValue\n");
for (int i = 0; i < TABLE_SIZE; i++)
{ if (table[i].key != -1) {
printf("%d\t%d\t%d\n", i, table[i].key, table[i].value);
} else {
printf("%d\t--\t--\n", i);
}
}
}

int main() {
struct HashTableEntry hashTable[TABLE_SIZE];
initializeTable(hashTable);

int choice, key, value;


while (1) {
printf("\n1. Insert\n2. Search\n3. Display\n4. Exit\nEnter your choice: ");
scanf("%d", &choice);

switch (choice)
{ case 1:
printf("Enter key: ");
scanf("%d", &key);
printf("Enter value: ");
scanf("%d", &value);
insert(hashTable, key, value);
break;

case 2:
printf("Enter key to search: ");
scanf("%d", &key);

Page No
Data Structure (3130702) 230170132038
value = search(hashTable, key);
if (value != -1) {
printf("Key found with value: %d\n", value);
} else {
printf("Key not found!\n");
}
break;

case 3:
displayTable(hashTable);
break;

case 4:
exit(0);

default:
printf("Invalid choice!\n");
}
}

return 0;
}

Output:

1. Insert
2. Search
3. Display
4. Exit
Enter your choice: 1
Enter key: 12
Enter value: 100

1. Insert
2. Search
3. Display
4. Exit
Enter your choice: 1
Enter key: 22
Enter value: 200

1. Insert
2. Search
3. Display
4. Exit
Enter your choice: 3

Page No
Data Structure (3130702) 230170132038
Index Key Value
0 -- --
1 -- --
2 -- --
3 12 100
4 22 200
5 -- --
6 -- --
7 -- --
8 -- --
9 -- --

1. Insert
2. Search
3. Display
4. Exit
Enter your choice: 2
Enter key to search: 12
Key found with value: 100

10.2 Write a program to demonstrate the file primitives such as fopen, fclose, fprintf.

Program:

#include <stdio.h>
#include <stdlib.h>

int main() {

FILE *filePtr;

filePtr = fopen("example.txt", "w");

if (filePtr == NULL) {
printf("Error! Could not open file.\n");
exit(1); // Exit if fopen() failed
}

fprintf(filePtr, "This is an example of file I/O in C.\n");


fprintf(filePtr, "Using fprintf to write formatted data to the file.\n");
fprintf(filePtr, "You can write multiple lines using fprintf.\n");

fclose(filePtr);

Page No
Data Structure (3130702) 230170132038
printf("Data successfully written to 'example.txt'.\n");

return 0;
}

Output:

Data successfully written to 'example.txt'.

10.3 Identify widely used applications which use Hashing technique for implementation of
its important feature.

1) Databases
 Application: Hashing is used in database indexing to quickly retrieve data without
scanning entire tables.
 Feature: Hash tables are used to index rows for fast lookups, especially in large
datasets.
2) Cryptography
 Application: Hash functions are a cornerstone of cryptography, where they are used
to ensure data integrity and generate digital signatures.
 Feature: Cryptographic hash functions (e.g., SHA-256, MD5) create fixed-length
outputs that are virtually unique, even for slightly different inputs.
3) Password Storage
 Application: Hashing is widely used to securely store user passwords in databases.
 Feature: Passwords are hashed before storage so that even if a database is
compromised, attackers cannot easily recover the original passwords.
4) Caching Systems
 Application: Hashing is used in caching systems like Redis and Memcached to store
and retrieve frequently used data quickly.
 Feature: Hashing allows mapping of cached objects to specific keys for rapid access,
reducing the load on primary data stores.
5) Compiler Design
 Application: Compilers use hashing for symbol tables, which store identifiers such as
variable names and function names for fast lookups.
 Feature: A hash table allows quick access to variables and functions when compiling
the code, improving the speed of the compilation process.
6) Data Deduplication
 Application: Hashing is used in data deduplication to identify and eliminate duplicate
files or blocks of data.
 Feature: Hashes of files or blocks are compared, and if two hashes match, the system
identifies the data as a duplicate.
7) Load Balancing
 Application: Hashing is used in load balancing algorithms to distribute tasks or
requests evenly across multiple servers.
 Feature: Consistent hashing ensures that requests for a specific resource are always
directed to the same server, optimizing resource usage.
8) File Systems
Page No
Data Structure (3130702) 230170132038
 Application: File systems use hashing to locate file blocks and manage directories
efficiently.
 Feature: A hash table can map file names or file blocks to their locations on disk for
faster file access.
9) Blockchain and Cryptocurrency
 Application: Hashing is essential for verifying transactions and securing data in
blockchain and cryptocurrencies like Bitcoin and Ethereum.
 Feature: Hashing ensures that each block of data in the blockchain is uniquely
identified and secure, making it resistant to tampering.
Observations:

Efficiency
Security
Scalability
Storage Optimization
Robustness

Conclusion:

Hashing is a versatile technique with widespread applications across multiple domains,


from ensuring data security to optimizing resource allocation. Its ability to provide quick access,
data integrity, and security makes it indispensable in modern computing.

Quiz:

(1) What is internal hashing and external hashing?


(2) Explain linear probing.
(3) Which are primitive operations on file?

Suggested Reference:

1. An Introduction to Data Structures with Applications. by Jean-Paul Tremblay & Paul G.


Sorenson Publisher-Tata McGraw Hill.
2. Data Structures using C & C++ -By Ten Baum Publisher – Prenctice-Hall International
3. Fundamentals of Computer Algorithms by Horowitz, Sahni,Galgotia Pub. 2001 ed.
4. http://www.geeksforgeeks.org/data-structures/
5. http://www.coursera.org/specializations/data-structures-algorithms

References used by the students:

1. Paul G. Sorenson Publisher-Tata McGraw Hill

Page No
Data Structure (3130702) 230170132038
Rubric-wise marks obtained:

Problem Coding Completeness


Logic
Understanding Standards and accuracy Q&A
Rubrics Building (2) Total
(2) (2) (2)
Avg. Good Avg. Good Avg. Good Avg. Good Avg. Good
(1) (2) (1) (2) (1) (2) (1) (2) (1) (2)
Marks

Page No

You might also like