Algorithms Flashcards

1
Q

Definition of Variables

A
  • A value that can change during the processing & execution of the program
    Eg:
    1. LName
    2. Address
    3. Age
    4. Weight
    5. Salary
    (these values can change over time)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Definition of Constants

A

-Values that do NOT change during its process
Eg:
1. Gravity
2. DoB
3. URT
4. FName
5. Eye colour
6. Days of Week

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name The Three Control Structures

A
  1. Sequence
  2. Selection/ Conditional/ Logic
  3. Iterations/ Loop/ Repetition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Sequencing (Control Structure)

A
  • This refers to the order of executing statements.
  • In sequencing, one of a number of statements is executing depending on the condition of a program

Eg. Develop an algorithm that would find the area of a triangle using the formula
Area: 1/2 by base by height
0.5 * base * height
Start
Write “Enter the base and height”
Read B,H
Area: 0.5 * B * H
Write “The Area is”, Area
Stop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define Selection/Conditional/Logic (Control Structure)

A
  • In the selection statement, all decisions are made
  • The Statements that consist of the selection construction are:
    1. “IF THEN” Statement
    2. “IF THEN ELSE” Statement
    3. “IF THEN ELSE IF” Statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Define Iteration/Loop/Repetition Statement (Control Structure)

A
  • This is a looping statement.
  • It is a process where a set of instructions are repeated until a CONDITION is met
  • There are THREE types of loops:
    1. FOR Do loop
    2. WHILE Do loop
    3. REPEAT UNTIL loop

Eg. (FOR Do loop) write an algorithm that will prompt user to read the amt of rainfall in the month of October. Display the total rainfall for the month
Start
Count=0
For Rainfall= 1 to 31 Do
Print “Enter amount of rainfall in October”
Read Rain
Count= Rainfall + Count
Print “The total amount of rainfall in October is”,Count
End FOR
Stop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Counting in Pseudocode

A
  • Counting is an action done to find a number of elements or objects
  • When implementing a Counting Statement, an appropriate VARIABLE NAME must be chosen to reflect what is being counted
  • The next step is to initialise to zero (0)
  • This statement means you are starting to count from zero
    Eg. Laptop= 0
    Laptop= Laptop + 1
    Eg. write a pseudocode to count the number of novels in a bookstore & print the appropriate labelling

Start
Novel=0
Print “Enter type of book”
Read Book
IF Book= Novel THEN
Novel= Novel + 1
End IF
Print “The number of novels is ”,Novel
Stop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

While Loop (Repetition Statement)

A
  • This is an unbounded or indefinite loop.
  • The while construct uses the following operations:
    > (more than)
    < (less than)
    <> (more than or less than)
    >= (more than or equal to)
    <= (less than or equal to)

Eg. Buses from Charles Town charge $3.00 per passenger to Curepe. Write the algorithm to input the number of passengers for each day terminated by zero(0). The algorithm should calculate the number of passengers daily as well as the daily revenue.
Start
Tolal=0
Print “Enter the number of passengers per day”
Read P
While P<>0 Do
Revenue= P*3.00
Total= Total + Revenue
Print “The number of passengers”,P
Print “The revenue is”, Revenue
End While
Stop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly