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

Introduction and Performance Analysis

The document provides information about the Data Structure and Algorithm course for the third semester of B.Tech. It discusses the introduction to data structures and algorithms, including definitions, need for data structures, types of data structures, and characteristics of algorithms.

Uploaded by

Pratham Agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Introduction and Performance Analysis

The document provides information about the Data Structure and Algorithm course for the third semester of B.Tech. It discusses the introduction to data structures and algorithms, including definitions, need for data structures, types of data structures, and characteristics of algorithms.

Uploaded by

Pratham Agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

B.

TECH III SEM CSE


ACADEMIC YEAR: 2022-2023

Course Name: Data Structure and Algorithm


Topic: Introduction

Course code : CS 2103


Credits : 4
Mode of delivery : Hybrid (Power point presentation)
Faculty : Mr. Satpal Singh Kushwaha
Email-id : [email protected]
Assignment
quiz
Mid term examination
Assessment criteria’s
End term Examination
Introduction
to
Data Structure & Algorithm

3
INTRODUCTION

•DATA SRUCTURE
• Data: Raw facts about an objects.

• Structure: Way of storing , organising and manipulating data.

• Information: Organized and structured data.


Why are we studying Data Structures ?
Modern world all about … DATA
Dealing with data…
• How to use it ?
• How to store it ?
• How to process it ?
• How to gain “knowledge” from it ?
• How to keep it secret?
Dealing with data…
• How to use it ?
• How to store it ?
• How to process it ?
• How to gain “knowledge” from it ?
• How to keep it secret?
How should data be stored?
Depends on your requirement
Data is diverse ..
But we have some building blocks
To store our big data
Data Structure can be defined as the group of data elements which provides an efficient
way of storing and organizing data in the computer so that it can be used efficiently.
Elementary Data “Structures”
head
• Arrays
• Stacks 1
2
• Queues 4
3
• Linked Lists 7 8
5 6
• Trees
• Graph
F R

14
Need of Data Structure
• As applications are getting complexed and amount of data is increasing day by

day, there may arise the following problems:

✓ Processor speed: To handle very large amount of data, high speed processing is

required, but as the data is growing day by day to the billions of files per entity,

processor may fail to deal with that much amount of data.

✓ Data Search: Consider an inventory size of 106 items in a store, If our application

needs to search for a particular item, it needs to traverse 106 items every time,

results in slowing down the search process.

✓ Multiple requests: If thousands of users are searching the data simultaneously on a

web server, then there are the chances that a very large server can be failed during

that process
DEFINITION OF DATA STRUCTURE:

• Logical (or) Mathematical model of a particular organisation of data.


❖How the data should be organised.

❖How the flow of data should be controlled.

❖How a data structure should be designed.

A data structure is a particular way of storing and organizing data in a computer so


that it can be used efficiently
Why Data Should Be Organized?

• Suitable representation: Data should be stored in such a


manner that it represents the various components of the problem.
• Ease of retrieval: The data should be stored in such a manner
that the program can easily access it.
• Operations allowed: The operations needed to be performed on
the data must be allowed by the representation.

Data Structures
Factors Affecting Performance of a
Program

• Choice of right data structures for the given problem.


• Design of a suitable algorithm to work upon the chosen data
structures.

Data Structures
Choice of Data Structure

• Build in data structure can be used such as arrays, structures,


unions, files and pointers.
• New data structure can be created.

Data Structures
Example

• Let us consider a situation where it is required to create a merit list


of 60 students. These students appeared in a class examination.
The data of a student consists of his name, roll number, marks,
percentage, and grade.

Contd…

Data Structures
Choice 1

Parallel List of Student Data

Data Structures
Choice 1

• An equivalent declaration for data structure of figure is given


below:
char nameList[60][15];
int roll[60];
int marks[60];
float percent[60];
char grade[60];

Contd…

Data Structures
Choice 2

• From the built-in data structures, the struct can be selected to


represent the data of a student as shown below:
struct student
{
char name[15];
int roll;
int marks;
float percent;
char grade;
};

Data Structures
Types of Data Structures

