Dsa 2 Assign

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

VISVESVARAYATECHNOLOGICALUNIVERSITY,

BELAGAVI

An ASSIGNMENT REPORT
Submitted as subject assignment work,
for the subject
Data Structures and Applications (BCS304)
By

KAVYASHREE
4AL22CS074

Under the Guidance of


Mrs. Deepika Kamath
Assistant Professor
DEPARTMENT OF COMPUTER SCIENCE &ENGINEERING
ALVA’S INSTITUTE OF ENGINEERING AND TECHNOLOGY
MOODBIDRI-574225, KARNATAKA ,2023–2024
ALVA’S INSTITUTE OF ENGINEERING AND TECHNOLOGY
MIJAR, MOODBIDRI D.K. -574225
KARNATAKA
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

CERTIFICATE

This is to certify that Kavyashree bearing USN 4AL22CS074 has successfully


completed the course which is assigned to her as the assignment work for the
subject “Data Structures and Applications (BCS304)” and submitted a report
during the academic year 2023–24 Odd Semester. It is certified that all
corrections/suggestions indicated in the presentation session have been
incorporated into the report.
The following are the score of student and report is deposited in the departmental
library.

USN Student Name Score


4AL22CS074 KAVYASHREE

Mrs . Deepika Kamath


Assistant Professor

INDEX

Chapters Title of the Chapter Page


1 Introduction 1
2 Linked Lists
2.1 Types of Linked Lists 2-3
2.2 Operations on linked list 4
3 Binary Search Trees
3.1 Introduction to BST 5
3.2 Traversing in BST 6-7
4 Graphs
4.1 Components of Graphs 8
4.2 Properties of Graphs 9
5 Conclusion 10
6 Reference 10

Virtual Lab

Introduction:
In this report, I aim to elucidate the virtual lab concept and its role in my learning
process. Within the virtual lab environment, I extensively explored three pivotal
concepts in data structures and applications.
They are, Linked Lists, Binary Search Trees, and Graphs. Through interactive
modules and guided exercises, I learned many things in these topics.
Virtual Labs is a project initiated by the Ministry of Education, Government of
India, under the National Mission on Education through Information and
Communication Technology. The project aims to provide remote access to
Laboratories in various disciplines of Science and Engineering for students at all
levels from undergraduate to research.
Virtual Labs have been designed to provide remote access to labs in various
disciplines of Science and Engineering. These Virtual Labs cater to students at the
undergraduate level, postgraduate level as well as to research scholars.
Virtual Labs enable the students to learn at their own pace and enthuse them to
conduct experiments. Virtual Labs also provide a complete learning management
system where the students can avail various tools for learning, including additional
web resources, video lectures, animated demonstration, and self-evaluation. Virtual
Labs can be used to complement physical labs.
In the virtual lab concept, numerous topic options are available for selection,
covering a wide array of subjects. Each subject encompasses multiple topics, and
within each topic, explanations are provided succinctly, making them easily
understandable. Additionally, practice questions are included to reinforce learning,
and quizzes are available to assess comprehension.

1. Linked Lists

Linked List is a linear data structure, in which elements are not stored at a
contiguous location, rather they are linked using pointers. Linked List forms a
series of connected nodes, where each node stores the data and the address of the
next node.

Node Structure: A node in a linked list typically consists of two components:


Data: It holds the actual value or data associated with the node.
Next Pointer: It stores the memory address (reference) of the next node in the
sequence.
Head and Tail: The linked list is accessed through the head node, which points to
the first node in the list. The last node in the list points to NULL or nullptr,
indicating the end of the list. This node is known as the tail node.
Types of linked lists:
There are mainly three types of linked lists:
 Single-linked list
 Double linked list

 Circular linked list

1. Single-linked list:In a singly linked list, each node contains a reference to the
next node in the sequence. Traversing a singly linked list is done in a forward
direction.
2. Double-linked list:
In a doubly linked list, each node contains references to both the next and previous
nodes. This allows for traversal in both forward and backward directions, but it
requires additional memory for the backward reference.

3. Circular linked list:


In a circular linked list, the last node points back to the head node, creating a
circular structure. It can be either singly or doubly linked.

Operations on Linked Lists

1. Insertion: Adding a new node to a linked list involves adjusting the pointers of the
existing nodes to maintain the proper sequence. Insertion can be performed at the
beginning, end, or any position within the list
2. Deletion: Removing a node from a linked list requires adjusting the pointers of the
neighboring nodes to bridge the gap left by the deleted node. Deletion can be
performed at the beginning, end, or any position within the list.
3. Searching: Searching for a specific value in a linked list involves traversing the list
from the head node until the value is found or the end of the list is reached.

2. Binary Search Trees

