You are on page 1of 29

Industrial Training Report On

Mastering in DSA with C++


Submitted By-

Vaishnavi Dwivedi
Roll Number - 198330097

(2022-23)

Bachelor Of Technology
Computer Science and Engineering
IET DSMNRU

Lucknow, Uttar Pradesh

Approved by AICTE, New Delhi


Declaration

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

• On demand recorded videos

• 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’.

Company Services in Technology


iNeuron started as a product development company, then launched its ed-tech division. We
provide 360 degree solutions from learning to internship to finding a job, and the first ever
educational OTT platform to upgrade your skill set.

Why we learn DSA?:

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.

What are Algorithms?


Informally, an algorithm is nothing but a mention of steps to solve a problem. They are
essentially a solution.

For example, an algorithm to solve the problem of factorials might look something like
this:

Problem: Find the factorial of n

Initialize fact = 1

12 | P a g e
For every value v in range 1 to n:

Multiply the fact by v

fact contains the factorial of n

Here, the algorithm is written in English. If it was written in a programming language,


we would call it to code instead. Here is a code for finding the factorial of a number in
C++.

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.

Use of Data Structures and Algorithms to Make Your


Code Scalable
Time is precious.
Suppose, Alice and Bob are trying to solve a simple problem of finding the sum of the
first 1011 natural numbers. While Bob was writing the algorithm, Alice implemented it
proving that it is as simple as criticizing Donald Trump.
13 | P a g e
Algorithm

Initialize sum = 0

for every natural number n in range 1 to 1011(inclusive):


add n to sum
sum is your answer

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:

Time to run code = number of instructions * time to execute each instruction

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) +

(1011) + 1 , which is x = 2 * 1011 + 3

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

Time to run y instructions = 1 second

Time to run 1 instruction = 1 / y seconds

Time to run x instructions = x * (1/y) seconds = x / y seconds

Hence,

Time to run the code = x / y

= (2 * 1011 + 3) / 108 (greater than 33 minutes)

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

Converting it into code will look something like this:

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

Time based approach

16 | P a g e
Concept of Big O and graphs

Data Structures and Algorithms Cases


• Problem solving
1. Start with a challenge reverse string

17 | P a g e
DATA STRUCTURE INTRO DUCTION
• Memory process Stack and Heap

Physical and logical data structures

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

Recursion is the technique of making a function call itself. This technique


provides a way to break complicated problems down into simple problems which are
easier to solve. Recursion may be a bit difficult to understand.

Tracing the recursion tree

20 | P a g e
Types of Recursion

Complex recursion tree

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.

Factorial program in CPP:-

22 | P a g e
Fibonacci series THEORY

23 | P a g e
Fibonacci series and its version CPP Code:-

Classic Tower of Hanoi problem

24 | P a g e
Classic Tower of Hanoi CPP code

Introduction to Linked List

25 | P a g e
Add value in linked list cases

Push Append and insertat in LinkedList CPP code

26 | P a g e
Deletion in linked list CPP code

27 | P a g e
Stack Push and Pop operation THEORY

Stack operations with CPP code

28 | P a g e
Queue concept THEORY

29 | P a g e
Queue implementation in CPP code v:-

BINARY SEARCH TREE

What is Binary Search tree and creation THEORY update


Binary Search Tree is a node-based binary tree data structure which has the following
properties: The left subtree of a node contains only nodes .

30 | P a g e
Creating a Binary Search tree CPP code

What is Hashing THEORY

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

You might also like