CSC B1.4

Cards (21)

  • Algorithm is sequence of well-defined steps to solve a problem/sequence of steps arranged in a specific logical order which produces a solution for a problem
  • Good algorithm requirement:
    1. Input
    2. Output
    3. Generality
    4. Correctness
    5. Finiteness
  • INPUT is conceivable that an algorithm may have no input. However, such algorithms are trivial and quite rare
  • OUTPUT is an algorithm that does not produce anything is worthless
  • GENERALITY is it must be general (can be used for different inputs)
  • CORRECTNESS is It must be correct and must solve the problem for which it is designed
  • FINITENESS is it must execute its step and terminate in finite time
  • to represent algorithm:
    1. IPO Chart
    2. Pseudocode
    3. Flowchart
  • Find the square of a number INPUT : Number
    PROCESS : Calculate Square
    OUTPUT: Square
  • Calculate and display the average of three marks INPUT: mark1, mark2, mark3 PROCESS: calculate average OUTPUT: average
  • Calculate the area of a circle INPUT: radius
    PROCESS: calculate AreaCircle
    OUTPUT: AreaCircle
  • RM200 per night, service charge is 15%, determine total amount:
    INPUT: Number_Of_Night PROCESS: Calculate Total_Payment
    OUTPUT: Total_Payment
  • PSEUDOCODE is written statement of an algorithm using a semiformal language with limited vocabulary
  • The main purpose of using pseudocode is to define the procedural logic of an algorithm in a simple, easy-to-understand for its readers, who may not be proficient in computer programming language
  • In order to succeed in accomplishing its objectives, a pseudocode must: 1. Have limited vocabulary 2. Easy to learn 3. Produce simple, English-like narrative notation 4. Capable of describing all algorithms, regardless of their complexity
  • General format for pseudocode: START DECLARE Variable1, Variable2,..... INPUT/READ/ENTER/GET....(input) Formula/Condition.... (process) OUTPUT/DISPLAY/PRINT....(output) END
  • PROBLEM STATEMENT 1: Find the square of a number
    START DECLARE Number, Square
    INPUT Number
    Square Number×Number
    PRINT Square
    END
  • Calculate and display the average of three marks
    START DECLARE Mark1, Mark2, Mark3, Average INPUT Mark1, Mark2, Mark3 Average (Mark1 + Mark2 + Mark3)/3 PRINT Average END
  • Calculate the area of a circle
    START DECLARE Radius, AreaCircle
    INPUT Radius
    AreaCircle = 3.142×Radius×Radius
    PRINT AreaCircle
    END
  • RM200 per night, charge is 15%, total amount
    START DECLARE Number_Of_Night, Total_Payment, Total INPUT Number_Of_Night Total = Number_Of_Night×200 Total_Payment = Total+(0.15×Total) PRINT Total_Payment
    END
  • Flowchart is a set of standard shaped boxes that are connected by flowlines to represent an algorithm