Data Structure and Algorithim
Data Structure and Algorithim
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.
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
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
Best-case
analysis
Worst-case
analysis
Average-case
analysis
Analysis of Algorithms
Best-case
analysis
Worst-case
analysis
activity