KP - Report 3 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

A

Training
Report on
DSA in C++
from
GeeksForGeeks

Submitted in the partial fulfillment of the requirements of the Degree of Bachelor of


Technology in Electrical & Electronics Engineering
By

Disha Singh
2000270210029

DEPARTMENT OF ELECTRICAL & ELECTRONICS ENGG.


AJAY KUMAR GARG ENGINEERING COLLEGE
GHAZIABAD (U.P)
Session: 2023-24

i
ABSTRACT

What is Data Structure?


A data structure is defined as a particular way of storing and organizing data in
our devices to use the data efficiently and effectively. The main idea behind using
data structures is to minimize the time and space complexities. An efficient data
structure takes minimum memory space and requires minimum time to execute
the data.
What is Algorithm?
Algorithm is defined as a process or set of well-defined instructions that are
typically used to solve a particular group of problems or perform a specific type of
calculation. To explain in simpler terms, it is a set of operations performed in a step-
by-step manner to execute a task.
How to start learning DSA?
The first and foremost thing is dividing the total procedure into little pieces
which need to be done sequentially.
The complete process to learn DSA from scratch can be broken into 4 parts:
1.Learn about Time and Space complexities
2.Learn the basics of individual Data Structures
3.Learn the basics of Algorithms
4.Practice Problems on DSA
ACKNOWLEDGEMENT

I express my deepest sense of gratitude towards for his patience,


inspiration, guidance, constant encouragement,moral support, keen interest,
and valuable suggestions during preparation of this Training report. My
heartfelt gratitude goes to all faculty members of Electrical & Electronics
Engineering Dept., who with their encouraging and caring words and most
valuable suggestions have contributed, directly or indirectly, in a significant
way .
I am indebted to all my classmates for taking interest in discussing my problem and
encouraging me. I owe a debt of gratitude to my father and mother for their consistent
support, sacrifice, candid views, and meaningful suggestion given to me at different
stages of this work. Last but not the least I am thankful to the Almighty who gave me
the strength and health for completing my report.

Disha Singh
CONTENT
1) ESSENTIAL C AND C++ CONCEPTS
1. ARRAY BASICS
2. STRUCTURES
3. POINTERS
4. REFERENCE IN C++
5. POINTER TO STRUCTURE
6. FUNCTION
7. PARAMETER PASSING METHODS
8. ARRAY AS PARAMETER
9. STRUCTURE AS PARAMETER
10.CONSTRUCTOR
11. TEMPLATE

2) RECURSION
1.HOW RECURSION WORKS
2.GENERALISING RECURSION
3.HOW RECURSION USES STACK RECURRENCE
RELATION-TIME COMPLEXITY OF RECURSION
4.STATIC AND GLOBAL VARIABLES
5.TAIL RECURSION
6.HEAD RECURSION
7.TREE RECURSION
8.INDIRECT RECURSION
9.NESTED RECURSION
10.PROGRAMS OF RECURSION

3) ARRAY REPRESENTATION
1.INTRODUCTION TO ARRAY S
2. ARRAYS VS DYNAMIC ARRAYS
3.2D-ARRAY
4) ARRAY ADT
1.ARRAY ADT
2.INSERTING IN ARRAY
3.DELETING FROM ARRAY
4.LINERA SEARCH
5.INPROVING LINEAR SEARCH
6.BINARY SEARCH
7.BINARY SEARCH ALGORITHIM
8.ANALYSIS OF BINARY SEARCH
9.GET ()/SET ()/AVG () FUNCTIONS ON ARRAY
10.REVERSE AND SHIFT AN ARRAY
11.CHECK IF ARRAY IS SORTED
12.MERGING ARRAYS SET OPERATOR ON ARRAY -: UNION,
INTERSECTION, DIFFERNCE

5) STRINGS
1.INTRODUCTION TO STRINGS
2.FINDING LENGTH OF A STRING
3.CHANGING CASE OF A STRING
4.COUNTING WORDS AND VOWELS ON A STRING
5.VALIDATING A STRING
6.REVERSING A STRING
7.COMPARING STRINGS CHECKING PLAINDROME
8.FINDING DUPLICATES IN A STRING FINDING FUPLICATES IN A
SGTRING USING BITWISE OPERATIONS
9.CHECKING IF 2 STRINGS ARE ANAGRAM

