SlideShare a Scribd company logo
Created By Zaheer Abbas Aghani
Data Structure (ITC-322) Lecture 2 Algorithms
Algorithms (Definition) An Algorithm (pronounced AL-go-rith-um) is a  se quence  of instructions specifying the steps required to accomplish some task. OR An algorithm is a finite step by step list of well defined instruction for solving a particular problem.
Algorithm  -- Examples A cooking recipe. The rules of how to play a game. VCR instructions. Directions for driving from A to B. A car repair manual.
Computer Algorithms A computer program is another example of an algorithm. To make a computer do anything, you have to write a computer program. To write a computer program you have to tell the computer step by step, exactly what you want to do.  The computer then executes the program following each step to accomplish the end goal. When you telling the computer what to do, you also get to choose how it’s going to do it. That’s where computer algorithms come in.
From Algorithms to Programs Problem C  Program Algorithm :  A sequence of instructions describing how to do a task (or process)
Examples: Suppose Add two number a & b and store in c. Steps: Step1: Initialize variable a and b [a=1, b=1] Step2: Declare variable c. Steps3: Add variables and store in other variable [ c= a+b]. Steps4:Print output [c].
Implement of Algorithm in C Void main() { int a,b,c;  //declaration of variables a=1,b=1; //initialize variable a and b c=a+b; // add a and b and store result in c printf(“%d”,&c); // print output }
Example:-  Algorithm:  Drive_To_Uni Steps  { 1. find car keys 2. disable car alarm 3. open car door 4. get in car 5. shut car door 6. put keys in ignition 7. start car 8. back car out of    driveway 9. drive to end of street 10. turn right 11. drive to end of street 12. turn left ...etc...etc...etc ...etc...etc...etc... 52. find parking space 53. pull into parking    space 54. turn off engine 55. remove keys from    ignition 56. open car door 57. get out 58. shut car door 59. lock car door 60. enable alarm }
Controls Structures A control structure or logic structure is a structure that controls the logical sequences in which programs instructions are executed. OR Control flow   or Control structures refers to the order in which the individual statements, instructions, are executed. Algorithms and their equivalent computer programs are more easily understood if they mainly use these types of control structures. An algorithm or computer program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. In algorithm design structure, three types of control structure are used to form the logic of program.
Control Structures Cont…. Sequential Logic or sequential Flow. Selection Logic or Conditional Flow. Iteration Logic or Repetitive Flow. Sequential Logic :  In sequence control structure, one program statement following another logical order. OR Steps are executed one after one i.e Step1   Step2  Step3  Step4  So on…
2. Selection Logic Selection logic employs a number of conditions which leads to a selection of one out of several alternatives conditions. The selection control structure also known as IF-THEN-ELSE structure. Its offers two paths to follow when a decision must be made by a program. The selection control structure fall into 3 types:
Selection control structure types:  Single Alterative : (One Condition): This structure has the form: IF condition, then  [Module A ] End of IF structure. ------------------------------------- Algorithm: step1: start step2: if  today is wed” then goto step3. Step3: print “ today is wed”  Step4: End/Exit
Double Alterative: This structure has the form IF condition, then [Module A] Else [Module B] End of IF Structure ------------------------------ Algorithm: Step1: start Step2: if a=1 then goto step3  Step3: Print “a=1” Else Step4: print “a!=1” Step5: End/Exit.
Multiple Alterative: This structure has the form. IF condition1, then [Module A] Else IF condition2, then [Module B] Else IF condition3, then [Module C]  Else [Module D] Algorithm: Step1: start Step2: if a=1 then goto step3 Step3: print a=1. else Step4: if a=2 then goto step5 Step5: print a=2. Else Step6: if a=3 then goto step7 Step7: print a=3. Else Step8: print a!=1,2,3 Step9: End/Exit.
3.  Iteration Logic OR Repetitive Flow In this iteration or loop control structure a process may be repeat as long as the condition remain true. In this control structure, we use either two types of structure involving loops. For Loop While Loop For loop is used to repeat a process until a fix number of times While loop is used to repeat a process or instructions until our condition is true.
Iteration logic Example: Algorithm: Step1: start Step2: declare variable x as interger for{ Step3: assign value 1 to x variable. Step4: if x<=5 then goto step5 Step5: print value of x. Step6: add 1 to x (x++) Step7: goto step4 } Else Step8: End
Program (For Loop) void main() { int x; for(x=1;x<=5;x++) { printf(“\n x=%d”,x); } } Output: x=1 x=2 x=3 x=4 x=5 Format string Variable declaration Assignment of a value . check condition (value of x) Increament statement ( add 1 to x)
Program (while loop) void main () { int x=3; while(x!=1) { printf(“\nData Structure”); x--; } } OUTPUT: Data Structure Data Structure same as x = x- 1;
Complexity of an Algorithm: The analysis of algorithm is a major task in computer science. In order to compare algorithm, we must have some criteria to measure the efficiency or complexity of an algorithm. Efficiency of an algorithm depends on two major criteria. First one is run time of that algorithm. Second is space.
We implement different data structures, some data structure takes more space but improves the run time and some take less space but its run time is slow. Lets suppose space is fixed of an algorithm then only run time will be considered for obtaining the complexity. We take three cases for complexity of algorithms. Best Case Worst Case Average Case
Best Case:   In this case, the algorithm takes less time to execute or  algorithm searches the element in first time. Worst Case:  In this case, algorithm takes more time to execute or its fail to achieve its goal or in this case, algorithm finds the element at end or searching of element is fail. Average Case:  Here we take probability with list of data. Average case algorithm should be average number of steps but since data can be at any place, so finding exact behavior of algorithm is difficult.
FLOWCHART
FLOWCHART A program flowchart is a graphical representation of how process works. OR A program flowchart is a chart that graphical present the detail series of steps (algorithm or logical flow) needed to solve a programming problem. The program flowchart can be likened to the blueprint of a building.
Meaning of a flowchart:  A flowchart is a diagrammatic representation that illustrates the sequence of operation to be performed to get the solution of a problem. Flowcharts facilitate communication between the programmers and business people. Flowchart play a vital role in the programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems. Once the flowchart is drawn, it becomes easy to write the program in any high level language.
Design the Flowchart The flowchart is drawn according to define rules and using standard flowchart symbols.
Symbols of FlowChart Terminator: An oval flowchart indicating the start and end of process. Process: A rectangular shape indicating a normal process flow step or calculation or assigning of values to variables. Data: A parallelogram shape indicating any statement that causes data to be input to a program or output from the program.
Symbols of Flowchart: Decision: A diamond shape indicating conditional steps. Diamond shape have two paths (True/False or Yes/No) Connector: A small, labelled circular shape used to indicate a jump in the process flow. Arrows: Arrows are used to connect symbols and indicates the sequence of operations.
Example: Program: Void main() { int a=1; if(a=1) {   printf(“a is equal to 1”); } } Start Int a=1 If a=1 Print a=1 End NO YES

More Related Content

PPTX
Algorithm
PPT
03 algorithm properties
PDF
Lecture Note-2: Performance analysis of Algorithms
PDF
QULITIES OF A GOOD ALGORITHM
PPT
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
PPTX
phases of algorithm
PDF
Algorithm defination, design & Implementation
PPTX
Flowcharts and algorithms
Algorithm
03 algorithm properties
Lecture Note-2: Performance analysis of Algorithms
QULITIES OF A GOOD ALGORITHM
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
phases of algorithm
Algorithm defination, design & Implementation
Flowcharts and algorithms

What's hot (19)

PPTX
Algorithm and flowchart with pseudo code
PPTX
11 Unit 1 Problem Solving Techniques
PPT
Algorithm and Flowcharts
PPT
PPTX
Algorithm and flowchart
PPTX
Algorithm and flowchart2010
PPTX
What is an algorithm?
PPTX
FIT-Unit3 chapter 1 -computer program
PPT
Algorithm Design
PPT
Computer Program- Introduction, characteristics and stages
PPTX
Algorithm &amp; flowchart
PPT
Introduction to Algorithms & flow charts
PPSX
Ic lecture6 architecture and algo
PPTX
Algorithm and Flowcharts
PPT
Programming fundamentals lecture 1&2
PPT
2.3 Apply the different types of algorithm to solve problem
PPTX
Algorithm - Introduction
PDF
Algorithm
Algorithm and flowchart with pseudo code
11 Unit 1 Problem Solving Techniques
Algorithm and Flowcharts
Algorithm and flowchart
Algorithm and flowchart2010
What is an algorithm?
FIT-Unit3 chapter 1 -computer program
Algorithm Design
Computer Program- Introduction, characteristics and stages
Algorithm &amp; flowchart
Introduction to Algorithms & flow charts
Ic lecture6 architecture and algo
Algorithm and Flowcharts
Programming fundamentals lecture 1&2
2.3 Apply the different types of algorithm to solve problem
Algorithm - Introduction
Algorithm
Ad

Viewers also liked (8)

PPT
Lect 17-18 Zaheer Abbas
PPT
Lect 10 Zaheer Abbas
PPT
Lect 15-16 Zaheer Abbas
PPT
Lect 8(pointers) Zaheer Abbas
PPT
Lect 1-2 Zaheer Abbas
PPT
Lect 14 Zaheer Abbas
PPT
Lect 13 Zaheer Abbas
PPT
Lect 19 Zaheer Abbas
Lect 17-18 Zaheer Abbas
Lect 10 Zaheer Abbas
Lect 15-16 Zaheer Abbas
Lect 8(pointers) Zaheer Abbas
Lect 1-2 Zaheer Abbas
Lect 14 Zaheer Abbas
Lect 13 Zaheer Abbas
Lect 19 Zaheer Abbas
Ad

Similar to Lect 3-4 Zaheer Abbas (20)

PDF
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
PPT
Unit 1 psp
PDF
Unit 1-problem solving with algorithm
PDF
Introduction to Problem Solving Techniques- Python
PPTX
FPL -Part 2 ( Sem - I 2013)
PPTX
Data Structures_Introduction to algorithms.pptx
DOCX
Algorithm design and problem solving
PPTX
UNIT 1.pptx Programming for Problem Solving
PPTX
PPT
Flowcharts and Introduction to computers
PPT
Flowchart presentation that can be useful
PPTX
CSE-113 UNIT-1 with the basic knowledge of the computer science.pptx
PPT
Programming algorithms and flowchart.ppt
PDF
GE8151 notes pdf.pdf
PPT
algorithm
PPTX
Data Structure and Algorithms –Introduction.pptx
PDF
Astu DSA week 1-2.pdf
PPTX
UNIT I.pptxpython unit 1 engineering full unit completed
PDF
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
PDF
lect 1-ds algo(final)_2.pdf
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Unit 1 psp
Unit 1-problem solving with algorithm
Introduction to Problem Solving Techniques- Python
FPL -Part 2 ( Sem - I 2013)
Data Structures_Introduction to algorithms.pptx
Algorithm design and problem solving
UNIT 1.pptx Programming for Problem Solving
Flowcharts and Introduction to computers
Flowchart presentation that can be useful
CSE-113 UNIT-1 with the basic knowledge of the computer science.pptx
Programming algorithms and flowchart.ppt
GE8151 notes pdf.pdf
algorithm
Data Structure and Algorithms –Introduction.pptx
Astu DSA week 1-2.pdf
UNIT I.pptxpython unit 1 engineering full unit completed
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
lect 1-ds algo(final)_2.pdf

More from Information Technology Center (8)

PDF
It3 4 by Zaheer Abbas Aghani
DOC
Flip & flop by Zaheer Abbas Aghani
DOC
C# by Zaheer Abbas Aghani
DOC
C# by Zaheer Abbas Aghani
PPT
Lect 22 Zaheer Abbas
PPT
Lect 21 Zaheer Abbas
PPT
Lect 11-12 Zaheer Abbas
PPT
Lect 9(pointers) Zaheer Abbas
It3 4 by Zaheer Abbas Aghani
Flip & flop by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
Lect 22 Zaheer Abbas
Lect 21 Zaheer Abbas
Lect 11-12 Zaheer Abbas
Lect 9(pointers) Zaheer Abbas

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mushroom cultivation and it's methods.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
TLE Review Electricity (Electricity).pptx
PPT
Teaching material agriculture food technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
A Presentation on Artificial Intelligence
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Machine Learning_overview_presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
August Patch Tuesday
PPTX
cloud_computing_Infrastucture_as_cloud_p
Reach Out and Touch Someone: Haptics and Empathic Computing
Advanced methodologies resolving dimensionality complications for autism neur...
MIND Revenue Release Quarter 2 2025 Press Release
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mushroom cultivation and it's methods.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
TLE Review Electricity (Electricity).pptx
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
A Presentation on Artificial Intelligence
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine Learning_overview_presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
August Patch Tuesday
cloud_computing_Infrastucture_as_cloud_p

Lect 3-4 Zaheer Abbas

  • 1. Created By Zaheer Abbas Aghani
  • 2. Data Structure (ITC-322) Lecture 2 Algorithms
  • 3. Algorithms (Definition) An Algorithm (pronounced AL-go-rith-um) is a se quence of instructions specifying the steps required to accomplish some task. OR An algorithm is a finite step by step list of well defined instruction for solving a particular problem.
  • 4. Algorithm -- Examples A cooking recipe. The rules of how to play a game. VCR instructions. Directions for driving from A to B. A car repair manual.
  • 5. Computer Algorithms A computer program is another example of an algorithm. To make a computer do anything, you have to write a computer program. To write a computer program you have to tell the computer step by step, exactly what you want to do. The computer then executes the program following each step to accomplish the end goal. When you telling the computer what to do, you also get to choose how it’s going to do it. That’s where computer algorithms come in.
  • 6. From Algorithms to Programs Problem C Program Algorithm : A sequence of instructions describing how to do a task (or process)
  • 7. Examples: Suppose Add two number a & b and store in c. Steps: Step1: Initialize variable a and b [a=1, b=1] Step2: Declare variable c. Steps3: Add variables and store in other variable [ c= a+b]. Steps4:Print output [c].
  • 8. Implement of Algorithm in C Void main() { int a,b,c; //declaration of variables a=1,b=1; //initialize variable a and b c=a+b; // add a and b and store result in c printf(“%d”,&c); // print output }
  • 9. Example:- Algorithm: Drive_To_Uni Steps { 1. find car keys 2. disable car alarm 3. open car door 4. get in car 5. shut car door 6. put keys in ignition 7. start car 8. back car out of driveway 9. drive to end of street 10. turn right 11. drive to end of street 12. turn left ...etc...etc...etc ...etc...etc...etc... 52. find parking space 53. pull into parking space 54. turn off engine 55. remove keys from ignition 56. open car door 57. get out 58. shut car door 59. lock car door 60. enable alarm }
  • 10. Controls Structures A control structure or logic structure is a structure that controls the logical sequences in which programs instructions are executed. OR Control flow or Control structures refers to the order in which the individual statements, instructions, are executed. Algorithms and their equivalent computer programs are more easily understood if they mainly use these types of control structures. An algorithm or computer program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. In algorithm design structure, three types of control structure are used to form the logic of program.
  • 11. Control Structures Cont…. Sequential Logic or sequential Flow. Selection Logic or Conditional Flow. Iteration Logic or Repetitive Flow. Sequential Logic : In sequence control structure, one program statement following another logical order. OR Steps are executed one after one i.e Step1  Step2  Step3  Step4  So on…
  • 12. 2. Selection Logic Selection logic employs a number of conditions which leads to a selection of one out of several alternatives conditions. The selection control structure also known as IF-THEN-ELSE structure. Its offers two paths to follow when a decision must be made by a program. The selection control structure fall into 3 types:
  • 13. Selection control structure types: Single Alterative : (One Condition): This structure has the form: IF condition, then [Module A ] End of IF structure. ------------------------------------- Algorithm: step1: start step2: if today is wed” then goto step3. Step3: print “ today is wed” Step4: End/Exit
  • 14. Double Alterative: This structure has the form IF condition, then [Module A] Else [Module B] End of IF Structure ------------------------------ Algorithm: Step1: start Step2: if a=1 then goto step3 Step3: Print “a=1” Else Step4: print “a!=1” Step5: End/Exit.
  • 15. Multiple Alterative: This structure has the form. IF condition1, then [Module A] Else IF condition2, then [Module B] Else IF condition3, then [Module C] Else [Module D] Algorithm: Step1: start Step2: if a=1 then goto step3 Step3: print a=1. else Step4: if a=2 then goto step5 Step5: print a=2. Else Step6: if a=3 then goto step7 Step7: print a=3. Else Step8: print a!=1,2,3 Step9: End/Exit.
  • 16. 3. Iteration Logic OR Repetitive Flow In this iteration or loop control structure a process may be repeat as long as the condition remain true. In this control structure, we use either two types of structure involving loops. For Loop While Loop For loop is used to repeat a process until a fix number of times While loop is used to repeat a process or instructions until our condition is true.
  • 17. Iteration logic Example: Algorithm: Step1: start Step2: declare variable x as interger for{ Step3: assign value 1 to x variable. Step4: if x<=5 then goto step5 Step5: print value of x. Step6: add 1 to x (x++) Step7: goto step4 } Else Step8: End
  • 18. Program (For Loop) void main() { int x; for(x=1;x<=5;x++) { printf(“\n x=%d”,x); } } Output: x=1 x=2 x=3 x=4 x=5 Format string Variable declaration Assignment of a value . check condition (value of x) Increament statement ( add 1 to x)
  • 19. Program (while loop) void main () { int x=3; while(x!=1) { printf(“\nData Structure”); x--; } } OUTPUT: Data Structure Data Structure same as x = x- 1;
  • 20. Complexity of an Algorithm: The analysis of algorithm is a major task in computer science. In order to compare algorithm, we must have some criteria to measure the efficiency or complexity of an algorithm. Efficiency of an algorithm depends on two major criteria. First one is run time of that algorithm. Second is space.
  • 21. We implement different data structures, some data structure takes more space but improves the run time and some take less space but its run time is slow. Lets suppose space is fixed of an algorithm then only run time will be considered for obtaining the complexity. We take three cases for complexity of algorithms. Best Case Worst Case Average Case
  • 22. Best Case: In this case, the algorithm takes less time to execute or algorithm searches the element in first time. Worst Case: In this case, algorithm takes more time to execute or its fail to achieve its goal or in this case, algorithm finds the element at end or searching of element is fail. Average Case: Here we take probability with list of data. Average case algorithm should be average number of steps but since data can be at any place, so finding exact behavior of algorithm is difficult.
  • 24. FLOWCHART A program flowchart is a graphical representation of how process works. OR A program flowchart is a chart that graphical present the detail series of steps (algorithm or logical flow) needed to solve a programming problem. The program flowchart can be likened to the blueprint of a building.
  • 25. Meaning of a flowchart: A flowchart is a diagrammatic representation that illustrates the sequence of operation to be performed to get the solution of a problem. Flowcharts facilitate communication between the programmers and business people. Flowchart play a vital role in the programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems. Once the flowchart is drawn, it becomes easy to write the program in any high level language.
  • 26. Design the Flowchart The flowchart is drawn according to define rules and using standard flowchart symbols.
  • 27. Symbols of FlowChart Terminator: An oval flowchart indicating the start and end of process. Process: A rectangular shape indicating a normal process flow step or calculation or assigning of values to variables. Data: A parallelogram shape indicating any statement that causes data to be input to a program or output from the program.
  • 28. Symbols of Flowchart: Decision: A diamond shape indicating conditional steps. Diamond shape have two paths (True/False or Yes/No) Connector: A small, labelled circular shape used to indicate a jump in the process flow. Arrows: Arrows are used to connect symbols and indicates the sequence of operations.
  • 29. Example: Program: Void main() { int a=1; if(a=1) { printf(“a is equal to 1”); } } Start Int a=1 If a=1 Print a=1 End NO YES