SlideShare a Scribd company logo
1 of 33
Lecture No.01
Data Structures and
Algorithms
Rabbia mahum, UET Taxila
Grading Theory
 Mid Term 25%
 Final 50%
 Programming Assignments 10%
 Surprise Quiz's 05%
 Project 10%
Grading Lab
 Mid Term 25%
 Final 50%
 Programming Project 20%
 Presentation and viva voca 05%
Acknowledgement
This Lecture has been prepared from your Reference Course Book titled as
“Data Structure” by Schaum Series.
Other source includes tutorialpoint page and google pages
4
What is Data Structures
 Data Structures are the programmatic way of storing data so that
data can be used efficiently.
 Almost every enterprise application uses various types of data
structures in one or the other way.
5
Why to Learn Data Structure and
Algorithms?
 As applications are getting complex and data rich, there are three
common problems that applications face now-a-days.
1. Data Search
2. Processor speed
3. Multiple requests
6
Why to Learn Data Structure and
Algorithms?
 Data Search − Consider an inventory of 1 million(106) items of a
store. If the application is to search an item, it has to search an item
in 1 million(106) items every time slowing down the search. As data
grows, search will become slower.
7
Why to Learn Data Structure and
Algorithms?
 Processor speed − Processor speed although being very high, falls
limited if the data grows to billion records.
 Multiple requests − As thousands of users can search data
simultaneously on a web server, even the fast server fails while
searching the data.
8
Why to Learn Data Structure and
Algorithms?
 To solve these mentioned problems, data structures come to rescue.
 Data can be organized in a data structure in such a way that all items
may not be required to be searched, and the required data can be
searched almost instantly.
9
Data Structure: Foundation terms
 Interface − Each data structure has an interface. Interface represents
the set of operations that a data structure supports. An interface only
provides the list of supported operations, type of parameters they can
accept and return type of these operations.
10
Data Structure: Foundation terms
 Implementation − Implementation provides the internal
representation of a data structure.
 Implementation also provides the definition of the algorithms used in
the operations of the data structure.
11
Characteristics of a Data Structure
1. Correctness − Data structure implementation
should implement its interface correctly.
2. Time Complexity − Running time or the execution
time of operations of data structure must be as
small as possible.
3. Space Complexity − Memory usage of a data
structure operation should be as little as possible.
12
What is an Algorithm?
 The word algorithm comes from the name of a Persian author, Abu Ja’far
Mohammed ibn Musa al Khowarizmi (c. 825 A.O.) who wrote a textbook on
mathematics.
 An examination of the latest edition of Webster's dictionary defines its
meaning as "any special method of solving a certain kind of problem.
13
Definition of “Algorithm”
 An Algorithm, intuitively speaking, is a finite step-by-step list of well
defined instructions for solving a particular problem.
 An algorithm is a clearly specified set of simple instructions to be
followed to solve a problem.
14
Definition of “Algorithm”
 Algorithms are generally created independent of underlying languages,
i.e. an algorithm can be implemented in more than one programming
language.
15
Definition of “Algorithm”
 From the data structure point of view, following
are some important categories of algorithms −
1. Search − Algorithm to search an item in a data
structure.
2. Sort − Algorithm to sort items in a certain order.
3. Insert − Algorithm to insert item in a data structure.
4. Update − Algorithm to update an existing item in a data
structure.
5. Delete − Algorithm to delete an existing item from a
data structure.
16
Properties or Constraints
 For example, each operation must be definite, meaning that it must
be perfectly clear what should be done.
 Directions such as "compute 5/0" or "add 6 or 7 to x" are not permitted
because it is not clear what the result is or which of the two possibilities
should be done.
17
Properties or Constraints
 Another important property each operation should have is that it be
effective; each step must be such that it can, at least in principle, be
done by a person using pencil and paper in a finite amount of time.
 Arithmetic operations on integer is an effective while on some real
