Paper 1 Flashcards
(39 cards)
What is an algorithm?
A sequence of steps that can be followed to complete a task.
What is a computer program?
An implementation (application) of an algorithm.
What is decomposition?
The process of breaking down a complex problem into sub-problems or more manageable chunks, so each sub-problem accomplishes an identifiable task.
* This makes the problem easier to understand.
What is abstraction?
Abstraction is the process of removing unnecessary detail from a problem.
* This SIMPLIFIES the problem
What makes an algorithm efficient?
- Takes less time to execute.
- Less calculations are required for the algorithm to be completed.
How does the linear search algorithm work?
Why is it important to use a meaningful identifier name?
- Describes the role of the variable
- Making the algorithm easier to understand
What are the advantages of using the structured approach/ subroutines?
- Subroutines can be developed seperately
- It is easier to discover errors
- Subroutines can be updated without affecting the overall program
What should the conditions of an algorithm be?
- Preicse
- Well-defined
- Finite
What is pseudocode?
- Informal description
- Intended for human reading and understanding, but understands code
- No standardised (correct) syntax
Flowcharts:
- Symol for start/end of an algorithm- ⬭
- Symbol for a process being carried out- ☐
- Symbol for a decision to be made- ⬦
The linear search algorithm:
- Works by checking each element to see if it matches the target
- This repeats until a match has been found or the whole list of values has been checked
- WHEN PROGRAMMING THIS USE A BOOLEAN VALUE TO KEEP TRACK OF THE VALUE AND IF IT HAS BEEN FOUND/NOT FOUND.
🚩- Not efficient for long lists
The binary search algorithm:
- List must be ordered first to work- extra step. If this is not done, the program is inefficient and won’t work.
- OVERALL, BINARY SEARH IS MORE EFFICIENT THAN LINEAR SEARCH.
Compare the bubble sort and merge sort algorithm.
- Bubble sort is less efficient than merge sort
What is a variable?
- An address in memory
- That is given a name
- That is assigned a value
- That can change whilst the program is running.
Define constant.
- An address in memory
- That is given a name
- That is asigned a value
- That cannot change while the program is running
Advantages of using a constant:
1) You only have to change the value of the constant once in the source code. If we didn’t have the constant we’d have to hunt through the program to find all the places where we’d written 4 and change them to the new number.
2) It makes sure that our program is consistent as we only have to enter the value once.
3) If lots of people are working on the same program it stops mistakes happening.
4) It also makes your code more readable. For example if you are writing a program to calculate with circles it is much easier to have a constant called PI than to have to keep typing 3.1415…
How do you identify a constant?
A constant has an ALL UPERCASE VARIABLE name.
What are the three main constructs?
- Sequence - the idea of one step being done after another in a particular order
- Iteration - repeating sections of code in a loop (FOR, WHILE, REPEAT)
- Selection - changing the direction of a program based on a specific criteria (IF, SELECT CASE)
Iteration- indefinite loop (condition controlled loop):
- Condition controlled loops are the that in which the end of the loop is unknown, it will continue indefinetely until the condition is met.
Which condition controlled loop is adavntageous and why?
The REPEAT…UNTIL loop
* Th same effect is achieved with both WHILE…ENDWHILE and REPEAT…UNTIL loop
* But the REPEAT…UNTIL loop allows the program to enter the loop, gain an input, then test the condition at the end
* The WHILE…ENDWILE loop will keep running UNTIL the the conditio is met, but the REPEAT…UNNTIL loop only runs when the condition is met.
* This makes it more efficient.
What are the two types of indefinite loop?
- Pre-controlled loops – the condition is checked before the loop starts, and will keep going whilst the condition is TRUE. E.g. END…ENDWILE
- Post-controlled loops – the condition is checked once the loop has finished, and will stop as soon as the condition is TRUE. E.g. REPEAT…UNTIL
What is an exaple of a pre-controlled loop.
WHILE count < 5
count ← count + 1
ENDWHILE
What is an example of a post-controlled loop.
REPEAT
count ← count + 1
UNTIL count < 5