Introduction To Data Structure and Algorithm
Introduction To Data Structure and Algorithm
Introduction to
Data Structure and
Algorithm
Mar Riel C. Abuke
I.T Instructor
1
What
Click toare
editData
MasterStructure?
title style
Data structure is a storage that is used to store and organize data. It is a way of
a r r a n g i n g d a t a o n a c o m p u t e r s o t h a t i t c a n b e a c c e s s e d a n d u p d a t e d e f f i c i e n t l y.
Depending on your requirement and project, it is important to choose the right data
structure for your project. For example, if you want to store data sequentially in the
m e m o r y, t h e n y o u c a n g o f o r t h e A r r a y d a t a s t r u c t u r e .
Note: Data structure and data types are slightly different. Data structure is the
collection of data types arranged in a specific order.
2 2
Click to edit
Two Main Master
Types titleStructure
of Data style
6 6
Click to edit
Popular Master
Linear Data title style
Structures
2. Stack Data Structure
In stack data structure, elements are stored in the LIFO principle. That
is, the last element stored in a stack will be removed first.
It works just like a pile of plates where the last plate kept on the pile will
be removed first.
In a stack, operations can be perform only from one end (top here).
7 7
Click to edit
Popular Master
Linear Data title style
Structures
3. Queue Data Structure
Unlike stack, the queue data structure works in the FIFO principle where
first element stored in the queue will be removed first.
It works just like a queue of people in the ticket counter where first
person on the queue will get the ticket first.
In a queue, addition and removal are performed from separate ends.
8 8
Click to edit
Popular Master
Linear Data title style
Structures
4. Linked List Data Structure
In linked list data structure, data elements are connected through a
series of nodes. And, each node contains the data items and address to
the next node.
9 9
Click to edit
Two Main Master
Types titleStructure
of Data style
10
10
Click to editData
Non Linear Master title style
Structures
1. Graph Data Structure
In graph data structure, each node is called vertex and each vertex is
connected to other vertices through edges.
Popular Graph Based Data Structures:
Spanning Tree and Minimum Spanning Tree
Strongly Connected Components
Adjacency Matrix
Adjacency List
11
11
Click to editData
Non Linear Master title style
Structures
2. Trees Data Structure
Similar to a graph, a tree is also a collection of vertices and edges.
However, in tree data structure, there can only be one edge between
two vertices.
Popular Tree based Data Structure
Binary Tree
Binary Search Tree
AVL Tree
B-Tree
B+ Tree
Red-Black Tree 12
12
Click to
Linear Vsedit Master Data
Non-linear title style
Structures
Now that we know about linear and non-linear data structures, let's
see the major differences between them.
Now that we know about linear and non-linear data structures, let's
see the major differences between them.
14
14
Click is
What toan
edit Master title style
Algorithm?
17
17
Click to edit
Algorithm Master title style
Examples:
18
18
Click to edit
Algorithm Master title style
Examples:
19
19
Click to edit
Algorithm Master title style
Examples:
20
20
Click to edit Master title style
Difference between Algorithm, Pseudocode and
Program
Algorithm : Systematic logical approach which is a
well-defined, step-by-step procedure that allows a
computer to solve a problem.
Pseudocode : It is a simpler version of a
programming code in plain English which uses short
phrases to write code for a program before it is
implemented in a specific programming language.
Program : It is exact code written for problem following
all the rules of the programming language.
21
21
Click to edit Master title style
Difference between Algorithm, Pseudocode and
Program
Algorithm:
An algorithm is used to provide a solution to a particular problem
in form of well-defined steps. Whenever you use a computer to
solve a particular problem, the steps which lead to the solution
should be properly communicated to the computer. While
executing an algorithm on a computer, several operations such
as additions and subtractions are combined to perform more
complex mathematical operations. Algorithms can be expressed
using natural language, flowcharts, etc.
22
22
Difference between
Click to edit MasterAlgorithm,
title style Pseudocode and
Program
Algorithm:
Let’s take a look at an example for a better understanding. As a
programmer, we are all aware of the Linear Search program. (Linear
Search)
Algorithm of linear search :
Here, we can see how the steps of a linear search program are explained
in a simple, English language.
23
23
Difference between
Click to edit MasterAlgorithm,
title style Pseudocode and
Program
Pseudocode:
It is one of the methods which can be used to represent an algorithm for a
program. It does not have a specific syntax like any of the programming
languages and thus cannot be executed on a computer. There are several
formats which are used to write pseudo-codes and most of them take down
the structures from languages such as C, Lisp, FORTRAN, etc.
Many time algorithms are presented using pseudocode since they can be
read and understood by programmers who are familiar with different
programming languages. Pseudocode allows you to include several control
structures such as While, If-then-else, Repeat-until, for and case, which is
present in many high-level languages.
Note: Pseudocode is not an actual programming language. 24
24
Difference between
Click to edit MasterAlgorithm,
title style Pseudocode and
Program
Pseudocode:
Pseudocode for Linear Search :
In here, we haven’t used any specific programming language but wrote the steps of a
linear search in a simpler form which can be further modified into a proper program. 25
25
Difference between
Click to edit MasterAlgorithm,
title style Pseudocode and
Program
Program:
A program is a set of instructions for the computer
to follow. The machine can’t read a program
directly, because it only understands machine
code. But you can write stuff in a computer
language, and then a compiler or interpreter can
make it understandable to the computer.
26
26
Difference between
Click to edit MasterAlgorithm,
title style Pseudocode and
Program
Program:
Program for Linear Search :
27
27
Data
ClickStructure & Algorithm
to edit Master in PHP
title style
Implementation
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:
29
29
Use of Data Structures and Algorithms to Make
Click to edit Master title style
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.
30
30
Use of Data Structures and Algorithms to Make
Click to edit Master title style
Your Code Scalable
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?
The number of instructions depends on the code you used, and the
time taken to execute each code depends on your machine and
compiler.
32
32
Click to edit Master title style
End of
Lesson
33