6) MATRICES
1.INTRODUCTION
2.DIAGONAL MATRIX
3.C++ CLASS FOR DIAGONAL MATRIX
4.LOWER TRIANGULAR MATRIX ROW-MAJOR MAPPING
5.UPPER TRIANGULAR MATRIX ROW-MAJOR MAPPING
6.UPPER TRIANGULAR MATRIX COLIMN-MAJOR MAPPING
7.SYMMETRIC MATRIX
8.TRI-DIGONAL AND TRI-BAND MATRIX
7)LINKED LIST
1.WHY WE NEED DYNAMIC DATASTRUCTURES
2.ABOUT LINKED LIST
3.DISPLAY LINKED LIST
4.RECURSIVE DISPLAY FOR LINKED LIST
5.COUNTING NODES IN LINKED LIST
6.SUM OF ALL ELEMENTS IN A LINKED LIST
7.SEARCHING IN A LINKED LIST
8.INSERTING IN A LINKED LIST
9.CREATING A LINKED LIST USING INSERT
10.CREATING A LINKED LIST BY INSERTING AT LAST
11.INSERTING IN A SORTED LINKED LIST
12.DELETING FROM A LINKED LIST
13.CHECK IF A LINKED LIST IS SORTED
14.REMOVE DUPLICATES FROM A SORTED LINKED LIST
15.REVERSING A LINKED LIST
16.REVERSING USING SLIDING POINTERS
17.CONCATENATING 2 LINKED LIST
18.MERGING 2 LINKED LISTS
19.CHECK FOR LOOP IN LINKED LIST
20.CIRCULAR LINKED LIST
21.DISPLAY CIRCULAR LINKED LIST
22.INSERTING IN A CIRCULAR LINKED LIST
23.DELETING FROM A CIRCULAR LINKED LIST
24.DOUBLY LINKED LIST
25.INSERTING IN A BOUBLY LINKED LIST
26.FELETING FROM A DOUBLY LINKED LIST
27.REVERSE A DOUBLY LINKED LIST
28.CIRCULAR DOUBLY LINKED LIST
29.COMPARISON OF ARRAY WITH LINKED LIST

8 STACK
INTRODUCTION TO STACK
1.STACK USING ARRAY
2.IMPLEMENTATION OF STACK USING ARRAY
3.STACK USING LINKED LIST
INTRODUCTION

a) STACK VS HEAP MEMORY:

Stack Allocation: The allocation happens on contiguous blocks of


memory. We call it a stack memory allocation because the allocation happens in
the function call stack. The size of memory to be allocated is known to the
compiler and whenever a function is called, its variables get memory allocated on
the stack. And whenever the function call is over, the memory for the variabless
de-allocated. This all happens using some predefined routines in the compiler.

Heap Allocation: The memory is allocated during the execution of


instructions written by programmers. Note that the name heap has
nothing to do with the heap data structure. It is called heap
because it is a pile of memory space available to programmers to
allocate and de- allocate. Every time when we made an object it
always creates in Heap- space and the referencing information to
these objects are always stored in Stack-memory.

Key Differences Between Stack and Heap Allocations


1.In a stack, the allocation and de-allocation are automatically
done
2.by the compiler whereas in heap, it needs to be done by the programmer
manually.
3.2. Handling of Heap frame is costlier than the handling of the stack
frame.

The most important point that you need to remember is for implementing the logical
data structures (Stack, Queue, Trees, Graphs, Hash Tables) we either use an array
or linked list or a combination of array and linked list physical data structures. So,
that is all we have given the introduction of various types of data structures. This
was just the introduction to give us awareness.
c) ADT (ABSTRACT DATA TYPE)

The abstract datatype is special kind of datatype, whose behavior is defined by a


set of values and set of operations. The keyword <Abstract= is used as we can use
these datatypes, we can perform different operations. But how those operations are
working that is totally hidden from the user. The ADT is made of with primitive
datatypes, but operation logics are hidden.

Let us see some operations of those mentioned ADT −

Stack −

isFull(), This is used to check whether stack is full or not


isEmpry(), This is used to check whether stack is empty or
not
push(x), This is used to push x into the stack
pop(), This is used to delete one element from top of the
stack
peek(), This is used to get the top most element of the
stack size(), this function is used to get number of
elements present into the stack

Queue

isFull(), This is used to check whether queue is full or not isEmpry(),


This is used to check whether queue is empty or not
insert(x), This is used to add x into the queue at the rear end delete(),
This is used to delete one element from the front end of the queue
size(), this function is used to get number of elements
present into the queue
size(), this function is used to get number of elements present
into the list
insert(x), this function is used to insert one element into the
list
remove(x), this function is used to remove given element
from the list
get(i), this function is used to get element at position i
replace(x, y), this function is used to replace x with y value

d) TIME AND SPACE COMPLEXITY:

Space Complexity
Space complexity of an algorithm represents the amount of memory space needed
the algorithm in its life cycle.
Space needed by an algorithm is equal to the sum of the following two components

A fixed part that is a space required to store certain data and variables (i.e. simple
variables and constants, program size etc.), that are not dependent of the size of the
problem.
A variable part is a space required by variables, whose size is totally dependent on
the size of the problem. For example, recursion stack space, dynamic memory
allocation etc.
Space complexity S(p) of any algorithm p is S(p) = A + Sp(I) Where A is treated as the
fixed part and S(I) is treated as the variable part of the algorithm which depends on
instance characteristic I. Following is a simple example that tries to explain the
concept

Time Complexity
Time Complexity of an algorithm is the representation of the amount of time required
by the algorithm to execute to completion. Time requirements can be denoted or
defined as a numerical function t(N), where t(N) can be measured as the number of
steps, provided each step takes constant time.
For example, in case of addition of two n-bit integers, N steps are taken.
Consequently, the total computational time is t(N) = c*n, where c is the time
consumed for addition of two bits. Here, we observe that t(N) grows linearly as
input size increases.

RECURSION

a) HOW RECURSION
WORKS:
When any function is called from main(), the memory is allocated to it on
the stack. A recursive function calls itself, the memory for a called
function is allocated on top of memory allocated to the calling function
and a different copy of local variables is created for each function call.
When the base case is reached, the function returns its value to the
function by whom it is called and memory is de-allocated and the process
continues.

b) TAIL
RECURSION:
Tail recursion is defined as a recursive function in which the recursive call
is the last statement that is executed by the function. So basically nothing
is left to execute after the recursion call.

// An example of tail recursive function

void print(int n)
{
if (n < 0)
return;
cout << " " << n;

// The last executed statement is recursive call


print(n - 1);
}

c) HEAD RECURSION:
If a recursive function calling itself and that recursive call is the first statement in
the function then it9s known as Head Recursion. There no statement, no
operation before the call. The function doesn9t have to process or perform any
operation at the time of calling and all operations are done at returning time.
Example:

// C++ program showing Head Recursion #include

<bits/stdc++.h>
using namespace std;
// Recursive function
void fun(int n)
{
if (n > 0) {
// First statement in the function
fun(n - 1);
cout << " "<< n;
}
}
// Driver code
int main()
{
int x = 3;
fun(x);
return 0;
}

d) TREE RECURSION:

A function that calls itself, is a recursive function. If it is calling itself


more than one time, then it is a tree recursion. Please have a look at the
below example which is an example
of a tree recursive function. As you can see fun is calling itself 2 times (more
than 1 time). In our example, we have shown the recursive call like 2 times,
but it can also be more than 2 times.
Dynamic Arrays:

Dynamic arrays differ from static arrays in that they don’t have a
fixed size. However, this is at the cost of having quick appends. How
a dynamic array works is that it resizes itself whenever it runs out of
space. This is usually by doubling itself. For example, if its size
defaulted to 10 indices then it would double to 20. Let’s take a closer
look at how it does this:

1. When you allocate a dynamic array your language of


choice will make a static array with a set size. Let’s say that
this
size is 10.
2. Let’s say you go to append an 11th item to your array. This
will make your array run out of space causing it to create a
bigger array that’s double its size (20).

Static Arrays:

When you allocate an array in a low-level language like C++ or Java, you
have to specify upfront how many indices you want your array to have like
so:

This makes the array static because it only has five indices that you
can use. This makes it impossible to append items when all five
indices are filled with values. The upside to this is that if you know
that you are only going to have five elements, then appending to this
array becomes worst case O(1) time.
c) 2D ARRAYS:

The two-dimensional array can be defined as an array of arrays. The 2D


array is organized as matrices which can be represented as the collection
of rows and columns. However, 2D arrays are created to implement a
relational database lookalike data structure

Declaration of two dimensional Array in C


The syntax to declare the 2D array is given

below. data_type array_name[rows][columns];

d) HOW TO INCREASE SIZE OF ARRAY:

If you want to change the size, you need to create a new array of the desired
size, and then copy elements from the old array to the
new array, and use the new array. In our example, arr can only hold int
values. Arrays can hold primitive values, unlike ArrayList, which can only
hold object values.

ARRAY ADT: a)
ADT indicates for Abstract Data Type.
Arrays are defined as ADT’s because they are capable of holding
contiguous
elements in the same order. And they permit
access for the specific element via index or position.
They are abstract because they can be String, int or Person
Advantages
Fast, random access of items or elements.
Very memory efficient, very little memory is needed other than
that needed to store the contents.

Disadvantages
Slow insertion and deletion of elements
Array size must be known when the array is created and is fixed (static)

b) Insertion in array:
Given an array arr of size n, this article tells how to
insert an element x in this array arr at a specific position
pos.

#include <stdio.h>

int main()
{
int arr[100] = { 0 };
int i, x, po
s, n = 10;
// initial array of size 10
for (i = 0; i < 10; i++)
arr[i] = i + 1;
// print the original array
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
// element to be inserted
x = 50;

// position at which element


// is to be inserted
pos = 5;

// increase the size by 1


n++;
// shift elements forward
for (i = n - 1; i >= pos; i--)
arr[i] = arr[i - 1];

// insert x at pos
arr[pos - 1] = x;
// print the updated array
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
return 0;

c) DELETING FROM ARRAY:


Given an array and a number w8xr9i,te a function to delete 8x9
from the given array. We assume that array maintains two things
with it, capacity and size. So when we remove an item, capacity
does not change, only size changes.

#include<bits/stdc++.h>
using namespace std;

// This function removes an element x from arr[] and


// returns new size after removal (size is reduced only
// when x is present in arr[]
int deleteElement(int arr[], int n, int x)
{
// Search x in array
int i;
for (i=0; i<n; i++)
if (arr[i] == x) break;
// If x found in array
if (i < n)
{
// reduce size of array and move all
// elements on space ahead
n = n - 1;
for (int j=i; j<n; j++)
arr[j] = arr[j+1];
}
return n;

d) LINEAR SEARCH:

Follow the given steps to solve the problem: Start from the leftmost
element of arr[] and one by one compare x
with each element of arr[]
If x matches with an element, return the index.
If x doesn9t match with any of the elements, return -1.

#include <stdio.h>

int search(int arr[], int N, int x)


{
int i;
for (i = 0; i < N; i++)
if (arr[i] == x)
return i;
return -1;
}

// Driver's code
int main(void)
{
int arr[] = { 2, 3, 4, 10, 40 };
int x = 10;
int N = sizeof(arr) / sizeof(arr[0]);

// Function call
int result = search(arr, N, x);
(result == -1)
? printf("Element is not present in array")
: printf("Element is present at index %d", result);
return 0;
}

e) BINARY SEARCH:
Binary Search Algorithm: The basic steps to perform Binary Search are:
1.Begin with the mid element of the whole array as a search key.
2.If the value of the search key is equal to the item then return an
3.index of the search key.
4.Or if the value of the search key is less than the item in the middle
5.of the interval, narrow the interval to the lower half.
6.Otherwise, narrow it to the upper half.
7.Repeatedly check from the second point until the value is found or
8.the interval is empty.
1) ITERATIVE METHOD:

binarySearch(arr, x, low, high)


repeat till low = high
mid = (low + high)/2
if (x == arr[mid])

return mid

else if (x > arr[mid]) // x is on the right side


low = mid + 1
else // x is on the left side

high = mid – 1
2) RECURSIVE METHOD:
binarySearch(arr, x, low, high)
if low > high
return False
else
mid = (low + high) / 2
if x == arr[mid]
return mid
else if x > arr[mid]
// x is on the right

return binarySearch(arr, x, mid + 1, high)

else // x is on the right

return binarySearch(arr, x, low, mid - 1)

STRING:

a) INTRODUCTION TO STRINGS:

A string is generally considered as a data type and is often


implemented as an array data structure of bytes (or words) that
stores a sequence of elements, typically characters, using some
character encoding. String may also denote more general arrays or
other sequence (or list) data types and structures.
#include <bits/stdc++.h>
using namespace std;

// Function to print permutations of string


// This function takes three parameters:
// 1. String
// 2. Starting index of the string
// 3. Ending index of the string.
void permute(string a, int l, int r)
{
// Base case
if (l == r)
cout<<a<<endl;
else
{
// Permutations made
for (int i = l; i <= r; i++)
{
// Swapping done
slw], aa[pi]()a; [
// Recursion called
permute(a, l+1, r);
//backtrack
swap(a[l], a[i]);
}
}
}

// Driver Code
int main()
{
string str = "ABC";
int n = str.size();
permute(str, 0, n-1);
return 0;

MATRICES:

a) INTRODUCTION:
What is Matíix in Data Stíuctuíe?

A matrix represents a collection of numbers arranged in an order of rows and columns. It

is necessary to enclose the elements of a matrix in parentheses or brack

b) DIAGONAL MATRIX:

For example, consider the following 4 X 4 input matrix.


A00 A01 A02
A03 A10 A11 A12
A13 A20 A21 A22
A23 A30 A31 A32
A33
The primary diagonal is formed by the elements A00, A11, A22,
A33.
Condition for Principal Diagonal:

#include <bits/stdc++.h>
using namespace std;

const int MAX = 100;

// Function to print the Principal Diagonal


void printPrincipalDiagonal(int mat[][MAX], int n)
{
cout << "Principal Diagonal: ";
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
// Condition for principal diagonal
if (i == j)
cout << mat[i][j] << ", ";
}
}
cout << endl;

C) SYMMETRIC MATRIX:

A Simple solution is to do following.


1. Create transpose of given matrix.
2. Check if transpose and given matrices are same or not

#include <iostream>
using namespace std;

const int MAX = 100;

// Returns true if mat[N][N] is symmetric, else false


bool isSymmetric(int mat[][MAX], int N)
{
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (mat[i][j] != mat[j][i])
return false;
return true;
}

// Driver code
int main()
{
int mat[][MAX] = { { 1, 3, 5 },
{ 3, 2, 4 },
{ 5, 4, 1 } };
if (isSymmetric(mat, 3))
cout << "Yes";
else
cout << "No";
return 0;
}
. Define a node current which initially points to the head of the list.
a. Traverse through the list till current points to null.
b. Display each node by making current to point to node next to it in each
iteration.

#include <stdio.h>
#include <stdlib.h>
1. //Represent a node of singly linked list
2. struct node{
3. int data;
4. struct node *next;
5. };
6.
7. //Represent the head and tail of the singly linked list
8. struct node *head, *tail = NULL;
9.
10. //addNode() will add a new node to the list
11. void addNode(int data) {
12. //Create a new node
13. struct node *newNode = (struct node*)malloc(sizeof(struct node));
14. newNode->data = data;
15. newNode->next = NULL;
16.
17. //Checks if the list is empty
18. if(head == NULL) {
19. //If list is empty, both head and tail will point to new node
20. head = newNode;
21. tail = newNode;
22. }
23. else {
24. //newNode will be added after tail such that tail's next will point
to newN ode
25. tail->next = newNode;
26. //newNode will become new tail of the list
27. tail = newNode;
28. }
29. }
30.
31. //display() will display all the nodes present in
the list 32. void display() {
33. //Node current will point to head
34. struct node *current = head;
35.
36. if(head == NULL) {
37. printf("List is empty\n");
38. return;
39. }
40. printf("Nodes of singly linked list: \n");
41. while(current != NULL) {
42. //Prints each node by incrementing pointer
43. printf("%d ", current->data);
44. current = current->next;
45. }
46. printf("\n");
47. }
48.
49. int main()
50. {
51. //Add nodes to the list
52. addNode(1);
53. addNode(2);
54. addNode(3);
55. addNode(4);
56.
57. //Displays the nodes present in the list
58. display();

c) DOUBLY LINKED LIST:

A Doubly Linked List (DLL) contains an extra pointer,


typically called the previous pointer, together with the next
pointer and data which are there in the singly linked list.
The plate which we put last is on the top and since we remove the plate
that is at the top, we can say that the plate that was put last comes out
first.
Basic Operations on Stack

In order to make manipulations in a stack, there are certain operations


provided to us.
push() to insert an element into the stack
pop() to remove an element from the stack
top() Returns the top element of the stack.
isEmpty() returns true is stack is empty else false
size() returns the size of stack

Push:
Adds an item to the stack. If the stack is full, then it is said to be an Overflow
condition.
Algorithm for push:

begin
if stack is full
return
endif
else
increment top
stack[top] assign value
end else
end procedure

Pop:
Removes an item from the stack. The items are popped in the reversed order
in which they are pushed. If the stack is empty, then it is said to be an
Underflow condition.
Algorithm for pop:
begin
if stack is empty
return
endif
else
store value of stack[top]
decrement top
return value
end else
end procedure

Top:
Returns the top element of the stack.
Algorithm for Top:
begin
return stack[top]
end procedure

isEmpty:
Returns true if the stack is empty, else
false. Algorithm for isEmpty:
begin
if top < 1
return true
else
return false
end procedure
Understanding 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 which is at the top is
the first one to be removed, i.e. the plate which 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 the LIFO/FILO order.

Time Complexity

Operations Complexity

push() O(1)

pop() O(1)

isEmpty() O(1)

size() O(1)

Types of Stacks:

Applications of the stack:

Register Stack: This type of stack is also a memory element


present in the memory unit and can handle a small amount of data
only. The height of the register stack is always limited as the size of
the register stack is very small compared to the memory.
Memory Stack: This type of stack can handle a large amount of memory data.
The height of the memory stack is flexible as it
occupies a large amount of memory data.

Infix to Postfix /Prefix conversion


Redo-undo features at many places like editors, photoshop.
Forward and backward features in web browsers
Used in many algorithms like Tower of Hanoi, tree traversals, stock
span problems, and histogram problems.
Backtracking is one of the algorithm designing techniques. Some
examples of backtracking are the Knight-Tour problem, N-Queen
problem, find your way through a maze, and game-like chess or
checkers in all these problems we dive into someway if that way is
not efficient we come back to the previous state and go into some
another path. To get back from a current state we need to store the
previous state for that purpose we need a stack.
In Graph Algorithms like Topological Sorting and Strongly
Connected Components
3. Trivial Graph:
A graph is said to be trivial if a finite graph contains only one vertex and no
edge.

4. Simple Graph:
A simple graph is a graph that does not contain more than one edge
between the pair of vertices. A simple railway track connecting different
cities is an example of a simple graph.
5. Multi Graph:
Any graph which contains some parallel edges but

doesn’t contain any self-loop is called a multigraph. For example a Road Map. Parallel Edges:
If two vertices are connected with more than one
edge then such edges are called parallel edges that are many routes

but one destination. Loop:


An edge of a graph that starts from a vertex and ends at the
same vertex is called a loop or a self-loop.
6. Null Graph:
A graph of order n and size zero is a graph where there are only isolated
vertices with no edges connecting any pair of vertices.

7. Complete Graph:
A simple graph with n vertices is called a complete graph if the degree of each
vertex is n-1, that is, one vertex is attached with n-1 edges or the rest of the
vertices in the graph. A complete graph is also called Full Graph.

8. Pseudo Graph:
A graph G with a self-loop and some multiple edges is called a pseudo graph.
9. Regular Graph:
A simple graph is said to be regular if all vertices of graph G are of equal degree.
All complete graphs are regular but vice versa is not possible.

10.
A Bipartite
graph G = (V,Graph:
E) is said to be a bipartite graph if its vertex set V(G) can be
partitioned into two non-empty disjoint subsets. V1(G) and V2(G) in such a way
that each edge e of E(G) has one end in V1(G) and another end in V2(G). The
partition V1 U V2 = V is called Bipartite of G. Here in the figure: V1(G)={V5, V4,
V3} and V2(G)={V1, V2}
11. Labeled Graph:
If the vertices and edges of a graph are labeled with name, date, or weight
then it is called a labeled graph. It is also called Weighted Graph.

12. Digraph Graph:


A graph G = (V, E) with a mapping f such that every edge maps onto some
ordered pair of vertices (Vi, Vj) are called a Digraph. It is also called Directed
Graph. The ordered pair (Vi, Vj) means an edge between Vi and Vj with an
arrow directed from Vi to Vj. Here in the figure: e1 = (V1, V2) e2 = (V2, V3) e4
= (V2, V4)
ASYMPTOTIC ANALYSIS:

Asymptotic analysis of an algorithm refers to defining the mathematical


boundation/framing of its run-time performance. Using asymptotic analysis, we can
very well conclude the best case, average case, and worst case scenario of an
algorithm.
Asymptotic analysis is input bound i.e., if there's no input to the algorithm, it is
concluded to work in a constant time. Other than the "input" all other factors are
considered constant.
Asymptotic analysis refers to computing the running time of any operation in
mathematical units of computation. For example, the running time of one operation
is computed as f(n) and may be for another operation it is computed as g(n2).
This
means the first operation running time will increase linearly with the increase in n
and the running time of the second operation will increase exponentially when
n increases. Similarly, the running time of both operations will be nearly the same
if n is significantly small.
Usually, the time required by an algorithm falls under three types −
Best Case − Minimum time required for program execution.
Average Case − Average time required for program execution.
Worst Case − Maximum time required for program execution.
Asymptotic Notations
Following are the commonly used asymptotic notations to calculate the running time
complexity of an algorithm.
Notation Ω
Notation Ο
Notation θ

Big Oh Nota tionΟ,


The notation Ο(n) is the formal way to express the upper bound of an
algorithm's running time. It measures the worst case time complexity or the
longest amount of time an algorithm can possibly take to complete.

OMEGA NOTATION :
The notation
Ω(n) is the formal way to express the lower bound of an algorithm's running time. It measures the
bes cas an algorithm can possibly take to complete.

For example, for a function(n)


f

Theta Notationθ,
The notation
θ(n) is the formal way to express both the lower bound and the upper bound of an algorithm's running tim

CONCLUSION
In conclusion, data structures are a great tool to computer science and
the professionals who utilize them. Data structures have their advantages
and disadvantages like everything in our lives. Only advance users can
make changes to data structures, and any problem involving data
structure will need a professional to rectify. Luckily, there are more
advantages than there are disadvantages. Data structures allow
information storage, it provides the means for management of large data
like databases, work together and are necessary for efficient algorithms,
safe storage of data, allows easier processing of data, and the use of the
internet to access data anytime. With those odds, this makes it easy to
accept that without these applications in our lives, life would be that much
harder when dealing with computer science and even our day to day tasks
REFERENCES
www..https.leetcode.com
www.https://geeks for geeks com
www.cpalgorithum.com
www.codzilla.com
www.freecodecamp.org

THANK YOU

You might also like