Component 2- Algorithms Flashcards
What is an algorithm?
A series of instructions that solves a problem in a finite number of steps
What three criteria lead to a successful algorithm?
- Accuracy
- Consistency
- Efficiency
What is a sequence?
An ordered set of steps or instructions
What does unambiguous mean?
Written in a way that makes it completely clear what is meant
What are the two ways to plan and design an algorithm?
- Visual (Using flow chart symbols)
- Text (Using a written sequence of instructions)
What is the difference between an algorithm and a problem?
Before you can write a program to solve a problem, you have to work out the algorithm first
What is a variable?
A storage location used to store a value; this could be text or a number. The value stored in the variable may change as the program is run.
What are the rules for a variable name?
- Must be written before a value is assigned to it
- Cannot start with a number
- Must not have spaces
- Must make sense in algorithm
What is ‘=’ in OCR pseudocode?
Assignment of a value to a variable
What is ‘==’ in OCR pseudocode?
Shows equality
What is the flow chart symbol for a terminator and what does it show?
- Oval / Rounded Rectangle
- Start or end of algorithm
What is the flow chart symbol for a process and what does it show?
- Rectangle
- Process in algorithm e.g. Calculating price
What is the flow chart symbol for a decision and what does it show?
- Diamond
- Have one of two answers; yes or no, true or false
What is the flow chart symbol for an input or output and what does it show?
- Parallelogram
- Shows data into algorithm or outputs from it
What does an arrow show in a flow chart?
- Sequence of steps in the algorithm
- Usually vertical or horizontal
What is a flow chart?
Visual representation of the sequence of steps in an algorithm
What is a constant?
A storage location used to store a value that never changes as the program runs
What is assignment?
Giving a variable or constant a value by linking a value to the identifier
What is an identifier?
A unique name given to a variable or constant in your algorithm which makes your algorithm easier to read and understand
What is pseudocode?
A structured, code-like language that can be used to describe an algorithm
What are keywords?
Used in pseudocode for common operators; written in capital letters
What are some example keywords?
INPUT- Getting values into the algorithm from user via keyboard
OUTPUT- Messages or results displayed on screen
What are the pseudocode arithmetic operators for addition, subtraction, multiplication and division?
+ , - , * , /
What are the pseudocode arithmetic operators for integer division and modulus?
DIV (only evaluates quotient which is the integer)
MOD (only evaluates remainder)
List all the comparison operators (and what they evaluate to)
< - Less than (True)
> - Greater than (False)
== - Same as (True)
!= - Not equal to (True)
<= - Less than or equal to (True True)
>= - Greater than or equal to (True False)
True or False: Arithmetic Operators are evaluated AFTER comparison operators
False, evaluated BEFORE.
What are the three Boolean operators?
AND - Checks both conditions are true or false
OR - Checks EITHER conditions is true
NOT - Reverses Boolean Value (e.g x>y = False, NOT reverses evaluation to True)
What is an operator?
Symbol that shows an operation
What are the three basic programming constructs ?
- Sequence
- Selection
- Iteration
What is an exponentiation?
Base integer is raised to power of exponent integer, Operator is ^
What are the two types of iteration?
- Condition- controlled loop
- Count-controlled loop
What is nesting?
Combining code together, putting a while loop inside a while loop
What is an array?
Data structure that allows storage of multiple items in a single variable
What is a subprogram?
Clear, independent blocks of code within a computer program which can be called and accessed by main program
What is ‘call’?
Starting the subprogram
What are subprograms which return values known as?
Functions
What are subprograms which don’t return values known as?
Procedures
What is decomposition?
Breaking problem down into smaller sub-problems until these tasks are solved
What is a string?
A sequence of characters surrounded by quotation marks
What is concatenation?
Merging or joining two strings together using a concatenation operator (+)
What is abstraction?
Process of removing unnecessary details from a problem
What is time efficiency?
The number if steps to complete the algorithm
What is space efficiency?
The amount of memory required to complete the algorithm
What is brute force?
Process that tries all possible alternatives to find a solution
How are data values within a program stored?
Either as variables or constants which serve as placeholders that reference specific memory locations
True or False: Each variable or constant is design to contain multiple data items at any given time.
False, while a program can encompass numerous variables and constants, each is designed to contain a SINGLE data item at any given time.
What are the common data types and what are they used for?
Integer - Whole Numbers, both positive and negative
Real - Employed for numbers with fractional components, including decimals
Character (char) - Holds single characters (e.g. letter, digit, symbol)
String - Stores a sequence of characters.
Boolean - Representing truth values
Why is a variable name important?
Used by program to reference a specific memory location where the associated data is stored.
What happens when a new value is assigned to a variable?
Old value is overwritten and lost unless it’s stored elsewhere
What is snakecase?
Variables are written in lowercase with words separated by an underscore (first_name)
What is camelcase?
Variables are written in lowercase without any spaces and after first word each new word starts with capital letter (firstName)
What is pascalcase?
Variables are written the same as camelcase but first word also starts with capital letter (FirstName)
What is the difference of a constant compared to a variable?
- Once a value is assigned to a constant, it remains fixed and cannot be changed while program is running
- Offer a way to define consistent values and are only declared and assigned once
- Can be referred to repeatedly without worrying about accidental modifications.
What is the primary advantage of a constant?
- Provide single point of change (only one location needs modification) if a decision to modify value or precision in future
- Improves maintainability and reduces risk of introducing errors
What are inputs?
Data that a program receives or and processes . Come from variety of sources, including user input, files, sensors and networks
What are outputs?
Results of a program’s processing which can be displayed on screen, printed out or sent other devices or programs.
How can data retrieved by an input function be made use of?
Assign the return value to a variable or the input value will effectively go unused and program will proceed with execution
What do programming constructs provide?
Structural framework for creating programs and define how instructions and data are organised an manipulated within a program.
What can programmers create using programming constructs?
Algorithms and logical structures that achieve specific tasks and solve problems.
What does the sequence construct involve?
- Executing series of statements in specific order, following linear flow of program
- Foundation for building step-by-step logic that characterises most programs
What does the selection construct involve?
- Enables program to make decisions based on conditions
- Evaluating whether certain conditions are true or false then executing different sets of instructions accordingly
- Introduces branching and enables programs to adapt to different scenarios
What does the iteration construct involve?
- Also known as looping
- Allows set of instructions to repeat multiple times as long as a certain condition remains true
- Crucial for automating repetitive tasks and creating efficient, data-driven processes
What happens when the sequence construct is ignored and instructions are executed in wrong order?
- Logic Errors: May not perform designed task or might produce incorrect outputs due to flawed logic
- Unexpected Results: Incorrect sequencing can lead to unseen results which make it challenging to troubleshoot and identify root cause
- Crashes: In extreme cases, incorrect sequence could cause crashes, freeze or undefined behaviour
What are the two types of iteration?
Count-controlled iteration - Number of times the loop is executed is predetermined before loop starts
Condition-controlled iteration- Loop continues to execute until certain condition is met