SlideShare a Scribd company logo
Chapter-2
INTRODUCTION TO ALGORITHMS
Preliminaries
MRS.SOWMYA JYOTHI, SDMCBM, MANGALORE
Reference: Data Structures with C by Seymour
Lipschutz, Schaumโ€™s Outlines Series.
INTRODUCTION
โ€ข Study of data structures includes development of algorithms for
creation and processing of data structures.
โ€ข An algorithm may be complex.
โ€ข The computer programs implementing the more complex data
structures can be easily understood if the programs are organized into
hierarchies of modules.
โ€ข In such an organization, each program contains first, a main module
which in turn refers to one or more sub-modules.
ALGORITHMIC NOTATIONS
A well-defined computational procedure is the one that takes some
value, or a set of values, as input and produces some value, or a set of
values, as output.
It can also be defined as sequence of computational steps that transform
the input into the output.
Identifying number: Each algorithm is assigned an identifying number.
For example, Algorithm 1.3
โ€ข Steps, Control Exit: The steps of the algorithm are executed one after
the other, beginning with step 1. Control may be transferred to step n
of the algorithm by the statement โ€œgo step nโ€. The algorithm is
completed when the statement โ€œExitโ€ is encountered.
โ€ข Comments: Each step may contain a comment in brackets which
indicates the main purpose of the step. The comment will usually
appear at the beginning or the end of the step.
โ€ข Variable Names: Variable names will use capital letters, as in MAX
and DATA. Single letter names of variables used as counters or
subscripts will also be capitalized in the algorithms (K and N for
example). Lowercase may be used for these same variables.
โ€ข Assignment Statements: assignment statements will use the dots-equal
notation :=
For example,
K := 5
MAX :=DATA[1]
โ€ข Input and Output: data may be input and assigned to variables by means
of a Read statement with the following form:
Read: variables names.
โ€ข Similarly, messages placed in quotation marks, and data in variables may
be output by means of a Write or Print statement with the following
form:
Write: Messages and/or variable names.
โ€ข Procedures: Procedures will be used for an independent algorithmic
module which solves a particular problem. It is used to write sub
algorithms.
Example:
Algorithm 1.3
โ€ข (Largest Element in Array) A nonempty array DATA with N numerical values
is given. This algorithm finds the location LOC and the value MAX of the
largest element of DATA. The variable K is used as a counter.
Step 1. [Initialize] Set K:=1, LOC:=1 and MAX:=DATA[1]
Step 2. [Increment counter] Set K:=K+1
Step 3. [Test counter] If K>N, then:
Write: LOC, MAX and Exit.
Step 4. [Compare and update] If MAX<DATA[K], then:
Set LOC:=K and MAX:=DATA[K]
Step 5. [Repeat loop] Go to Step 2
CONTROL STRUCTURES
โ€ข Algorithms and their equivalent computer programs are
more easily understood if they mainly use self-contained
modules and three types of logic, or flow of control, called
1. Sequence logic, or sequential flow
2. Selection logic, or conditional flow
3. Iteration logic, or repetitive flow.
1. Sequence logic (Sequential Flow):
โ€ข The modules are executed in the sequence i.e. by the order in which the
modules are written.
2. Selection logic (Conditional Flow):
โ€ข It employs a number of conditions which lead to a selection
of one out of several alternative modules. The structures
which implement this logic are called conditional structures
or If structures. For clarity, the end of such a structure will be
indicated by the statement [End of If structure].
These conditional structures fall into three types:
a) Single alternative: This structure has the form
If condition, then:
[module A]
[End of If structure]
1. Single Alternative:
The logic of this structure is pictured here.
โ— If the condition holds, then Module A,
which may consist of one or more
statements, is executed;
โ— Otherwise Module A is skipped and
control transfers to the next step of
the algorithm
2. Double Alternative:
The logic of this structure is:
This structure has the form:
If (Condition), then:
[Module A]
Else:
[Module B]
[End if structure]
As indicated by the flowchart, if the condition holds, then Module A is executed; otherwise Module B is executed.
3. Multiple Alternatives:
โ— The logic of this structure
allows only one of the modules will
be executed.
โ— If condition 1 is true then module A1
will be executed. Otherwise condition
2 will be checked. If condition 2 is true
then module A2 will be executed. And
so on. If none of the conditions is true
then module B will be executed.
3) Multiple Alternative: This structure has the form
If condition(1), then:
[module A]
Else if condition(2), then:
[module B]
.....
Else if condition(M), then:
[module M]
Else:
[module N]
[End of If structure]
Iteration Logic (Repetitive Flow):
โ€ข The third kind of logic refers to either of two types of structures involving
loops.
โ€ข Each type begins with a repeat statement and is followed by a module,
called the body of the loop.
โ€ข For clarity, we will indicate the end of the structure by the statement
[End of loop]
Iteration Logic (Repetitive Flow)
The Iteration logic employs
a loop which involves a
repeat statement followed
by a module known as the
body of a loop.
The two types of these structures are:
1. Repeat- For structure
2. Repeat-While structure
Repeat-For Structure
This structure has the form:
Repeat for i = A to N by I:
[Module]
[End of loop]
Here, A is the initial value, N is the end value
and I is the increment. The loop ends when
A>B. K increases or decreases according to
the positive and negative value of I
respectively.
โ€ข The repeat-for-loop uses an index variable such as, K to control the
loop.
The loop will usually have the form:
Repeat for K=R to S by T:
[Module]
[End of loop]
The cycling begins with K=R , then with K=R+T and so on and ends
when K>S.
If T is negative, K decreases in value, then the cycling ends when K<S.
โ€ข The repeat-while-loop uses condition to control the loop. The loop
will usually have the form:
Repeat while condition:
[Module]
[End of loop]
โ€ข The cycling continues until the condition is false.
โ€ข We emphasize that there must be a statement before the structure
that initializes the condition controlling the loop, and in order that the
looping may eventually cease, there must be a statement in the body
of the loop that changes the condition.
Repeat-While Structure
It also uses a condition to control the
loop. This structure has the form:
Repeat while condition:
[Module]
[End of Loop]
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI

More Related Content

What's hot

Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
ย 
Interrupts
InterruptsInterrupts
Interrupts
Albin Panakkal
ย 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
ย 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
Kuppusamy P
ย 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P
ย 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
Kamal Acharya
ย 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
Sayantan Sur
ย 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
Gaurav Subham
ย 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
ย 
Conversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with StackConversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with Stack
sahil kumar
ย 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
Maruf Abdullah (Rion)
ย 
C++ Data Structure PPT.ppt
C++ Data Structure PPT.pptC++ Data Structure PPT.ppt
C++ Data Structure PPT.ppt
Mukesh Thakur
ย 
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
ย 
Data Structures Chapter-4
Data Structures Chapter-4Data Structures Chapter-4
Data Structures Chapter-4
priyavanimurugarajan
ย 
Restoring & Non-Restoring Division Algorithm By Sania Nisar
Restoring & Non-Restoring Division Algorithm By Sania NisarRestoring & Non-Restoring Division Algorithm By Sania Nisar
Restoring & Non-Restoring Division Algorithm By Sania Nisar
Sania Nisar
ย 
Data Structure
Data StructureData Structure
Data Structure
Karthikeyan A K
ย 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisation
Muzamil Hussain
ย 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
DivyeshKumar Jagatiya
ย 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
ย 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
sangrampatil81
ย 

What's hot (20)

Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
ย 
Interrupts
InterruptsInterrupts
Interrupts
ย 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
ย 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
ย 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
ย 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
ย 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
ย 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
ย 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
ย 
Conversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with StackConversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with Stack
ย 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
ย 
C++ Data Structure PPT.ppt
C++ Data Structure PPT.pptC++ Data Structure PPT.ppt
C++ Data Structure PPT.ppt
ย 
Applications of stack
Applications of stackApplications of stack
Applications of stack
ย 
Data Structures Chapter-4
Data Structures Chapter-4Data Structures Chapter-4
Data Structures Chapter-4
ย 
Restoring & Non-Restoring Division Algorithm By Sania Nisar
Restoring & Non-Restoring Division Algorithm By Sania NisarRestoring & Non-Restoring Division Algorithm By Sania Nisar
Restoring & Non-Restoring Division Algorithm By Sania Nisar
ย 
Data Structure
Data StructureData Structure
Data Structure
ย 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisation
ย 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
ย 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
ย 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
ย 

Similar to BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI

Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
Information Technology Center
ย 
Control engineering module 3 part-A
Control engineering  module 3 part-AControl engineering  module 3 part-A
Control engineering module 3 part-A
Mohammed Imran
ย 
493 297
493 297493 297
493 297
SanelLeric
ย 
GE8151 notes pdf.pdf
GE8151 notes pdf.pdfGE8151 notes pdf.pdf
GE8151 notes pdf.pdf
payalkarmarkar1
ย 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
Koteswari Kasireddy
ย 
Data structure
Data structureData structure
Data structure
Muhammad Farhan
ย 
Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1
Blue Elephant Consulting
ย 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
jinalgoti
ย 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
Hamad Odhabi
ย 
COMPUTER PROGRAMMING UNIT 1 Lecture 4
COMPUTER PROGRAMMING UNIT 1 Lecture 4COMPUTER PROGRAMMING UNIT 1 Lecture 4
COMPUTER PROGRAMMING UNIT 1 Lecture 4
Vishal Patil
ย 
Lecture_03_EEE 363_Control System.pptx
Lecture_03_EEE 363_Control System.pptxLecture_03_EEE 363_Control System.pptx
Lecture_03_EEE 363_Control System.pptx
TasnimAhmad14
ย 
Simulink 1.pdf
Simulink 1.pdfSimulink 1.pdf
Simulink 1.pdf
ssuser1dfd371
ย 
Modern control system
Modern control systemModern control system
Modern control system
Pourya Parsa
ย 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
ShaswatSurya
ย 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
yasir_cesc
ย 
Lab03
Lab03Lab03
Lab03
Ibrahim Badway
ย 
Lecture_control_system.pptx
Lecture_control_system.pptxLecture_control_system.pptx
Lecture_control_system.pptx
robomango
ย 
ME416A_Module 1.pdf
ME416A_Module 1.pdfME416A_Module 1.pdf
ME416A_Module 1.pdf
MECHANICALENGINEERIN55
ย 
solver (1)
solver (1)solver (1)
solver (1)
Raj Mitra
ย 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
ssusere004a8
ย 

Similar to BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI (20)

Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
ย 
Control engineering module 3 part-A
Control engineering  module 3 part-AControl engineering  module 3 part-A
Control engineering module 3 part-A
ย 
493 297
493 297493 297
493 297
ย 
GE8151 notes pdf.pdf
GE8151 notes pdf.pdfGE8151 notes pdf.pdf
GE8151 notes pdf.pdf
ย 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
ย 
Data structure
Data structureData structure
Data structure
ย 
Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1
ย 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
ย 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
ย 
COMPUTER PROGRAMMING UNIT 1 Lecture 4
COMPUTER PROGRAMMING UNIT 1 Lecture 4COMPUTER PROGRAMMING UNIT 1 Lecture 4
COMPUTER PROGRAMMING UNIT 1 Lecture 4
ย 
Lecture_03_EEE 363_Control System.pptx
Lecture_03_EEE 363_Control System.pptxLecture_03_EEE 363_Control System.pptx
Lecture_03_EEE 363_Control System.pptx
ย 
Simulink 1.pdf
Simulink 1.pdfSimulink 1.pdf
Simulink 1.pdf
ย 
Modern control system
Modern control systemModern control system
Modern control system
ย 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
ย 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
ย 
Lab03
Lab03Lab03
Lab03
ย 
Lecture_control_system.pptx
Lecture_control_system.pptxLecture_control_system.pptx
Lecture_control_system.pptx
ย 
ME416A_Module 1.pdf
ME416A_Module 1.pdfME416A_Module 1.pdf
ME416A_Module 1.pdf
ย 
solver (1)
solver (1)solver (1)
solver (1)
ย 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
ย 