numbers its not……
18
Properties or Constraints
 An algorithm produces one or more outputs and may have zero or
more inputs which are externally supplied.
 Another important criterion we will assume about algorithms is that
they terminate after a finite number of operations.
19
Algorithmic Notations
 In coming slides you will learn the format that is used to present
algorithms throughout this course. This is best describes by means of an
example.
 Example: An array DATA of numerical values is in memory. We want to
find the location LOC and the value MAX of the largest element of DATA.
20
Algorithmic Notations
 Initially begin with LOC = 1 and MAX = DATA
[1]. Then compare MAX with each successive
element DATA[K] of DATA.
 If DATA[K] exceeds MAX then update LOC and
MAX so that LOC = K and MAX = DATA [K].
 The final values appearing in LOC and MAX give
the location and value of the largest element
of DATA. 21
Algorithmic Notations: Example Largest
Element in the Array
Algorithm 2.1
Algorithmic Notations: Example Largest
Element in the Array
Flow Chart
Algorithmic Notations: The Solution of the
Quadratic Equation
Algorithmic Notations: The Solution of the
Quadratic Equation
 The quantity D = b2 – 4ac is called the
discriminant of the equation. If D is negative,
then there are no real solutions.
 If D = 0, then there is only one (double) real
solution , x = -b/2a
 If D is positive, the formula gives the two
distinct real solutions.
Algorithmic Notations: The Solution of the
Quadratic Equation
Algorithm 2.3
Algorithmic Notations: Linear Search
 Suppose a linear array DATA contains n elements,
and suppose a specific ITEM of information is given.
We want either to find the location LOC of item in
the array DATA, or to send some message, such as
LOC = 0, to indicate that ITEM is not in the DATA.
 The linear search algorithm solves this problem by
comparing ITEM, one by one, with each element in
DATA. That is we compare ITEM with DATA[1],
DATA[2], and so on, until we find LOC such that ITEM
= DATA [LOC].
Algorithm 2.4
Algorithmic Notations: Linear Search
Algorithm 2.4
Algorithmic Notations: Binary Search
 During each stage of binary search algorithm our search
for ITEM is reduced to a segment of elements of DATA
 The BEG and END denote respectively the beginning and
end location of segment under consideration. Where
BEG = 1 or LB and END = n or UB
 The Algorithm compares ITEM with the middle element
DATA[MID] of segment where MID is obtained by
MID = INT (BEG + END ) /2
Algorithmic Notations: Binary Search
 If DATA [MID] = ITEM then search is successful and we
set LOC = MID, otherwise a new segment of DATA is
obtained as follow
 A) If ITEM < DATA [MID] then ITEM can appear on left
side of segment
 DATA [BEG] , DATA [BEG+1] … DATA[MID -1]
B) If ITEM > DATA [MID] then ITEM can appear in right half of the
segment
 DATA [MID] , DATA [MID+1] … DATA[END]
Algorithmic Notations: Binary Search
• If ITEM is not in DATA then eventually we obtain
END < BEG
• This condition signals that the search is unsuccessful, and in such case we assign LOC =
NULL.
Algorithmic Notations: Binary Search
1 2 3 4 5 6 7 8 9 10 11 12 13
11 22 30 33 40 44 55 60 66 77 80 88 99
Algorithmic Notations: Linear Search
Algorithm 2.4

More Related Content

Similar to Lecture#1(Algorithmic Notations).ppt

Similar to Lecture#1(Algorithmic Notations).ppt (20)

Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Ds
DsDs
Ds
 
Chapter 1 Data structure.pptx
Chapter 1 Data structure.pptxChapter 1 Data structure.pptx
Chapter 1 Data structure.pptx
 
Unit 1 dsa
Unit 1 dsaUnit 1 dsa
Unit 1 dsa
 
8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx
 
Chapter 1- IT.pptx
Chapter 1- IT.pptxChapter 1- IT.pptx
Chapter 1- IT.pptx
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
 
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Lecture1 data structure(introduction)
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
 
