[go: up one dir, main page]

0% found this document useful (0 votes)
107 views45 pages

Data Structure and Algorithms Short Note: NSJ Online Academy

This document provides a short overview of key data structures and algorithms concepts. It defines data structures as the arrangement of data in computer memory or storage. It describes common data structures like arrays, linked lists, stacks, queues and trees. It also covers basic algorithms like sorting and discusses different sorting techniques like selection sort. Big O notation is introduced as a way to describe the time complexity of algorithms. The document provides examples of implementing various data structures and algorithms in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views45 pages

Data Structure and Algorithms Short Note: NSJ Online Academy

This document provides a short overview of key data structures and algorithms concepts. It defines data structures as the arrangement of data in computer memory or storage. It describes common data structures like arrays, linked lists, stacks, queues and trees. It also covers basic algorithms like sorting and discusses different sorting techniques like selection sort. Big O notation is introduced as a way to describe the time complexity of algorithms. The document provides examples of implementing various data structures and algorithms in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 1


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

❖ What is Data Structure?

Data structure is the arrangement of data in a computer


memory/storage.

❖ Big 0 Notation

We can say that a function is "of the order of n", which can be written as
O(n) to describe the
upper bound on the number of operations. This is called Big-Oh notation.

❖ Best Case Efficiency

Best case efficiency is the minimum number of steps that an algorithm


can take any collection of data values.

❖ Worst Case Efficiency

Worst case efficiency is the maximum number of steps that an algorithm


can take for any collection of data values.

❖ Average Case Efficiency

is the efficiency averaged on all possible inputs


must assume a distribution of the input
is normally assumed for uniform distribution (all keys are equally
probable)

❖ Abstract Data Types

ADT is a specification of a mathematical set of data and the set of


operations that can be performed on the data

NSJ ONLINE ACADEMY 2


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

Data Types

Array Data Structure

NSJ ONLINE ACADEMY 3


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

A program to store and print elements in an array

#include<iostream.h>
#include<conio.h>
void main()
{
int i;
char keys[6]={'Q','W','E','R','T','Y'};
cout<<"The first 6 keys of a keyboard are ";
for (i=0; i<=5; i++)
cout<<keys[i]<<" ";
}

A program to search and replace an element in an array:

#include<iostream.h>
#include<conio.h>
void main()
{
int i;
char s,r;
int found=0; //found=false
char keys[6]={'Q','W','E','R','T','Y'};
cout<<"Enter a character to be searched: "; cin>>s;
cout<<"Enter a character to replace: "; cin>>r;
i= (-1);
while (i<5 && found==0)
if (keys[++i]==s) found=1;
if (found==1)
keys[i]=r;
else
cout<<"No such element.";
}

NSJ ONLINE ACADEMY 4


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

A program to delete an element from an array

#include<iostream.h>
#include<conio.h>
void main()
{
int i;
char d;
nt found=0; //found=false
char keys[6]={'Q','W','E','R','T','Y'};
cout<<"Enter a character to be deleted: "; cin>>d;
i= (-1);
while (i<5 && found==0)
if (keys[++i]==d) found=1;
if (found==1)
keys[i]=NULL;
else
cout<<"No such element."
}

Multi-Dimensional Array:

NSJ ONLINE ACADEMY 5


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

A program to store and print elements in a two dimensional array:

#include<iostream.h>
#include<conio.h>
void main()
{
Int i,j;
clrscr();
int matrix[3][4]={{5,3,6,4},{2,5,3,7},{3,6,5,8}};
cout<<"The elements of the array are";
for (i=0; i<3; i++)
{
for (j=0; j<4; j++)
cout<<matrix[i][j]<<"\t";
cout<<"\n";
}
}

❖ Advantages of arrays:

Fast access if index is known


Easy to add an element in a particular location.

NSJ ONLINE ACADEMY 6


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

❖ Disadvantages of arrays:

Fixed size
Same data type
Slow in searching an element
Slow in inserting/deleting an element

Linked List Data Structure

❖ What is Pointer?

Pointer contains memory address of a particular type of data.

NSJ ONLINE ACADEMY 7


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

❖ What is Structure (in C++)?

❖ What is Linked List?

A linked list consists of nodes of data which are connected to other


nodes.
Linked lists can be linear and non-linear data structures however arrays
are linear data structures.
There are several types of linked lists.

NSJ ONLINE ACADEMY 8


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 9


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 10


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 11


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 12


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

Stack Data Structure

❖ What is Stack

Stack is a data structure which is used to handle data in a last-in-first-out (LIFO) method.
That is we
can remove the most recently added element from the stack first.
Undo sequence in a text editor and the chain of method calls in a programming
language are
examples for applications of stack.

