2.1 Algorithms Flashcards
What is Abstraction?
Process of removing unnecessary details and including only the relevant details
What is Decomposition?
Breaking a complex problem into smaller more manageable parts
What is Algorithmic Thinking?
Creating a step by step solution to a problem
What are the 2 types of searching algorithms?
Binary and Linear search
What are the advantages of a Linear Search?
Simple
The list doesn’t need to be ordered
Easy to program
What are the disadvantages of a Linear Search?
Not efficient
Takes time with a lot of data
What are the advantages of a Binary Search?
More efficient than a linear search
What are the disadvantages of a Binary Search?
Only works on an ordered list
How does linear search work?
Checks each item in the list one by one until it finds what it is looking for
How does binary search work?
Finds the middle item in an ordered list By doing n+1/2 Compares the item to the middle item So it knows where to look in the first half of the second half Repeats until the item is found
What is a sorting algorithm?
Sorts items into an ordered list
How does a bubble sort work?
Checks the first 2 items in a list Swaps them if they are in the wrong order Moves to the next items and Repeats Moves through the entire list again Until ordered
How does a merge sort work?
Finds the middle item by (n+1)/2 Splits the list in half Repeats until items are paired Each time the sub-list are paired They are sorted into the correct order
How does an insertion sort work?
Looks at 2nd item in the list and compares it to the items that are in front of it
Then inserts it into the right place correctly
It is Quick for sorting small lists
What is the shape of the input box?
Parallegoram
What is the shape of a decision making?
Diamond
What is the shape of the process?
Rectangle
What does the lines show?
The control passing betweens the connected shapes
How do you output an statement?
Print(“hello”)
How do you do a for loop in OCR Reference language
For i = 0 to 7
…
next i
What are the comparison operators?
== Equal to != Not equal to < Less than <= Less than or equal to > Greater than >= Greater than or equal to
What does 12 MOD 5 give?
2 - Because the MOD function always returns the remainder
What does 12 DIV 5 give?
2 - DIV functions returns how much a number goes into another number - excluding remainders
How do you do an IF - THEN - ELSE in OCR Exam Reference Language?
If x== 6 then ... elsif .. then .. else ... endif
How do you do an CASE SELECT or SWITCH?
Switch x: case "a": .... case "b": ... default: (Same as an else equivalent) endswitch
How do you get a length of a spring?
Variable.length
How do you get “put” from subject = “ Computer Science”
subject.substring(3,3))
will start at position p - because the string starts at the 0th character
then count the character its on and go 2 along
which will print out put
How do you make a string in all upper cases?
String.upper
How do you make a string in all lower cases?
string.lower
What is an example of a procedure?
procedure name(..)
…
endprocedure
What is an example of a function?
function name(..) ... return ... endfunction
How do you call a function?
function(parameters)
How do you call a procedure?
procedure(parameters)
How do you establish an array?
array name[5] - example
array name[number of boxes]
How do you declare a 2D array?
For example
array board[8,8]
How do you make a random number?
myVariable = random(1,6)
How do you open a file?
For example:
myFile = open(“sample.txt)
How do you close a file?
myFile.close()
How do you read/write a file?
Myfile.readLine( )
Myfile.writeLine(..)
How do you end a file/ create a file?
myFile.endOfFile()
newFile()
What are syntax errors?
Errors which break the grammatical rules of the programming language
Stop it from being run
What are logic errors?
Errors that produce an unexpected output
On their own they won’t stop a program from running
What are the advantages of constants?
Can make a program easier to read
Compiler can optimises the code
Less chance of errors
What is a sequence?
Executing instructions one after another
What is selection?
Program branching depending on the condition
What is iteration?
Looping - repeating sections of the code
When are FOR loops used?
Number of iterations needed is known ahead of the iteration executing
When are WHILE loops used?
When the number of iterations is not known