• Linear data structures

• Non-linear data structures

Data Structures
Linear Data Structures

• These data structures represent a sequence of items. The elements


follow a linear ordering.

Linear Data Structures


Data Structures
Properties of Linear Data Structures

• Each element is `followed by’ at most one other element.

• No two elements are `followed by’ the same element.

Data Structures
Non-linear Data Structures

• These data structures represent objects which are not in sequence


but are distributed in a plane.

Non-linear Data Structures

Data Structures
ALGORITHMS

Definition:
An algorithm consists of a set of explicit and unambiguous, finite steps
when carrying out for a given set of initial condition ,produce
corresponding output and terminate in a finite time.
Characteristics of Algorithm
• Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs
should be clear and must lead to only one meaning.

• Input − An algorithm should have 0 or more well-defined inputs.

• Output − An algorithm should have well-defined outputs and should match the desired output.

• Finiteness − Algorithms must terminate after a finite number of steps.

• Feasibility − Should be feasible with the available resources.

• Independent − An algorithm should have step-by-step directions, which should be independent of any programming
code.
A program MUST be systematically and properly
designed before coding begins. This design process
results in the construction of an ALGORITHM.
Algorithm

• There is no general definition of algorithm accepted.

• But we can say that algorithm is:

i. A step‐by‐step problem‐solving procedure.

ii. A sequence of instruction that tell how to solve a particular problem.

iii. A set of instruction for solving a problem, especially on a computer.

iv. A computable set of steps to achieve a desired result.


Algorithm
• Therefore, we can conclude that:

• Algorithm a step‐by‐step problem-solving process in which a solution is


arrived in a finite amount of time

OR

• An algorithm is a finite list of sequential steps specifying actions that if


performed result in solution of a specific problem.
Algorithm & Logical Thinking
• To develop the algorithm, the programmer needs to ask:

• What data has to be fed into the computer?

• What information do I want to get out of the computer?

• Logic: Planning the processing of the program. It contains the instructions


that cause the input data to be turned into the desired output data.
From Algorithm to Program
• Both are sets of instructions on how to do a task;

• Algorithm:
• Talking to humans, easy to understand
• In plain (English) language

• Program:
• Talking to computer (compiler)
• Can be regarded as a “formal expression” of an algorithm
From Algorithm to Program

PROGRAM
ALGORITHM a set of instructions which
are commands to computers
a sequence of instructions
describing how to do a to perform specific
task (or process) operations on data
Algorithm & Program

Algorithm Program
• A step‐by‐step problem‐solving • A program is a set of instructions
procedure which are commands to computers to
perform specific operations on data.
• A sequence of instruction that tell
how to solve a particular problem.
• Instructions within a program are
• A set of instruction for solving a organized in such a way, when the
problem, especially on a computer. program is run on a computer; it
• A computable set of steps to achieve results in the solution of a problem.
a desired result.
• Written in pseudo code or flowchart. • Written in any programming language
Program Development Life Cycle
i. Problem solving Phases
Consist of problem definition and algorithm design
Phase 1: Problem Definition (Analysis)
Phase 2: Algorithm design

ii. Implementation Phases


Consist of algorithm implementation, program
testing and program maintenance phases.
Phase 3: Algorithm implementation
Phase 4: Program testing
Phase 5: Program maintenance
Algorithm Representation
• An algorithm can be written or described or represented using several tools:
• Pseudo code
Use English‐like phrases to describe the processing process. It is not standardized since every
programmer has his or her own way of planning the algorithm.
• Flowchart
Use standardized symbol to show the steps the computer needs to take to accomplish the
program’s objective. Because flowcharts are cumbersome to revise, they have fallen out of
favor by professional programmers. Pseudo code, on the other hand, has gained increasing
acceptance.
Flowchart Symbol and Description
Name Symbol Description
Lozenge Indicates the starting or ending of flowchart
(start / stop : terminal )
Connector Used to connect break in the flowchart

Parallelelogram Use for input and output operation (data)

Rectangle Indicates any interval operation (process)

Diamond Use for asking questions that can have either


TRUE of FALSE / YES or NO (decision / selection)

Module Sub solution to solve a part of entire problem

Control flow Shows flow direction


Flowchart Logic Structure
Sequence Structure Selection Structure Loop Structure

Yes IF No
(test
statement
condition)
LOOP
THEN ELSE (statement)
(statement) (statement)
statement

DO WHILE Yes
(test
condition)

No

DO WHILE
Design an algorithm to find the area of a rectangle
The formulas: area = length * width

Flowchart Example Input


Input variable:
Process
Processing item:
Output
Output:
length area area
width
Formula:
area = length x width
Start
Step / Solution algorithm:
get input
calculate area
length, width display output

calculate area

area

End
Sequence Example
Flowchart
Simple
Simple Design
Design Modular Design Modular Sub-Module
Design
Start
start Start
Read Read
num1 num2
Return
Read num1,
get_input()
num2
Start

calculate sum calculate_sum()


calculate sum

Return
Print sum display_output()
Start

end End Print sum

Return
Pseudo Code Style
Style 1 Style 2 Style 3 (Modular design)

Problem Problem Problem


1. Start 1. Start 1. Start
2. Task 2. Subproblem 1 2. Subproblem 1
3. Action Task 1,1 3. Subproblem 2
4. End Action 1,1,1 4. End
Action 1,1,2
3. Subproblem 2 2. Subproblem 1
Task 1,2 Task 1,1
Action 1,2,1 Action 1,1,1
Action 1,2,2 Action 1,1,2
4. End
3. Subproblem 2
Task 1,2
Sequence Example
Pseudo Code
Simple Design
Simple Design Modular Design
Modular Design
1. Start 1. Start
2. Get input 2. get_input()
Read num1 3. calculate_sum()
Read num2 4. display_output()
3. Calculate sum 5. End
sum = num1 + num2
4. Display output 2. get_input()
Print sum Read num1
5. End Read num2

3. calculate_sum()
sum = num1 + num2

4. display_output()
Print sum
Why Algorithm is Important?
• Describe the steps needed to perform a computation

• Important for writing efficient code


• Code that execute faster & which uses less memory
Performance Analysis

• An algorithm requires following two resources:


▪ Memory space
▪ CPU time

Data Structures
Big-Oh Notation

• The Big-Oh notation defines that for a large number of input ‘n’,
the growth rate of an algorithm T(n) is of the order of a function ‘g’
of ‘n’ as indicated by the following relation:

T(n) = O(g(n))

Data Structures
Simple Statement

• Let us assume that a statement takes a unit time to execute, i.e.,


1. Thus, T(n) = 1 for a simple statement.
• Therefore, the relation can be expressed as:
T(n) = O(1)

Data Structures
Sequence Structure

• The execution time of sequence structure is equal to the sum of


execution time of individual statements present within the sequence
structure. Let us consider a sequence of statements 1 to 4
• Algorithm AreaTriangle
{ Step
1. Read base, height;
2. Area = 0.5 * base * height;
3. Print Area;
4. Stop
}

Data Structures
Sequence Structure

• The previous algorithm takes four steps to complete. Thus,


T(n) = 4.
• So the time complexity of previous algorithm is O(k) or O(1), i.e.,
of the order 1.

Data Structures
The Loop Structure

• The loop structure iteratively executes statements written within its


bound. If a loop executes for N iterations, it contains only simple
statements
for (J = 1; J <= N; J++)
{
S;
}

T(n) = O(N)

Data Structures
Nested Loop

• In case of nested loops, the time complexity depends upon the


counters of both outer and inner loops.
for (I = 1; I <= N; I++)
{
for (J = 1; J <= N; J++)
{
S;
}
}
T(n) = N2

Data Structures
if-then-else Structure

• In the if-then-else structure,


the ‘then’ and ‘else’ parts
are considered separately.
• The time complexity of ‘if-
then-else’ structure is taken
to be the maximum of the
two, i.e., max(T1(Time
complexity of if part),
T2(Time complexity of else
part)).
Data Structures

You might also like