More from Sowmya Jyothi

Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
ย 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
ย 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
ย 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Sowmya Jyothi
ย 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
ย 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
ย 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
ย 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
ย 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
Sowmya Jyothi
ย 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
Sowmya Jyothi
ย 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
ย 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
ย 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
ย 
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHINETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
Sowmya Jyothi
ย 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
Sowmya Jyothi
ย 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
Sowmya Jyothi
ย 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPT
Sowmya Jyothi
ย 
Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya Jyothi
Sowmya Jyothi
ย 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
Sowmya Jyothi
ย 
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel  Chapter 2 Mrs.Sowmya JyothiIntroduction to the Kernel  Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Sowmya Jyothi
ย 

More from Sowmya Jyothi (20)

Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
ย 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
ย 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
ย 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
ย 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
ย 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
ย 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
ย 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
ย 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
ย 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
ย 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
ย 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
ย 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
ย 
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHINETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
ย 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
ย 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
ย 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPT
ย 
Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya Jyothi
ย 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
ย 
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel  Chapter 2 Mrs.Sowmya JyothiIntroduction to the Kernel  Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
ย 

Recently uploaded

Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
ย 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
ย 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
ย 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
ย 
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
ย 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
ย 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
ย 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
ย 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
ย 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
ย 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
ย 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
ย 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
ย 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
ย 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
ย 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
ย 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
ย 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
ย 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
ย 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
ย 

Recently uploaded (20)

Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
ย 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ย 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
ย 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
ย 
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
ย 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
ย 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
ย 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
ย 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
ย 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
ย 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
ย 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
ย 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
ย 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
ย 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
ย 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
ย 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
ย 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
ย 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
ย 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
ย 

BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI

  • 1. Chapter-2 INTRODUCTION TO ALGORITHMS Preliminaries MRS.SOWMYA JYOTHI, SDMCBM, MANGALORE Reference: Data Structures with C by Seymour Lipschutz, Schaumโ€™s Outlines Series.
  • 2. INTRODUCTION โ€ข Study of data structures includes development of algorithms for creation and processing of data structures. โ€ข An algorithm may be complex. โ€ข The computer programs implementing the more complex data structures can be easily understood if the programs are organized into hierarchies of modules. โ€ข In such an organization, each program contains first, a main module which in turn refers to one or more sub-modules.
  • 3.
  • 4. ALGORITHMIC NOTATIONS A well-defined computational procedure is the one that takes some value, or a set of values, as input and produces some value, or a set of values, as output. It can also be defined as sequence of computational steps that transform the input into the output.
  • 5. Identifying number: Each algorithm is assigned an identifying number. For example, Algorithm 1.3 โ€ข Steps, Control Exit: The steps of the algorithm are executed one after the other, beginning with step 1. Control may be transferred to step n of the algorithm by the statement โ€œgo step nโ€. The algorithm is completed when the statement โ€œExitโ€ is encountered. โ€ข Comments: Each step may contain a comment in brackets which indicates the main purpose of the step. The comment will usually appear at the beginning or the end of the step. โ€ข Variable Names: Variable names will use capital letters, as in MAX and DATA. Single letter names of variables used as counters or subscripts will also be capitalized in the algorithms (K and N for example). Lowercase may be used for these same variables.
  • 6. โ€ข Assignment Statements: assignment statements will use the dots-equal notation := For example, K := 5 MAX :=DATA[1] โ€ข Input and Output: data may be input and assigned to variables by means of a Read statement with the following form: Read: variables names. โ€ข Similarly, messages placed in quotation marks, and data in variables may be output by means of a Write or Print statement with the following form: Write: Messages and/or variable names. โ€ข Procedures: Procedures will be used for an independent algorithmic module which solves a particular problem. It is used to write sub algorithms.
  • 7. Example: Algorithm 1.3 โ€ข (Largest Element in Array) A nonempty array DATA with N numerical values is given. This algorithm finds the location LOC and the value MAX of the largest element of DATA. The variable K is used as a counter. Step 1. [Initialize] Set K:=1, LOC:=1 and MAX:=DATA[1] Step 2. [Increment counter] Set K:=K+1 Step 3. [Test counter] If K>N, then: Write: LOC, MAX and Exit. Step 4. [Compare and update] If MAX<DATA[K], then: Set LOC:=K and MAX:=DATA[K] Step 5. [Repeat loop] Go to Step 2
  • 8. CONTROL STRUCTURES โ€ข Algorithms and their equivalent computer programs are more easily understood if they mainly use self-contained modules and three types of logic, or flow of control, called 1. Sequence logic, or sequential flow 2. Selection logic, or conditional flow 3. Iteration logic, or repetitive flow.
  • 9. 1. Sequence logic (Sequential Flow): โ€ข The modules are executed in the sequence i.e. by the order in which the modules are written.
  • 10. 2. Selection logic (Conditional Flow): โ€ข It employs a number of conditions which lead to a selection of one out of several alternative modules. The structures which implement this logic are called conditional structures or If structures. For clarity, the end of such a structure will be indicated by the statement [End of If structure]. These conditional structures fall into three types: a) Single alternative: This structure has the form If condition, then: [module A] [End of If structure]
  • 11. 1. Single Alternative: The logic of this structure is pictured here. โ— If the condition holds, then Module A, which may consist of one or more statements, is executed; โ— Otherwise Module A is skipped and control transfers to the next step of the algorithm
  • 12. 2. Double Alternative: The logic of this structure is: This structure has the form: If (Condition), then: [Module A] Else: [Module B] [End if structure] As indicated by the flowchart, if the condition holds, then Module A is executed; otherwise Module B is executed.
  • 13. 3. Multiple Alternatives: โ— The logic of this structure allows only one of the modules will be executed. โ— If condition 1 is true then module A1 will be executed. Otherwise condition 2 will be checked. If condition 2 is true then module A2 will be executed. And so on. If none of the conditions is true then module B will be executed.
  • 14. 3) Multiple Alternative: This structure has the form If condition(1), then: [module A] Else if condition(2), then: [module B] ..... Else if condition(M), then: [module M] Else: [module N] [End of If structure]
  • 15.
  • 16.
  • 17.
  • 18. Iteration Logic (Repetitive Flow): โ€ข The third kind of logic refers to either of two types of structures involving loops. โ€ข Each type begins with a repeat statement and is followed by a module, called the body of the loop. โ€ข For clarity, we will indicate the end of the structure by the statement [End of loop]
  • 19. Iteration Logic (Repetitive Flow) The Iteration logic employs a loop which involves a repeat statement followed by a module known as the body of a loop. The two types of these structures are: 1. Repeat- For structure 2. Repeat-While structure Repeat-For Structure This structure has the form: Repeat for i = A to N by I: [Module] [End of loop] Here, A is the initial value, N is the end value and I is the increment. The loop ends when A>B. K increases or decreases according to the positive and negative value of I respectively.
  • 20. โ€ข The repeat-for-loop uses an index variable such as, K to control the loop. The loop will usually have the form: Repeat for K=R to S by T: [Module] [End of loop] The cycling begins with K=R , then with K=R+T and so on and ends when K>S. If T is negative, K decreases in value, then the cycling ends when K<S.
  • 21.
  • 22. โ€ข The repeat-while-loop uses condition to control the loop. The loop will usually have the form: Repeat while condition: [Module] [End of loop] โ€ข The cycling continues until the condition is false. โ€ข We emphasize that there must be a statement before the structure that initializes the condition controlling the loop, and in order that the looping may eventually cease, there must be a statement in the body of the loop that changes the condition.
  • 23. Repeat-While Structure It also uses a condition to control the loop. This structure has the form: Repeat while condition: [Module] [End of Loop]