A Binary Search Tree (BST) is a special type of binary tree in which the left child
of a node has a value less than the node’s value and the right child has a value
greater than the node’s value. This property is called the BST property and it
makes it possible to efficiently search, insert, and delete elements in the tree.
The root of a BST is the node that has the smallest value in the left subtree and the
largest value in the right subtree. Each left subtree is a BST with nodes that have
smaller values than the root and each right subtree is a BST with nodes that have
larger values than the root.

Binary Search Tree is a node-based binary tree data structure that has the following
properties:

1. The left subtree of a node contains only nodes with keys lesser than the node’s key.
2. The right subtree of a node contains only nodes with keys greater than the node’s
key.
3. This means everything to the left of the root is less than the value of the root and
everything to the right of the root is greater than the value of the root. Due to this
performing, a binary search is very easy.
4. The left and right subtree each must also be a binary search tree.

There are three steps to traverse the binary search tree. They are,
1.Inorder Traversal:
At first traverse left subtree then visit the root and then traverse the right subtree.
Follow the below steps to implement the idea:

1. Traverse left subtree


2. Visit the root and print the data.
3. Traverse the right subtree
The inorder traversal of the BST gives the values of the nodes in sorted order. To
get the decreasing order visit the right, root, and left subtree.

2.Preorder Traversal:
At first visit the root then traverse left subtree and then traverse the right subtree.
Follow the below steps to implement the idea:

1. Visit the root and print the data.


2. Traverse left subtree
3. Traverse the right subtree

3.Postorder Traversal:
At first traverse left subtree then traverse the right subtree and then visit the root.
Follow the below steps to implement the idea:

A. Traverse left subtree


B. Traverse the right subtree
C. Visit the root and print the data.
Inorder Traversal: 8 12 20 22 25 30 40
Preorder Traversal: 22 12 8 20 30 25 40
Postorder Traversal: 8 20 12 25 40 30 22

3. Graphs:
A Graph is a non-linear data structure consisting of vertices and edges. The vertices
are sometimes also referred to as nodes and the edges are lines or arcs that connect
any two nodes in the graph. More formally a Graph is composed of a set of vertices
( V ) and a set of edges ( E ). The graph is denoted by G (V, E).
Graph data structures are a powerful tool for representing and analysing complex
relationships between objects or entities. They are particularly useful in fields such
as social network analysis, recommendation systems, and computer networks. In
the field of sports data science, graph data structures can be used to analyse and
understand the dynamics of team performance and player interactions on the field.
Components of a Graph
Vertices: Vertices are the fundamental units of the graph. Sometimes, vertices are
also known as vertex or nodes. Every node/vertex can be labeled or unlabelled.
Edges: Edges are drawn or used to connect two nodes of the graph. It can be
ordered pair of nodes in a directed graph. Edges can connect any two nodes in any
possible way. There are no rules. Sometimes, edges are also known as arcs. Every
edge can be labelled/unlabelled.

The basic properties of a graph:


Vertices (nodes): The points where edges meet in a graph are known as vertices or
nodes. A vertex can represent a physical object, concept, or abstract entity.
Edges: The connections between vertices are known as edges. They can be
undirected (bidirectional) or directed (unidirectional).
Weight: A weight can be assigned to an edge, representing the cost or distance
between two vertices. A weighted graph is a graph where the edges have weights.
Degree: The degree of a vertex is the number of edges that connect to it. In a
directed graph, the in-degree of a vertex is the number of edges that point to it, and
the out-degree is the number of edges that start from it.
Path: A path is a sequence of vertices that are connected by edges. A simple path
does not contain any repeated vertices or edges.
Cycle: A cycle is a path that starts and ends at the same vertex. A simple cycle does
not contain any repeated vertices or edges.
Connectedness: A graph is said to be connected if there is a path between any two
vertices. A disconnected graph is a graph that is not connected.
Planarity: A graph is said to be planar if it can be drawn on a plane without any
edges crossing each other.
Bipartiteness: A graph is said to be bipartite if its vertices can be divided into two
disjoint sets such that no two vertices in the same set are connected by an edge.
Undirected Graphs: A graph in which edges have no direction, i.e., the edges do
not have arrows indicating the direction of traversal. Example: A social network
graph where friendships are not directional.
Directed Graphs: A graph in which edges have a direction, i.e., the edges have
arrows indicating the direction of traversal. Example: A web page graph where
links between pages are directional.
Conclusion:
Through this virtual lab experience, I deepened my understanding of key data
structure concepts, including linked lists, binary search trees, and graphs. I gained
practical insights into their implementation, operations, and associated algorithms,
equipping me with valuable knowledge applicable across various computational
domains. Moving forward, I aim to leverage this newfound expertise to tackle
complex problems and develop efficient solutions in my academic and professional
pursuits.

Reference:
Virtual lab, Geeks for Geeks

You might also like