Intro_2.ppt
Intro_2.pptIntro_2.ppt
Intro_2.ppt
 
Intro.ppt
Intro.pptIntro.ppt
Intro.ppt
 
Intro.ppt
Intro.pptIntro.ppt
Intro.ppt
 
Bca2020 data structure and algorithm
Bca2020   data structure and algorithmBca2020   data structure and algorithm
Bca2020 data structure and algorithm
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structure
 
Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptx
 

Recently uploaded

Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewingbigorange77
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Personfurqan222004
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of indiaimessage0108
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Lucknow
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 

Recently uploaded (20)

Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewing
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Person
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of india
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 

Lecture#1(Algorithmic Notations).ppt

  • 1. Lecture No.01 Data Structures and Algorithms Rabbia mahum, UET Taxila
  • 2. Grading Theory  Mid Term 25%  Final 50%  Programming Assignments 10%  Surprise Quiz's 05%  Project 10%
  • 3. Grading Lab  Mid Term 25%  Final 50%  Programming Project 20%  Presentation and viva voca 05%
  • 4. Acknowledgement This Lecture has been prepared from your Reference Course Book titled as “Data Structure” by Schaum Series. Other source includes tutorialpoint page and google pages 4
  • 5. What is Data Structures  Data Structures are the programmatic way of storing data so that data can be used efficiently.  Almost every enterprise application uses various types of data structures in one or the other way. 5
  • 6. Why to Learn Data Structure and Algorithms?  As applications are getting complex and data rich, there are three common problems that applications face now-a-days. 1. Data Search 2. Processor speed 3. Multiple requests 6
  • 7. Why to Learn Data Structure and Algorithms?  Data Search − Consider an inventory of 1 million(106) items of a store. If the application is to search an item, it has to search an item in 1 million(106) items every time slowing down the search. As data grows, search will become slower. 7
  • 8. Why to Learn Data Structure and Algorithms?  Processor speed − Processor speed although being very high, falls limited if the data grows to billion records.  Multiple requests − As thousands of users can search data simultaneously on a web server, even the fast server fails while searching the data. 8
  • 9. Why to Learn Data Structure and Algorithms?  To solve these mentioned problems, data structures come to rescue.  Data can be organized in a data structure in such a way that all items may not be required to be searched, and the required data can be searched almost instantly. 9
  • 10. Data Structure: Foundation terms  Interface − Each data structure has an interface. Interface represents the set of operations that a data structure supports. An interface only provides the list of supported operations, type of parameters they can accept and return type of these operations. 10
  • 11. Data Structure: Foundation terms  Implementation − Implementation provides the internal representation of a data structure.  Implementation also provides the definition of the algorithms used in the operations of the data structure. 11
  • 12. Characteristics of a Data Structure 1. Correctness − Data structure implementation should implement its interface correctly. 2. Time Complexity − Running time or the execution time of operations of data structure must be as small as possible. 3. Space Complexity − Memory usage of a data structure operation should be as little as possible. 12
  • 13. What is an Algorithm?  The word algorithm comes from the name of a Persian author, Abu Ja’far Mohammed ibn Musa al Khowarizmi (c. 825 A.O.) who wrote a textbook on mathematics.  An examination of the latest edition of Webster's dictionary defines its meaning as "any special method of solving a certain kind of problem. 13
  • 14. Definition of “Algorithm”  An Algorithm, intuitively speaking, is a finite step-by-step list of well defined instructions for solving a particular problem.  An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. 14
  • 15. Definition of “Algorithm”  Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in more than one programming language. 15
  • 16. Definition of “Algorithm”  From the data structure point of view, following are some important categories of algorithms − 1. Search − Algorithm to search an item in a data structure. 2. Sort − Algorithm to sort items in a certain order. 3. Insert − Algorithm to insert item in a data structure. 4. Update − Algorithm to update an existing item in a data structure. 5. Delete − Algorithm to delete an existing item from a data structure. 16
  • 17. Properties or Constraints  For example, each operation must be definite, meaning that it must be perfectly clear what should be done.  Directions such as "compute 5/0" or "add 6 or 7 to x" are not permitted because it is not clear what the result is or which of the two possibilities should be done. 17
  • 18. Properties or Constraints  Another important property each operation should have is that it be effective; each step must be such that it can, at least in principle, be done by a person using pencil and paper in a finite amount of time.  Arithmetic operations on integer is an effective while on some real numbers its not…… 18
  • 19. Properties or Constraints  An algorithm produces one or more outputs and may have zero or more inputs which are externally supplied.  Another important criterion we will assume about algorithms is that they terminate after a finite number of operations. 19
  • 20. Algorithmic Notations  In coming slides you will learn the format that is used to present algorithms throughout this course. This is best describes by means of an example.  Example: An array DATA of numerical values is in memory. We want to find the location LOC and the value MAX of the largest element of DATA. 20
  • 21. Algorithmic Notations  Initially begin with LOC = 1 and MAX = DATA [1]. Then compare MAX with each successive element DATA[K] of DATA.  If DATA[K] exceeds MAX then update LOC and MAX so that LOC = K and MAX = DATA [K].  The final values appearing in LOC and MAX give the location and value of the largest element of DATA. 21
  • 22. Algorithmic Notations: Example Largest Element in the Array Algorithm 2.1
  • 23. Algorithmic Notations: Example Largest Element in the Array Flow Chart
  • 24. Algorithmic Notations: The Solution of the Quadratic Equation
  • 25. Algorithmic Notations: The Solution of the Quadratic Equation  The quantity D = b2 – 4ac is called the discriminant of the equation. If D is negative, then there are no real solutions.  If D = 0, then there is only one (double) real solution , x = -b/2a  If D is positive, the formula gives the two distinct real solutions.
  • 26. Algorithmic Notations: The Solution of the Quadratic Equation Algorithm 2.3
  • 27. Algorithmic Notations: Linear Search  Suppose a linear array DATA contains n elements, and suppose a specific ITEM of information is given. We want either to find the location LOC of item in the array DATA, or to send some message, such as LOC = 0, to indicate that ITEM is not in the DATA.  The linear search algorithm solves this problem by comparing ITEM, one by one, with each element in DATA. That is we compare ITEM with DATA[1], DATA[2], and so on, until we find LOC such that ITEM = DATA [LOC]. Algorithm 2.4
  • 28. Algorithmic Notations: Linear Search Algorithm 2.4
  • 29. Algorithmic Notations: Binary Search  During each stage of binary search algorithm our search for ITEM is reduced to a segment of elements of DATA  The BEG and END denote respectively the beginning and end location of segment under consideration. Where BEG = 1 or LB and END = n or UB  The Algorithm compares ITEM with the middle element DATA[MID] of segment where MID is obtained by MID = INT (BEG + END ) /2
  • 30. Algorithmic Notations: Binary Search  If DATA [MID] = ITEM then search is successful and we set LOC = MID, otherwise a new segment of DATA is obtained as follow  A) If ITEM < DATA [MID] then ITEM can appear on left side of segment  DATA [BEG] , DATA [BEG+1] … DATA[MID -1] B) If ITEM > DATA [MID] then ITEM can appear in right half of the segment  DATA [MID] , DATA [MID+1] … DATA[END]
  • 31. Algorithmic Notations: Binary Search • If ITEM is not in DATA then eventually we obtain END < BEG • This condition signals that the search is unsuccessful, and in such case we assign LOC = NULL.
  • 32. Algorithmic Notations: Binary Search 1 2 3 4 5 6 7 8 9 10 11 12 13 11 22 30 33 40 44 55 60 66 77 80 88 99
  • 33. Algorithmic Notations: Linear Search Algorithm 2.4