Summer Training Report
Summer Training Report
Summer Training Report
GEEKSFORGEEKS
A summer training report submitted.
In partial fulfilment of the requirements for the
degree of Bachelor of Technology (Computer
Science and Engineering)
Submitted by
M. Yaswanth
(12201662)
1
CERTIFICATE:
!
)#224$$&22'4,,6$/-0,&3&%# 5&&+$/412&/.#3#314$341&2
#.%,(/1*3)-2&,'#$&%
/4.%&1&&+2'/1&&+2
)3302-&%*#(&&+2'/1(&&+2/1($/412&2$&13*'*$#3&2 $# %% $'# $%$ $0%'
2
STUDENT DECLARATION
ACKNOWLEDGEMENT
I would like to express my gratitude towards all the people
who have contributed their precious time and effort to
3
help me. Whom I would not have been able to understand
and complete my summer training without.
TABLE OF CONTENTS
4
1 Cover Page 1
2 Certificate 2
3 Student Declaration 3
4 Acknowledgement 4
5 Contents 5
6 Introduction 6
7 Technology Learnt 7
5
9 Project 44
10 Learning Outcome 46
Bibliography 47
11
INTRODUCTION
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. To structure the data in memory, 'n' number of
algorithms were proposed, and all these algorithms are
known as Abstract data types.
DATA STRUCTURES
Data Structures are a specialized means of organizing and
storing data in computers in such a way that we can
perform operations on the stored data more efficiently.
Data structures have a wide and diverse scope of usage
across the fields of Computer Science and Software
Engineering.
ALGORITHMS
The word Algorithm means” A set of rules to be followed in
calculations or other problem-solving operations” Or” A
6
procedure for solving a mathematical problem in a finite
number of steps that frequently by recursive operations “.
TECHNOLOGY LEARNT
Data structures and algorithms from basic to advanced
level.
An 8 weeks long course to master the basics of DSA and
practice coding questions and attempt assessment tests It
comes with more than 200+ questions and contests helped
learn all the concepts of Data structures and algorithms such
as Arrays, Linked List, Trees, queues, Hashing, Searching,
Matrix, Binary Search Tree, Heap, Graph, Greedy,
Backtracking, Dynamic Programming, Asymptotic Notations
and concepts of recursions and bit magic.
7
To predict the behavior of an algorithm without
implementing it on a specific computer.
8
1) Asymptotic Notations-:
Asymptotic notations are mathematical tools to
represent the time complexity of algorithms for
asymptotic analysis. The following 3 asymptotic
notations are mostly used to represent the time
complexity of algorithms:
9
• Big O Notation: The Big O notation defines an upper
bound of an algorithm, it bounds a function only
from above. For example, consider the case of
Insertion Sort. It takes linear time in best case and
quadratic time in worst case. We can safely say that
the time complexity of Insertion sort is O(n^2). Note
that O(n^2) also covers linear time.
If we use O notation to represent time complexity
of Insertion sort, we have to use two statements for
best and worst cases:
10
• Ω Notation: Just as Big O notation provides an
asymptotic upper bound on a function, Ω notation
provides an asymptotic lower bound. Ω Notation
can be useful when we have lower bound on time
complexity of an algorithm. The Omega notation is
the least used notation among all three.
Worst, Average and Best-Case Time Complexities
It is important to analyze an algorithm after writing it to
find its efficiency in terms of time and space in order to
improve it if possible.
1. Worst Case
2. Average Case
3. Best Case
11
Arrays -:
An array is a collection of items of the same data type
stored at contiguous memory locations. This makes it
easier to calculate the position of each element by simply
adding an offset to a base value, i.e., the memory location
of the first element of the array (generally denoted by the
name of the array).
12
Advantages of using arrays:
• Arrays allow random access of elements. This makes
accessing elements by their position faster.
• Arrays have better cache locality that can make a
pretty big difference in performance.
1) Traversal 2)
Insertion
3) Deletion
4) Search
Traversal:
Visiting every element of an array once is known as
traversing the array.
13
Insertion:
An element can be inserted in an array at a specific
position. For this operation to succeed, the array must have
enough capacity. Suppose we want to add an element 10 at
index 2 in the below-illustrated array, then the elements
after index 1 must get shifted to their adjacent right to
make way for a new element.
Deletion:
An element at a specified position can be deleted, creating
a void that needs to be fixed by shifting all the elements to
their adjacent left. We can also bring the last element of
the array to fill the void if the relative ordering is not
important
Searching:
Searching can be done by traversing the array until the
element to be searched is found O(n)
• Linear Search
• Binary Search
14
Linear Search
• Start with index 0 and compare each element with the target
• If the target is found to be equal to the element, return its index • If the target
is not found, return -1
Binary Search
This type of searching algorithm is used to find the posi6on of
a specific value contained in a sorted array. The binary
search algorithm works on the principle of divide and conquer
and it is considered the best searching algorithm because it's
faster to run.
15
• This process is repeated until the middle element is
equal to the target element, or the target element is
not in the array
• If the target element is found, its index is returned,
else -1 is returned.
Sorting
Sorting any sequence means to arrange the elements of that sequence
according to some specific criterion.
• Insertion Sort
• Selection Sort
• Bubble Sort
Insertion Sort
Insertion Sort is an In-Place sorting algorithm. This
algorithm works in a similar way of sorting a deck of
playing cards.
The idea is to start iterating from the second element of
array till last element and for every element insert at its
correct position in the subarray before it. Selection
Sort
The selection sort algorithm sorts an array by repeatedly
finding the minimum element (considering ascending
order) from unsorted part and putting it at the beginning.
The algorithm maintains two subarrays in a given array.
16
• Remaining subarray which is unsorted.
In every iteration of selection sort, the minimum element
(considering ascending order) from the unsorted subarray
is picked and moved to the sorted subarray.
Bubble Sort
In one iteration if we swap all adjacent elements of an array
such that after swap the first element is less than the
second element then at the end of the iteration, the first
element of the array will be the minimum element.
Matrix
A matrix represents a collection of numbers arranged in
order of rows and columns. It is necessary to enclose the
elements of a matrix in parentheses or brackets.
17
The above Matrix M has 3 rows and 3 columns. Each
element of matrix [M] can be referred to by its row and
column number.
Terminologies
18
• Square Matrix: A square Matrix has as many rows as it
has columns. i.e., no of rows = no of columns.
• Symmetric matrix: A square matrix is said to be
symmetric if the transpose of original matrix is equal
to its original matrix. i.e. (AT) = A.
• Skew-symmetric: A skew-symmetric (or antisymmetric
or antimetric [1]) matrix is a square matrix whose
transpose equals its negativities. (AT) = -A.
19
• Non-singular Matrix: A square matrix is said to be
nonsingular matrix if its determinant is non-zero.
Matrix Operation
1) Matrices Addition
20
1) Matrices Subtraction
21
Matrices Multiplication
22
Hashing
Hash Function:
23
A function that converts a given big phone number to a
small practical integer value. The mapped integer value is
used as an index in the hash table. In simple terms, a hash
function maps a big number or string to a small integer
that can be used as an index in the hash table.
A good hash function should have following properties:
24
table is called collision and must be handled using some
collision handling technique. Following are the ways to
handle collisions:
25
LINKED LIST
Linked Lists are linear or sequential data structures in which
elements are stored at non-contiguous memory locations
and are linked to each other using pointers.
Like arrays, linked lists are also linear data structures but in
linked lists elements are not stored at contiguous memory
locations. They can be stored anywhere in the memory but
for sequential access, the nodes are linked to each other
using pointers.
26
The size of the arrays is fixed, so we must know the upper
limit on the number of elements in advance. Also,
generally, the allocated memory is equal to the upper limit
irrespective of the usage. On the other hand, linked lists
are dynamic and the size of the linked list can be
incremented or decremented during runtime.
27
• Extra memory space for a pointer is required with each
element of the list.
STACK
28
In LIFO order, the insertion takes place at the rear end of
the stack and deletion occurs at the rear of the stack.
29
How to understand a stack practically?
There are many real-life examples of a stack. Consider the
simple example of plates stacked over one another in a
canteen. The plate that is at the top is the first one to be
removed, i.e., the plate that has been placed at the
bottommost position remains in the stack for the longest
period of time. So, it can be simply seen to follow LIFO/FILO
order.
30
• Using array
• Using linked list
Queue
Like Stack data structure, Queue is also a linear data
structure that follows a particular order in which the
operations are performed. The order is First In First Out
(FIFO), which means that the element that is inserted first in
the queue will be the first one to be removed from the
queue. A good example of queue is any queue of
consumers for a resource where the consumer who came
first is served first.
31
Operations on Queue: Mainly the following four basic
operations are performed on queue:
32
TREE
33
• Root: The root of a tree is the first node of the tree.
In the above image, the root node is the node 30.
• Edge: An edge is a link connecting any two nodes in
the tree. For example, in the above image there is an
edge between node 11 and 6.
• Siblings: The children nodes of same parent are
called siblings. That is, the nodes with same parent
are called siblings. In the above tree, nodes 5, 11, and
63 are siblings.
• Leaf Node: A node is said to be the leaf node if it has
no children. In the above tree, node 15 is one of the
leaf nodes.
• Height of a Tree: Height of a tree is defined as the
total number of levels in the tree or the length of the
path from the root node to the node present at the
last level. The above tree is of height 2.
34
Types of Binary Trees: Based on the structure and
number of parents and children nodes, a Binary Tree is
classified into the following common types:
35
• Complete Binary Tree: A Binary Tree is a complete
Binary Tree if all levels are completely filled except
possibly the last level and the last level has all keys as
left as possible
36
tree of height h is 1 + 2 + 4 + .. + 2h-1. This is a simple
geometric series with h terms and sum of this series
is 2h – 1. In some books, the height of the root is
considered as 0. In that convention, the above
formula becomes 2h+1 – 1.
37
HEAP
38
Binary Heap:
A Binary Heap is a heap where each node can have at most
two children. In other words, a Binary Heap is a complete
Binary Tree satisfying the above-mentioned properties.
39
40
GRAPH
41
structure and contains information like person id,
name, gender and locale.
42
•
43
Representing Graphs
Following two are the most commonly used
representations of a graph:
Adjacency Matrix:
The Adjacency Matrix is a 2D array of size V x V where V is
the number of vertices in a graph. Let the 2D array be
adj[][], a slot adj[i][j] = 1 indicates that there is an edge
from vertex i to vertex j. Adjacency matrix for undirected
graph is always symmetric. Adjacency Matrix is also used to
represent weighted graphs. If adj[i][j] = w, then there is an
edge from vertex i to vertex j with weight w.
Adjacency List:
Graph can also be implemented using an array of lists. That
is every index of the array will contain a complete list. Size
of the array is equal to the number of vertices and every
index i in the array will store the list of vertices connected to
the vertex numbered i. Let the array be array[]. An entry
array[i] represents the list of vertices adjacent to the ith
vertex. This representation can also be used to represent a
weighted graph. The weights of edges can be represented
as lists of pairs. Following is the adjacency list
representation of the above example undirected graph.
BACKTRACKING
A backtracking algorithm is a problem-solving algorithm
that uses a brute force approach for finding the desired
44
output. The Brute force approach tries out all the possible
solutions and chooses the desired/best solutions. The
term backtracking suggests that if the current solution is
not suitable, then backtrack and try other solutions. Thus,
recursion is used in this approach. This approach is used
to solve problems that have multiple solutions
Backtracking Algorithm
1)To find all Hamiltonian Paths present in a graph
2)To solve the N Queen problem
DYNAMIC PROGRAMMING
45
We can also see Dynamic Programming as dividing a
particular problem into subproblems and then storing the
result of these subproblems to calculate the result of the
actual problem.
46
complex problems with ease and now a days data
structures and algorithm is base of every software
job interviews every company interview you face
question related to data structures and algorithms
are asked which makes it the most demanding
technology to learn .
Project
Implementation of Tic-Tac-Toe game
47
• If no one wins, then the game is said to be draw
48
Check for a Win or Draw: After each move, check if the
current player has won the game or if the game has
ended in a draw. This involves checking rows, columns,
and diagonals for three consecutive symbols.
MINIMAX ALGORITHM
The algorithm associated with the tic tac toe games is
minimax algorithm it is a kind of backtracking algorithm that
is used in decision making and game theory in order to find
the optimal move for a player, assuming that your
opponent also plays optimally. It is widely used in two
player turn based games such as tic-tac-toe, chess etc.
49
The minimax algorithm performs a depth-first search
algorithm for the exploration of the complete game tree.
LEARNING OUTCOME
50
BIBLIOGRAPHY
• https://www.geeksforgeeks.org/dsa-
selfpacedcoursebasic-to-advanced-online-
coursebygeeksforgeeks/
• https://www.programiz.com/dsa/dynamicprogrammi
n g#:~:text=Dynamic%20Programming%20is
%20a%20technique,subproblems%20and%20optimal%20
substructure%20property.
• https://practice.geeksforgeeks.org/batch/dsa-4
51