SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Algorithm
   By Taimoor Abdullah Khan
                    BSCS - 1st
Definition
“Set of instructions used to perform a certain task.”
Characteristics of an Algorithm
•   Well-ordered Collection.
•   Unambiguous.
•   Effective.
•   Computable Operations.
•   Executable.
•   Result giving.
•   Halts in Finite amount of time.
Elements of Algorithm
1.   Constants.
2.   Variables.
3.   Arrays.
4.   Operators.
5.   Loops.
6.   Conditional Statements.
7.   Comments
1. Constants
  • Numbers as same as in mathematics.
  • Helps Structuring

            Example: y = 5*c
                     i=i+1
Value



2. Variables
   • For Storing Values.
   • Can be given any name, but given such to
     remind of its purpose. Sum, Temp etc.
Value             Value             Value




                                                myArray
                              myArray
3. Arrays             0                 1                 2
  • Two or more Variables with same name.
  • Addressed individually by their index.
                             myArray[7]
  • Variable or constant both used to address the
    index.
  • Each location can store a different value.
  • Usually Starting at index 0.
4. Operators
  • Used to perform Operations on Variables or
    Constants.
  • Mathematical Operators: +, -, *, / and %.
  • Assignment Operator: =
  • Comparison Operator: ==
  • Increment , Decrement Operator: ++, --
5. Iteration
   • Used to repeat a certain code or lines.
   • Useful for replacing repetition.
   • Can use Index variables for Arrays.
   • Major two types of loops: for loop
                                      While loop
   • Can be stopped from inside off loop body by using
     break; statement.
While Loop
•   Repeats if a certain Condition is true.
•   Stops when Condition becomes false.
•   Can repeat Infinite times.
•   Can be given value ‘1’ to represent Boolean value for ‘True’ so the loop
    remains true.
•   Syntax: while(Condition)
           {
                 Loop body;
           }
For Loop
•   Given a Variable, for which the condition is set.
•   Variable is Incremented or Decremented.
•   Repeats for fixed amount of times.
•   Syntax: for( i = 0; i <= n; i++) //n is any number
            {
                Loop body;
            }
6. Conditional Statement
   •   Used to take decision.
   •   Checks a Condition.
   •   Runs a statement body if Condition is true.
   •   Otherwise runs statment body for “Else” statement if any is given.
   •   Syntax: If(Condition)
                   {
                           Loop body;
                   }
              Else
                   {
                           Loop body;
                    }
7. Comments
  • Useful in long and complex programs.
  • Can be written where required
    explanation.
  • Mostly written after ‘//’.
The End
 What Are You Staring At?? Its Done!
Thank you.

Weitere ähnliche Inhalte

Was ist angesagt? (8)

CPP04 - Selection
CPP04 - SelectionCPP04 - Selection
CPP04 - Selection
 
Vb script final pari
Vb script final pariVb script final pari
Vb script final pari
 
Difference between is and as operators in c#
Difference between is and as operators in c#Difference between is and as operators in c#
Difference between is and as operators in c#
 
01 Variables
01 Variables01 Variables
01 Variables
 
Lec 1.4 Object Oriented Programming
Lec 1.4 Object Oriented ProgrammingLec 1.4 Object Oriented Programming
Lec 1.4 Object Oriented Programming
 
Type script variable declaration
Type script variable declarationType script variable declaration
Type script variable declaration
 
Javascripts hidden treasures BY - https://geekyants.com/
Javascripts hidden treasures            BY  -  https://geekyants.com/Javascripts hidden treasures            BY  -  https://geekyants.com/
Javascripts hidden treasures BY - https://geekyants.com/
 
Introduction of basics loop and array
Introduction of basics loop and arrayIntroduction of basics loop and array
Introduction of basics loop and array
 

Ähnlich wie Algorithm

Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 
Java class 1
Java class 1Java class 1
Java class 1
Edureka!
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
Connex
 
Going loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxGoing loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptx
Amy Nightingale
 

Ähnlich wie Algorithm (20)

Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Java class 1
Java class 1Java class 1
Java class 1
 
Variables in Pharo
Variables in PharoVariables in Pharo
Variables in Pharo
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
CPP05 - Arrays
CPP05 - ArraysCPP05 - Arrays
CPP05 - Arrays
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
C language
C languageC language
C language
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
data types.pdf
data types.pdfdata types.pdf
data types.pdf
 
Arrays
ArraysArrays
Arrays
 
Going loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxGoing loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptx
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
General Programming Concept
General Programming ConceptGeneral Programming Concept
General Programming Concept
 
Java
Java Java
Java
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 
First Class Variables as AST Annotations
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST Annotations
 

Algorithm

  • 1. Algorithm By Taimoor Abdullah Khan BSCS - 1st
  • 2. Definition “Set of instructions used to perform a certain task.”
  • 3. Characteristics of an Algorithm • Well-ordered Collection. • Unambiguous. • Effective. • Computable Operations. • Executable. • Result giving. • Halts in Finite amount of time.
  • 4. Elements of Algorithm 1. Constants. 2. Variables. 3. Arrays. 4. Operators. 5. Loops. 6. Conditional Statements. 7. Comments
  • 5. 1. Constants • Numbers as same as in mathematics. • Helps Structuring Example: y = 5*c i=i+1
  • 6. Value 2. Variables • For Storing Values. • Can be given any name, but given such to remind of its purpose. Sum, Temp etc.
  • 7. Value Value Value myArray myArray 3. Arrays 0 1 2 • Two or more Variables with same name. • Addressed individually by their index. myArray[7] • Variable or constant both used to address the index. • Each location can store a different value. • Usually Starting at index 0.
  • 8. 4. Operators • Used to perform Operations on Variables or Constants. • Mathematical Operators: +, -, *, / and %. • Assignment Operator: = • Comparison Operator: == • Increment , Decrement Operator: ++, --
  • 9. 5. Iteration • Used to repeat a certain code or lines. • Useful for replacing repetition. • Can use Index variables for Arrays. • Major two types of loops: for loop While loop • Can be stopped from inside off loop body by using break; statement.
  • 10. While Loop • Repeats if a certain Condition is true. • Stops when Condition becomes false. • Can repeat Infinite times. • Can be given value ‘1’ to represent Boolean value for ‘True’ so the loop remains true. • Syntax: while(Condition) { Loop body; }
  • 11. For Loop • Given a Variable, for which the condition is set. • Variable is Incremented or Decremented. • Repeats for fixed amount of times. • Syntax: for( i = 0; i <= n; i++) //n is any number { Loop body; }
  • 12. 6. Conditional Statement • Used to take decision. • Checks a Condition. • Runs a statement body if Condition is true. • Otherwise runs statment body for “Else” statement if any is given. • Syntax: If(Condition) { Loop body; } Else { Loop body; }
  • 13. 7. Comments • Useful in long and complex programs. • Can be written where required explanation. • Mostly written after ‘//’.
  • 14. The End What Are You Staring At?? Its Done!