cps ias caie 2 concept

Cards (84)

  • Abstraction
    Filtering out and concentrating on the relevant information in a problem; allowing a programmer to deal with complexity
  • Decomposition
    Breaking down problems into sub-problems in order to understand a process more clearly; program modules, procedures and functions all help the programmer to break down large problems
  • Algorithm
    A sequence of defined steps (step by step) to solve a given problem
  • Ways to represent an algorithm
    • Structured English
    • Pseudocode
    • Flowchart
  • Features of good pseudocode
    • Meaningful identifier names
    • Contains comments
    • Capitalize keywords
    • Using spacing
    • Using indentation
  • Identifier
    Name given to a variable in order to call it
  • Variable
    A memory location that stores a value that can be changed through the execution of the program
  • Constant
    A memory location that stores a value that cannot be changed through the execution of the program
  • Basic data types
    • Integer
    • Real
    • Char
    • String
    • Boolean
    • Date
  • Rules for naming identifiers
    • Should be meaningful
    • Must be unique
    • No spaces
    • Must begin with a letter
    • Consist of letters, digits and underscore
    • Must not be a reserved word
  • Assignment
    A value is given a name (identifier) or the value associated with a given identifier is changed
  • Sequence
    Instructions (lines of code) should be executed one after another in a fixed order
  • Selection
    Construct used to decide in choosing an option from many available options based on a condition
  • Selection constructs
    • IF selection
    • CASE selection
  • Repetition/Iteration
    Control structure in which a group of statements is executed repeatedly
  • Repetition/Iteration constructs
    • FOR loop
    • WHILE loop
    • REPEAT loop
  • Rogue value
    A value used to terminate a sequence of values
  • FOR loops are best used when you know the number of iterations required, and WHILE or REPEAT loops if you do not know the number of iterations required
  • Situations for different loop types
    • Iterate over an array: FOR Loop
    • Reading a file into a variable: WHILE Loop
    • Asking for user input: WHILE/REPEAT Loop
    • A loop that should execute n times: FOR Loop
  • Logical operations
    • Less than
    • Less than/equal
    • Greater than
    • Greater/equal
    • Equal to
    • Not equal to
  • Stepwise refinement
    Process of expressing the algorithm steps of a certain task in more details steps as the modular design by splitting a problem into smaller sub-tasks, which themselves are repeatedly split into even smaller sub-tasks until each is just one element of the final program
  • Subroutine
    Self-contained section of code, performing a specific task; part of the main program
  • Procedure
    Performs a specific task, no value returned to part of code where called
  • Function
    Performs a specific task, returns a value to part of code where called
  • Procedure/function header
    • Contains the name of the procedure or function, any parameters passed to it, and, for a function, the type of the return value
  • Argument
    The value passed to a procedure or function
  • Pass by value
    A method of passing a parameter to a procedure in which the value of the variable cannot be changed by the procedure
  • Pass by reference
    A method of passing a parameter to a procedure in which the value of the variable can be changed by the procedure
  • Global variable
    Declared outside of the functions/procedures in a program and can be accessed by any of them
  • Local variable
    Declared inside a specific function/procedure and can only be accessed by the function/procedure in which it is declared
  • Benefits of using modules, procedures and functions
    • Lines of code can be re-used; don't have to be repeated
    • Can be tested/improved independently of program
    • Easy to share procedures/functions with other programs
    • Create routines that can be called like built-in commands
  • Benefits of using built-in modules/library routines
    • The routines are all fully tested and should be error-free
    • No need to rewrite the many routines every single time
    • Leads to modular programming
    • Easier in maintenance
    • Saves considerable development time
  • Array
    A data structure containing several elements of the same data type; these elements can be accessed using the same identifier name
  • Index
    The position of each element in an array
  • Array types
    • One-dimensional (1D)
    • Two-dimensional (2D)
  • Pseudocode for 1D array
    1. DECLARE ArrayName[LowerBound:UpperBound]:DataType
    2. Assign values to array elements
  • Pseudocode for 2D array
    1. DECLARE ArrayName[LowerBound1:UpperBound1, LowerBound2:UpperBound2]:DataType
    2. Assign values to array elements
  • Bubble sort
    • An outer loop is set to stop the sort
    • A variable 'sorted' is set to 'true' at the beginning
    • An inner loop searches through the array
    • If the first number is greater than the second, they are swapped and 'sorted' is set to 'false'
    • The outer loop continues until 'sorted' remains 'true'
  • Bubble sort algorithm
    1. n ← MaxIndex - 1
    2. FOR i ← 0 TO MaxIndex - 1
    3. FOR j0 TO n
    4. IF MyList[j] > MyList[j + 1]
    5. THEN
    6. TempMyList[j]
    7. MyList[j] ← MyList[j + 1]
    8. MyList[j + 1] ← Temp
    9. ENDIF
    10. NEXT j
    11. n ← n - 1
    12. NEXT i
  • Efficient bubble sort algorithm
    1. n ← MaxIndex - 1
    2. REPEAT
    3. NoMoreSwapsTRUE
    4. FOR j0 TO n
    5. IF MyList[j] > MyList[j + 1]
    6. THEN
    7. TempMyList[j]
    8. MyList[j] ← MyList[j + 1]
    9. MyList[j + 1] ← Temp
    10. NoMoreSwapsFALSE
    11. ENDIF
    12. NEXT j
    13. n ← n - 1
    14. UNTIL NoMoreSwaps = TRUE