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

An Internship Report

On
Data Structure and Algorithm
Submitted for
Evaluation of Internship-II
(BECP-507)
Submitted For
Bachelor of Technology
In
Electronics and Communication Engineering
At

Women Institute of Technology Dehradun


(Department of Electronics and Communication Engineering)

SUBMITTED TO: SUBMITTED BY:


Mrs. Manju Devrari Samiksha Verma
(ECE Department) Roll no:721230102003
ECE-3rd Year (5th Sem.)
ACKNOWLEDGEMENT
I am grateful to Yhills for providing me with the exceptional
opportunity to learn and grow under their guidance. I would like to
extend my heartfelt appreciation to Yhills educator Jose Portilla,
whose unwavering support, encouragement, and expert instruction
were instrumental in my successful completion of the training
program.
I am particularly thankful to my esteemed teachers and Dr. Ashish
Bhagwari, HOD of Electronics and Communication, for their
unwavering guidance and mentorship throughout my training journey.
I would also like to express my sincere gratitude to the department
staff members who have consistently gone above and beyond to assist
me in my academic endeavours.
I am truly fortunate to have had the opportunity to learn. I am forever
grateful for the transformative experience I have gained during my
time while learning at Yhills.
CERTIFICATE

INDEX
S. No. Content Page No.

1. Introduction to DSA
 What is Data Structure?
 What is Algorithm?
 What is Data Structure and
Algorithm?
2. Real life examples of DSA

3. Types of Data Structure


 Primitive
 Non-primitive
4. Linear data structure
 Array
 Queue
 Stack
 Linked List
5. Non-Linear data structure
 Tree
 Graph
6. Tower of Hanoi Problem
 Introduction
 Program of Java for solve Tower of
Hanoi
 Output of the Program
7. Some another programs and their
outputs for different problems
 Check duplicate number an array
 Matrix reshape
 Search matrix position
8. Conclusion
Introduction

What is Data Structure?


The data structure name indicates itself that organizing the data in
memory. There are many ways of organizing the data in the memory
as we have already seen one of the data structures, i.e., array in C
language. Array is a collection of memory elements in which data is
stored sequentially, i.e., one after another. In other words, we can say
that array stores the elements in a continuous manner. This
organization of data is done with the help of an array of data
structures. There are also other ways to organize the data in memory.
The data structure is not any programming language like C, C++,
java, etc. It is a set of algorithms that we can use in any programming
language to structure the data in the memory.

What is Algorithm?
An algorithm is a process or a set of rules required to perform
calculations or some other problem-solving operations especially by a
computer. The formal definition of an algorithm is that it contains the
finite set of instructions which are being carried in a specific order to
perform the specific task. It is not the complete program or code; it is
just a solution (logic) of a problem, which can be represented either as
an informal description using a Flowchart or Pseudocode.

What is Data Structure and Algorithm?


Data structures and algorithms are closely related. Many algorithms
are designed to work with specific data structures. For example, the
quick sort algorithm is a sorting algorithm that works best with arrays.
Learning about data structures and algorithms is essential for anyone
who wants to be a good computer programmer. By understanding
how data is stored and manipulated, you can write more efficient and
effective code.

Real life examples:


Here are some examples of how data structures and algorithms are
used in the real world:
 Search engines:
 Search engines use data structures to store and index web
pages. This allows them to quickly find the most relevant pages
for a given search query.
 Social networks:
 Social networks use data structures to store user profiles,
relationships between users, and posts. This allows them to
quickly display the most relevant information to each user.
 Navigation apps:
 Navigation apps use data structures to store maps and road
networks. This allows them to quickly find the shortest path
between two points.
 E-commerce websites:
 E-commerce websites use data structures to store product
information, customer orders, and shipping addresses. This
allows them to quickly process orders and ship products to the
correct addresses.

Types of Data Structure


Fig1: Types of Data Structure
Primitive type data structure:
Primitive data types in Java are the building blocks of data
manipulation. They specify the size and type of variable
values. Primitive data types are pre-defined by the programming
language and cannot be further divided into simpler data types.
Normally primitive data structure has following data types:
 Integer
 Floating point
 Character
 Double
Non- primitive data structure:
Non-primitive data types in Java are not predefined. They are created
by the programmer. Non-primitive data types are also called
'reference variables' or 'object references' as they reference a memory
location where data is stored. Some of the examples of non-primitive
types include strings, arrays, and classes.
Types of non-primitive data types are as follows:
 Linear data structure
 Non-linear data structure

 Linear data structure:


A linear data structure is a structure in which the elements are stored
sequentially, and the elements are connected to the previous and the
next element. As the elements are stored sequentially, so they can be
traversed or accessed in a single run. The implementation of linear
data structures is easier as the elements are sequentially organized in
memory. The data elements in an array are traversed one after another
and can access only one element at a time.

The types of linear data structures are:

 Array

 Stack

 Queue

 Linked List

I. Array:
Arrays are defined as the collection of similar types of data items stored at
contiguous memory locations. It is one of the simplest data structures
where each data element can be randomly accessed by using its index
number.

In C programming, they are the derived data types that can store the
primitive type of data such as int, char, double, float, etc. For example, if we
want to store the marks of a student in 6 subjects, then we don't need to
define a different variable for the marks in different subjects. Instead, we
can define an array that can store the marks in each subject at the
contiguous memory locations.

Fig2: Array representation

Properties of array:

There are some of the properties of an array that are listed as follows:

o Each element in an array is of the same data type and carries the
same size that is 4 bytes.
o Elements in the array are stored at contiguous memory locations
from which the first element is stored at the smallest memory
location.
o Elements of the array can be randomly accessed since we can
calculate the address of each element of the array with the given
base address and the size of the data element.

II. Queue:
A queue can be defined as an ordered list which enables insert operations
to be performed at one end called REAR and delete operations to be
performed at another end called FRONT.

Queue is referred to be as First In First Out list.

For example, people waiting in line for a rail ticket form a queue.

Fig3: Queue representation

Properties of Queue:

There are some of the properties of an queue that are listed as follows:

o FIFO Order: Elements are removed from the queue in the same
order they were added.
o Front and Rear: Queues have two ends: the front and the rear.
Elements are added to the rear and removed from the front.
o Enqueue Operation: Enqueueing an element inserts it into the
rear of the queue.
o Dequeue Operation: Dequeueing an element removes it from
the front of the queue.
o Empty and Full Checks: Queues can be checked for emptiness
or fullness depending on their implementation.
o Bounded or Unbounded: Queues can have a fixed size
(bounded) or grow dynamically (unbounded).

III. Stack:
A Stack is a linear data structure that follows the LIFO (Last-In-First-
Out) principle. Stack has one end, whereas the Queue has two ends
(front and rear). It contains only one pointer top pointer pointing to
the topmost element of the stack. Whenever an element is added in
the stack, it is added on the top of the stack, and the element can be
deleted only from the stack. In other words, a stack can be defined as
a container in which insertion and deletion can be done from the one
end known as the top of the stack.

PUSH operation:

The steps involved in the PUSH operation is given below:

o Before inserting an element in a stack, we check whether the


stack is full.
o If we try to insert the element in a stack, and the stack is full,
then the overflow condition occurs.
o When we initialize a stack, we set the value of top as -1 to check
that the stack is empty.
o When the new element is pushed in a stack, first, the value of
the top gets incremented, i.e., top=top+1, and the element will
be placed at the new position of the top.
o The elements will be inserted until we reach the max size of the
stack.

POP operation:

The steps involved in the POP operation is given below:

o Before deleting the element from the stack, we check whether


the stack is empty.
o If we try to delete the element from the empty stack, then
the underflow condition occurs.
o If the stack is not empty, we first access the element which is
pointed by the top
o Once the pop operation is performed, the top is decremented by
1, i.e., top=top-1.

Fig4: Representation of stack

IV. Linked List:

o Linked List can be defined as collection of objects


called nodes that are randomly stored in the memory.
o A node contains two fields i.e. data stored at that particular
address and the pointer which contains the address of the next
node in the memory.
o The last node of the list contains pointer to the null.
o The list is not required to be contiguously present in the
memory. The node can reside any where in the memory and
linked together to make a list. This achieves optimized
utilization of space.
Fig5: Representation of linked list

Why use linked list over array?

Till now, we were using array data structure to organize the group of
elements that are to be stored individually in the memory. However,
Array has several advantages and disadvantages which must be
known in order to decide the data structure which will be used
throughout the program.

Array contains following limitations:

o The size of array must be known in advance before using it in


the program.
o Increasing size of the array is a time taking process. It is almost
impossible to expand the size of the array at run time.
o All the elements in the array need to be contiguously stored in
the memory. Inserting any element in the array needs shifting of
all its predecessors.

Linked list is the data structure which can overcome all the
limitations of an array. Using linked list is useful because,

o It allocates the memory dynamically. All the nodes of linked list


are non-contiguously stored in the memory and linked together
with the help of pointers.
o Sizing is no longer a problem since we do not need to define its
size at the time of declaration. List grows as per the program's
demand and limited to the available memory space.
 Non- Linear Data Structure:

 A non-linear data structure is another important type in which data


elements are not arranged sequentially; mainly, data elements are
arranged in random order without forming a linear structure.
 Data elements are present at the multilevel, for example, tree.
 In trees, the data elements are arranged in the hierarchical form,
whereas in graphs, the data elements are arranged in random order,
using the edges and vertex.
 Multiple runs are required to traverse through all the elements
completely. Traversing in a single run is impossible to traverse the
whole data structure.
 Each element can have multiple paths to reach another element.

Types of non-linear data types are follows:

 Tree
 Graph

 Tree:

A tree data structure is a hierarchical structure that is used to


represent and organize data in a way that is easy to navigate and
search. It is a collection of nodes that are connected by edges and
has a hierarchical relationship between the nodes.
The topmost node of the tree is called the root, and the nodes below
it are called the child nodes. Each node can have multiple child
nodes, and these child nodes can also have their own child nodes,
forming a recursive structure.
Fig6: Representation of Trees

Basic Operation Of Tree Data Structure:


 Create – create a tree in the data structure.
 Insert − Inserts data in a tree.
 Search − Searches specific data in a tree to check whether it is
present or not.
 Traversal:
o Preorder Traversal – perform Traveling a tree in a pre-
order manner in the data structure.
o In order Traversal – perform Traveling a tree in an in-
order manner.
o Post-order Traversal – perform Traveling a tree in a
post-order manner.

Application of Tree Data Structure:


 File System: This allows for efficient navigation and
organization of files.
 Data Compression: Huffman coding is a popular technique for
data compression that involves constructing a binary tree where
the leaves represent characters and their frequency of occurrence.
The resulting tree is used to encode the data in a way that
minimizes the amount of storage required.
 Compiler Design: In compiler design, a syntax tree is used to
represent the structure of a program.
 Database Indexing: B-trees and other tree structures are used in
database indexing to efficiently search for and retrieve data.

 Graph:
A graph can be defined as group of vertices and edges that are used to
connect these vertices. A graph can be seen as a cyclic tree, where the
vertices (Nodes) maintain any complex relationship among them
instead of having parent child relationship.

A graph G can be defined as an ordered set G(V, E) where V(G)


represents the set of vertices and E(G) represents the set of edges
which are used to connect these vertices.

A Graph G(V, E) with 5 vertices (A, B, C, D, E) and six edges ((A,B),


(B,C), (C,E), (E,D), (D,B), (D,A)) is shown in the following figure:

Fig7: Sequencial representation of graph

A graph is an abstract data type (ADT) that consists of a set of objects


that are connected to each other via links. These objects are
called vertices and the links are called edges.
Usually, a graph is represented as G = {V, E}, where G is the graph
space, V is the set of vertices and E is the set of edges. If E is empty,
the graph is known as a forest.
Representation of Graphs:

While representing graphs, we must carefully depict the elements


(vertices and edges) present in the graph and the relationship between
them. Pictorially, a graph is represented with a finite set of nodes and
connecting links between them. However, we can also represent the
graph in other most commonly used ways, like −

 Adjacency Matrix
 Adjacency List

 Adjacency Matrix:

The Adjacency Matrix is a V×V matrix where the values are filled
with either 0 or 1. If the link exists between Vi and Vj, it is recorded
1; otherwise, 0.

For the given graph below, let us construct an adjacency matrix −

The adjacency matrix is −


Adjacency List

The adjacency list is a list of the vertices directly connected to the


other vertices in the graph.

The adjacency list is:

Tower of Hanoi solving problem using DSA


The Tower of Hanoi is a mathematical puzzle in which the objective
is to move a stack of disks from one rod to another, following certain
rules:

 Only one disk can be moved at a time.


 Each move consists of taking the upper disk from one of the
stacks and placing it on top of another stack or on an empty rod.
 No disk may be placed on top of a smaller disk.

The puzzle is typically played with three rods, but can be played with
any number of rods. The number of moves required to solve the
puzzle is 2n-12, where n is the number of disks.

Fig 8: Diagramatically representation of Tower of Hanoi problem


solving

Program of Java for solve Tower of Hanoi problem:


Output of above Tower of Hanoi problem’s code:

Some another programs for different problems:


 Program for check duplicate number in an array using
Java:

Output:

 Program for matrix reshape using Java:


Output:

 Program for search matrix position using Java:


Output:

CONCLUSION
My Data Structure and Algorithm internship at Yhills has been an
invaluable experience that has provided me with a deep understanding
of data structures and algorithms and their application in real-world
scenarios. I have gained hands-on experience in designing,
implementing, and testing various data structures and algorithms, and
I have learned how to choose the right data structures and algorithms
for specific tasks. I have also developed my problem-solving skills
and my ability to think critically about complex problems.

I am grateful for the opportunity to have worked with such a talented


team of engineers and scientists. I have learned a great deal from
them, and I am confident that the skills I have gained will be valuable
to me in my future career.

I would highly recommend the DSA internship program at Yhills to


any student who is interested in learning more about data structures
and algorithms. The program is challenging but rewarding, and it
provides a great opportunity to gain hands-on experience in a real-
world setting.

Key takeaways from my internship:

 The importance of choosing the right data structures and algorithms


for specific tasks.
 How to design, implement, and test various data structures and
algorithms.
 How to apply data structures and algorithms to solve real-world
problems.
 How to think critically about complex problems and develop effective
solutions.

You might also like