NSJ ONLINE ACADEMY 13


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

❖ Common operations of Stack are:

initializeStack() – initializes the stack as empty stack.


push()- adds an element on top of the stack.

NSJ ONLINE ACADEMY 14


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

pop()-removes and returns the top most element from the stack.
topElt()-returns the top element without removing it.
isEmpty() - returns true if the stack has no elements and false otherwise.
isFull() - returns true if the stack is full of elements and false otherwise.
displayStack() - displays all elements from top to bottom.

NSJ ONLINE ACADEMY 15


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 16


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 17


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 18


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 19


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 20


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 21


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

Queue Data Structure

❖ What is Queue?

Queue is a data structure which is used to handle data in a first-in-


first-out (FIFO) method. That is we
can remove the element which has been added earlier from the
queue first

❖ Common operations of Queue are

initializeQueue() – initializes the queue as empty queue.


enQueue()- adds an element at the rear of the queue.
deQueue()-removes and returns the front element from the queue.
frontElt()-returns the front element without removing it.
isEmpty() - returns true if the queue has no elements and false
otherwise.
isFull() - returns true if the queue is full of elements and false
otherwise.
displayQueue() - displays all elements from front to rear.

NSJ ONLINE ACADEMY 22


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 23


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 24


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 25


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 26


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 27


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 28


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 29


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 30


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

Tree Data Structure

❖ What is Tree?

A tree is a widely-used data structure that emulates a hierarchical


tree structure with a set of linked
nodes

1. Root, parent, child, sibling, leaf

Every child node has a unique parent.


Every parent node can have any number of children (including none).
There is one unique node in every tree which has no parent and is called
the root of the tree.
An internal node has one or more children.
A leaf node has no children.
Nodes with the same parent are called siblings

NSJ ONLINE ACADEMY 31


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 32


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 33


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 34


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

Sorting Algorithm
❖ What is sorting?

Arranging items in ascending or descending order is called as sorting.


There are different types of sorting techniques each of which is good for
some cases such as nearly
sorted, reversed, random, etc

❖ Selection Sort:

Here we repeatedly find the next largest (or smallest) element in the
array and move it to its final

NSJ ONLINE ACADEMY 35


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

position in the sorted array.


Example: Sort the numbers 6, 7, 72, 4, 32, 65, 9, 56 using selection sort

NSJ ONLINE ACADEMY 36


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

❖ Bubble Sort
Here we repeatedly move the largest element to the highest index
position of the array.
Example: Sort the numbers 6, 7,72, 4, 32, 65, 9, 56 using bubble sort.
NSJ ONLINE ACADEMY 37
DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 38


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 39


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 40


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

Searching Algorithm
❖ What is search algorithm?

A search algorithm is an algorithm for finding an item among a


collection of items.
Here, we will concentrate on two search algorithms:
Sequential/Linear Search and Binary Search.

❖ Sequential Search:

It examines the first element in the list and then second element and
so on until a match is found.

❖ Sequential Search Algorithm (Pseudocode)

int sequentialSearch (a[], n, t)


for i=0 to n-1
if (a[i]=t) then
return i
next i
return -1

❖ C++ Implementation of Sequential Search Algorithm:

int sequentialSearch(int *a, int n, int t)


{
int i;
for (i = 0; i < n; i++)
if (a[i]==t) return i;
return (-1);
}

NSJ ONLINE ACADEMY 41


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

❖ Binary Search:

This algorithm finds the middle item of a sorted array (in ascending
ordered array), compare it against
the searched value, then decide which half of the list must contain the
searched value, and repeat
with that half.

NSJ ONLINE ACADEMY 42


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

NSJ ONLINE ACADEMY 43


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

Our Data Structure and Algorithms Sessions on Youtube

❖ Links

Introduction
https://youtu.be/JelOeHEG-WQ

Array Data Structure


https://youtu.be/QC6WOtm30lc

Linked List Data Structure


https://youtu.be/M-NmNOhA4NY

Stack Data Structure


https://youtu.be/PlmBg-v1ics

Queue Data Structure


https://youtu.be/KO2ehsa_XdY

Tree Data Structure


https://youtu.be/yCqvMq9SVko

Sorting Algorithms
https://youtu.be/G9fdmP-5sXM

Searching Algorithms
https://youtu.be/gJr9Im2sDF4

Do you have any question contact us on whatsapp 0703713832

NSJ ONLINE ACADEMY 44


DATA STRUCTURE AND ALGORITHMS SHORT NOTE

Subscribe Our Youtube Channel


https://www.youtube.com/channel/UCwuUSSB4T3mKD_pZdpC91cw/featured

NSJ ONLINE ACADEMY 45

You might also like