0% found this document useful (0 votes)
15 views

Data Structure and Algorithim

The document provides an overview of data structures and algorithms, detailing various types of data structures such as arrays, stacks, queues, linked lists, graphs, and trees, along with their characteristics and use cases. It also outlines the criteria for effective algorithms and methods for representing them, including pseudocode and flowcharts. Additionally, it discusses the analysis of algorithms based on best-case, worst-case, and average-case scenarios.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Data Structure and Algorithim

The document provides an overview of data structures and algorithms, detailing various types of data structures such as arrays, stacks, queues, linked lists, graphs, and trees, along with their characteristics and use cases. It also outlines the criteria for effective algorithms and methods for representing them, including pseudocode and flowcharts. Additionally, it discusses the analysis of algorithms based on best-case, worst-case, and average-case scenarios.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Data Structure and Algorithim

Data Structure and


Algorithim
CC 104
Data Structure:
Data structure is a
storage that is used to
store and organize
data. It is a way of
arranging data on a
computer so that it
can be accessed and
updated efficiently.
Arrays

Linked Lists
Types of Data
Structures
Stacks
Linear Data
Structures
Queues
Linear data structures
In linear data structures, the elements are arranged
in sequence one after the other. Since elements are
arranged in particular order, they are easy to
implement.

However, when the complexity of the program


increases, the linear data structures might not be
the best choice because of operational
complexities.
Array
In an array, elements in memory are
arranged in continuous memory. All the
elements of an array are of the same
type. And, the type of elements that can
be stored in the form of arrays is
determined by the programming
language.
Array
Stack
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).
Stack
Stack
perfect for supporting
undo/redo in text
editors or maintaining
history for web
browser
Queue
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.
Queue
Queue
sample; chat
applications and
printer jobs
Linked List
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.
Linked List
Sample usage is task
management, social
media feeds and
shopping carts
Graph
Types of Data
Structures
non Linear
Data Trees
Structures
Non linear data structures
Unlike linear data structures,
elements in non-linear data
structures are not in any sequence.
Instead they are arranged in a
hierarchical manner where one
element will be connected to one or
more elements.
Non-linear data structures are further
divided into graph and tree based
data structures.
Graph
In graph data structure, each node is
called vertex and each vertex is
connected to other vertices through
edges.
Trees
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.
Linear Vs Non-linear
Data Structures
Linear Data Structures Non Linear Data Structures

The data items are The data items are


arranged in arranged in non-
sequential order, one sequential order
after the other. (hierarchical manner).
Linear Vs Non-linear
Data Structures
Linear Data Structures Non Linear Data Structures

All the items are The data items are


present on the single present at different
layer. layers.
Linear Vs Non-linear
Data Structures
Linear Data Structures Non Linear Data Structures

It can be traversed on a It requires multiple runs.


single run. That is, if we That is, if we start from the
start from the first element, first element it might not
we can traverse all the be possible to traverse all
elements sequentially in a the elements in a single
single pass. pass.
Linear Vs Non-linear
Data Structures
Linear Data Structures Non Linear Data Structures

Different structures
The memory utilization utilize memory in
is not efficient. different efficient ways
depending on the need.
Linear Vs Non-linear
Data Structures
Linear Data Structures Non Linear Data Structures

The time complexity


Time complexity
increase with the data
remains the same.
size.
Data Types
data that a variable
can hold in a
programming language
all programming
language has a set of
built-in data types
Primitive Data Types
Integer
Float
Character
Boolean
byte
short
long
double
Integer
int
Stores whole
numbers from
-2,147,483,648 to
2,147,483,647
float
float
Stores fractional
numbers. Sufficient
for storing 6 to 7
decimal digits
Character
char
Stores a single
character/letter or
ASCII values
boolean
boolean
Stores true or false
values
byte
byte
Stores whole
numbers from -128
to 127
short
short
Stores whole
numbers from
-32,768 to 32,767
long
long
Stores whole
numbers from
-9,223,372,036,854,7
75,808 to
9,223,372,036,854,77
5,807
double
double
Stores fractional
numbers.
Sufficient for
storing 15 to 16
decimal digits
Abstract Data
Types
Abstract Data Types
specification of a set of
data and set of operations
performed in a data
storage for data defined
in terms of set of
operations to be
performed on the data
Abstract Data Types
(ADT)
Stacks
Queues
Lists
Deques
Priority Queues
Algorithms
Algorithms
step-by-step procedures for
solving a problem or performing a
computation
finite set of instructions that
specify a sequence of operations to
be carried out
recipe for solving a problem
all the tasks that can be carried
out by a computer can be
stated as algorithms
Criteria for Algorithm
Every algorithm must satisfy the
following criteria:

1. Input
zero or more quantities
are externally supplied
Accepts input values.
Criteria for Algorithm

2. Output - at
least one quantity
is produced
-Produces results.
Criteria for Algorithm
3. Definiteness -
each instruction
must be clear and
unambiguous
-Clearly defined steps.
Criteria for Algorithm
4. Finiteness - all
instructions of an
algorithm will terminate
after a finite number
of steps
-Finishes within a finite
time.
Criteria for Algorithm
5. Effectiveness -
each operation
must be definite,
but must also be
feasible
Criteria for Algorithm
5. Effectiveness -
each operation must
be definite, but must
also be feasible
-Solves all instances
of the problem.
Criteria for Algorithm
1. Inputs are the data items
presented to the algorithm. An
algorithm has either no input or
a predetermined number of
them.
2. Output are the data items
presented to the outside world
as the result of the execution
of a program based on the
algorithm.
Representing Algorithms
Procedure
essential tool in programming
that generalizes the notion of an
operator
Procedure can be used to
encapsulate parts of an algorithm
by localizing in one section of a
program all the statements
relevant to a certain aspect of a
program.
Representing Algorithms
Procedure
essential tool in programming
that generalizes the notion of an
operator
Procedure can be used to
encapsulate parts of an algorithm
by localizing in one section of a
program all the statements
relevant to a certain aspect of a
program.
Representing Algorithms
Procedure
Algorithms can be represented as:
Pseudocode: A high-level
description resembling code.
Flowcharts: Diagrams to illustrate
steps.
Stepwise Refinement: Breaking
down into smaller, more
manageable steps.
PSEUDOCODE
PSEUDOCODE
textual presentation of a
flowchart
close to a natural language
the control structures impose
the logic
may become part of the
program documentation
could be translated into a
program
Key Features of Pseudocode
1. Readable: Written in simple
English-like statements.
2. Abstract: Focuses on the logic
and flow of the algorithm.
3. Language-Independent: Can
be implemented in any
programming language later.
4. Clear and Concise: Avoids
excessive detail.
Basic Syntax of Pseudocode
Use keywords like START,
END, IF, WHILE, FOR, etc.
Indent for clarity in control
structures.
Example conventions:
Input: INPUT or READ
Output: PRINT or DISPLAY
Structure of Pseudocode
a. Start and End
Use START and END to define
the beginning and end of the
pseudocode.
b. Input and Output
For input: Use INPUT or READ.
For output: Use PRINT,
DISPLAY, or OUTPUT.
Structure of Pseudocode
c. Variables and Assignment
Use = for assignment.
Example: SET sum = 0
d. Conditional Statements
Use IF...THEN...ELSE for
decision-making.
Structure of Pseudocode
e. Loops
Use FOR, WHILE, or
REPEAT...UNTIL for loops.
FOR Loop:
Common Keywords in Pseudocode
Keyword Purpose

START, END Marks the beginning and end.

INPUT, READ Takes user input.

PRINT, OUTPUT, DISPLAY Outputs information.

IF, ELSE, ENDIF Conditional logic.

FOR, WHILE, REPEAT, UNTIL Loops for repetition.

SET Assigns a value to a variable.

RETURN Outputs a result from a function.

CALL Invokes a procedure or function


example
STEPWISE REFINEMENT
The process by which a
programmer refines an
initial idea to a
problem's solution into
more specific terms.
The last phase of
refinement results in a
program ready to be
coded for execution.
Analysis of Algorithms

Best-case
analysis
Worst-case
analysis
Average-case
analysis
Analysis of Algorithms

Best-case
analysis
Worst-case
analysis
activity

Create an algorithm for


washing the dishes.
Create an algorithm for
your enrolment in
AITE.

You might also like