Data Structures in Java
for Intermediate Level
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Agenda
• Binary Tree
• Binary Search Tree
• Graph
• Hashing
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Binary Tree
implementation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Binary Tree implementation
Tree Traversal
A Program implementing the following points:-
1. Create a binary tree using classes and objects in java
2. Implement in-order traversal
3. Implement pre-order traversal
4. Implement post-order traversal
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Binary Search Tree
implementation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Binary Search Tree implementation
A Program implementing the following points:-
1. Create a binary search tree using classes and objects in java
2. Insert element into the BST
3. Delete element from BST
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Graphs
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Graphs
Introduction
Graph is a data structure, which is a derived concept from Mathematics.
Graph is a collection of vertices and edges. Vertices represents data and edges represents
relationship between the vertices.
There are different types of Graph, having different uses in computer science.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Graphs
Adjacency matrix or Adjacency List is used to represent graph programmatically.
A B
F C
E D
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
BFS implementation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
BFS implementation
It is an algorithm to trace the nodes of the graph in a breadth-first order; that is, the
neighbouring nodes in a single level are traversed first, then the nodes in the next level are
traversed.
A B
F C
E D
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
DFS implementation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
DFS implementation
It is an algorithm to trace the nodes of the graph in a depth-first order; the nodes in one
depth are traversed first, then the nodes in the parallel depth are traversed. It uses the
concept of back-tracking after one vertical depth node is traversed.
A B
F C
E D
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Hash Tables
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Hash tables
Introduction - Hashing
Hashing is a black box that takes a key as input and
provides hash value as output, where hash value belongs
to a fixed space. “Key” refers to the message, and “hash
value” is called a message digest.
It is a one-way function. There are different hashing
techniques where just the underlying procedure differs.
A good hashing function has minimalistic Collision.
In java, there are inbuilt classes that help to implement
hashing
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Hashing implementation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Hashing implementation
A program to create hash function by using certain in-built methods for hashing in java.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Summary
• Binary tree
• Binary search tree
• Graph data structure
• Breadth first search
• Depth first search
• Hashing
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited