Professional Documents
Culture Documents
Vaishnavi Dwivedi
Roll Number - 198330097
(2022-23)
Bachelor Of Technology
Computer Science and Engineering
IET DSMNRU
This is to declare that the industrial training report entitled mastering in DSA with c++ summited
by Vaishnavi Dwivedi of B .Tech final year in the year 2022- 2023 of Computer Science and
Engineering Department of this institute is a satisfactory account of his industrial training work
based on syllabus which is approved for the award of degree of Bachelor of Technology.
ACKNOWLEDGEMENT
The completion of this training work could have been possible
with continued and dedicated effort of large number of faculty and
staff member of the institute. I acknowledge my gratitude to all of
them. I am also thankful to sir, who provided strong support
throughout this training and helped me to complete the training
successfully. Finally I would like to say that I’m in debt to my
parents for everything that they have done for me. All of this
would have been impossible without their constant support and I
also thanks to GOD for being kind to me and driving me through
this journey.
What you'll learn
• C++ programming basics
• C++ data types
• C++ data structures
• Input/Output in C++
• Control Flow in C++
• Loops
• Functions
• OOP in C++
• Memory management
• Macros
Course Features
• Course material
• Course resources
• Practical exercises
• Quizzes
• Assignments
11 | P a g e
Company Profile
Introduction:
Our goal is to make education and experiential skills affordable and
accessible to everyone regardless of their disparate economic and
educational backgrounds. We empower students to make demands unlike
any other platform or institute because curiosity cannot be contained.
Learning cannot be boxed in a book. So let’s step ahead and ‘build together’.
Data structures and algorithms (DSA) goes through solutions to standard problems in detail and
gives you an insight into how efficient it is to use each one of them. It also teaches you the science
of evaluating the efficiency of an algorithm. This enables you to choose the best of various choices.
For example, an algorithm to solve the problem of factorials might look something like
this:
Initialize fact = 1
12 | P a g e
For every value v in range 1 to n:
int factorial(int n) {
int fact = 1;
for (int v = 1; v <= n; v++) {
fact = fact * v;
}
return fact;
}
Programming is all about data structures and algorithms. Data structures are used to
hold data while algorithms are used to solve the problem using that data.
Data structures and algorithms (DSA) goes through solutions to standard problems in
detail and gives you an insight into how efficient it is to use each one of them. It also
teaches you the science of evaluating the efficiency of an algorithm. This enables you
to choose the best of various choices.
Initialize sum = 0
Code
int findSum() {
int sum = 0;
for (int v = 1; v <= 100000000000; v++) {
sum += v;
}
return sum;
}
Alice and Bob are feeling euphoric of themselves that they could build something of
their own in almost no time. Let's sneak into their workspace and listen to their
conversation.
Alice: Let's run this code and find out the sum.
Bob: I ran this code a few minutes back but it's still not showing the output. What's wrong with
it?
Oops, something went wrong! A computer is the most deterministic machine. Going
back and trying to run it again won't help. So let's analyze what's wrong with this simple
code.
Two of the most valuable resources for a computer program are time and memory.
The time taken by the computer to run code is:
The number of instructions depends on the code you used, and the time taken to
execute each code depends on your machine and compiler.
In this case, the total number of instructions executed (let's say x) are x = 1 + (1011 + 1) +
14 | P a g e
Let us assume that a computer can execute y = 108 instructions in one second (it can
vary subject to machine configuration). The time taken to run above code is
Hence,
Is it possible to optimize the algorithm so that Alice and Bob do not have to wait for 33
minutes every time they run this code?
I am sure that you already guessed the right method. The sum of first N natural
numbers is given by the formula:
Sum = N * (N + 1) / 2
int sum(int N) {
return N * (N + 1) / 2;
This code executes in just one instruction and gets the task done no matter what the
value is. Let it be greater than the total number of atoms in the universe. It will find the
result in no time.
The time taken to solve the problem, in this case, is 1/y (which is 10 nanoseconds). By
the way, the fusion reaction of a hydrogen bomb takes 40-50 ns, which means your
program will complete successfully even if someone throws a hydrogen bomb on your
computer at the same time you ran your code. :)
15 | P a g e
Why we need Data structures and algorithms
16 | P a g e
Concept of Big O and graphs
17 | P a g e
DATA STRUCTURE INTRO DUCTION
• Memory process Stack and Heap
18 | P a g e
Abstract Data Types ADT
bstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a
set of values and a set of operations.
19 | P a g e
RECURSION
20 | P a g e
Types of Recursion
21 | P a g e
What is Factorial
Factorial of a whole number 'n' is defined as the product of that number with every whole
number less than or equal to 'n' till 1.
22 | P a g e
Fibonacci series THEORY
23 | P a g e
Fibonacci series and its version CPP Code:-
24 | P a g e
Classic Tower of Hanoi CPP code
25 | P a g e
Add value in linked list cases
26 | P a g e
Deletion in linked list CPP code
27 | P a g e
Stack Push and Pop operation THEORY
28 | P a g e
Queue concept THEORY
29 | P a g e
Queue implementation in CPP code v:-
30 | P a g e
Creating a Binary Search tree CPP code
31 | P a g e
SORTING ALGORITHMS :-
SELECTION SORT:- Selection sort is a simple and efficient sorting algorithm that
works by repeatedly selecting the smallest (or largest) element from the unsorted portion
of the list and moving it to the sorted portion of the list. The algorithm repeatedly selects
the smallest (or largest) element from the unsorted portion of the list and swaps it with
the first element of the unsorted portion. This process is repeated for the remaining
unsorted portion of the list until the entire list is sorted. One variation of selection sort is
called “Bidirectional selection sort” that goes through the list of elements by alternating
between the smallest and largest element, this way the algorithm can be faster in some
cases.
The algorithm maintains two subarrays in a given array.
• The subarray which already sorted.
• The remaining subarray was unsorted.
BUBBLE SORT :-
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the
adjacent elements if they are in the wrong order. This algorithm is not suitable for large
data sets as its average and worst-case time complexity is quite high.
32 | P a g e
How does Bubble Sort Work?
Input: arr[] = {5, 1, 4, 2, 8}
First Pass:
• Bubble sort starts with very first two elements, comparing them to check which
one is greater.
• ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two
elements, and swaps since 5 > 1.
• ( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4
• ( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2
• ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in
order (8 > 5), algorithm does not swap them.
INSERTION SORT :-
Insertion sort is a simple sorting algorithm that works similar to the way you sort playing
cards in your hands. The array is virtually split into a sorted and an unsorted part. Values
from the unsorted part are picked and placed at the correct position in the sorted part.
Characteristics of Insertion Sort:
• This algorithm is one of the simplest algorithm with simple implementation
• Basically, Insertion sort is efficient for small data values
• Insertion sort is adaptive in nature, i.e. it is appropriate for data sets which are
already partially sorted.
33 | P a g e
Working of Insertion Sort algorithm:
Consider an example: arr[]: {12, 11, 13, 5, 6}
12 11 13 5 6
First Pass:
• Initially, the first two elements of the array are compared in insertion sort.
12 11 13 5 6
• Here, 12 is greater than 11 hence they are not in the ascending order and 12 is
not at its correct position. Thus, swap 11 and 12.
• So, for now 11 is stored in a sorted sub-array.
11 12 13 5 6
34 | P a g e