paper 2 Flashcards
decomposition
Decomposition: Breaking down a problem into smaller parts which are easier to understand. These smaller parts can be individually solved as they are easier to comprehend, for example creating an app would need graphics, audio, software used to create it, testers, user interface…
abstraction
Abstraction: filtering out and ignoring the parts of problems which are not needed to solve a problem. It is effectively a general overview of the program with specific details removed, for example, the London Underground map.
algorithmic thinking
Identifying the steps involved in solving a problem.
algorithm
An algorithm is a step-by-step set of instructions used to solve a problem. Before designing an algorithm, it must be decomposed into its inputs, outputs and the order of instructions, as well as if any decisions need to be made.
how can algorithms be made
pseudocode
flowcharts
high level language
flowchart symbols
Lines represent the flow of the program.
Parallelograms show inputs and outputs.
A rectangle shows a process, for example, x = x + 10
A diamond represents a decision, for example, if x > y. Then there would be 2 lines coming from this, one for yes and one for no.
A rectangle with curved sides represents a terminal, such as the start or end of the program.
subroutine - square with lines on ends.
Sequence that performs a specific task. You can use this within your flowchart to show more detail in a specific section
avanatge flowchart
Advantages of using flowcharts include the fact that they show a step-by-step method of how to solve a program, which can be easily written.
disavantage flowchart
Disadvantages of flowcharts include that they may be time-consuming to make and not easily drawn.
avantage pseudocode
The advantages of using pseudocode include it acts as the foundation for transcribing it into an actual programming language and is easy to understand with an English-like syntax, making it easy for non-programmers as well. Errors in the design will not affect the program as it is obvious what the intended result is, and if there is an obvious error this can be easily changed.
disavantge pseudocode
Disadvantages include that it can be harder to see how a program flows with indentation, and is just more time-consuming to make than a flowchart, so you might as well use Python for that.
trace table
A trace table is a table used to show how values in variables change throughout instructions occurring.
what goes where in trace table
In the columns goes the variable name. In the rows, the instruction number is written. Below the variable names, in the table, are the expected values of what each instruction does.
when does logic error occur on trace table
A logic error occurs if the expected value on paper does not equal the received value when executed by the program.
linear search
The simplest method of searching through a dataset. It gets the length of a dataset and sets it counter to 0. It looks at the position of its counter and sees if it matches the search. If not, the counter is incremented by 1 and the process is repeated
Linear searches work on unordered lists. On ordered lists, they will take a long time if the value to search for is a large number.
binary search
Binary search is used on a dataset of ordered numbers. It works by:
getting the midpoint in the list, getting the value, and if it is the target value the search ends.
If not, it will compare the received value. If the value is less than the value to be found, it will disregard the lower half of the list, as it knows it cannot be lower than the midpoint value.
The remaining part of the list is divided in half again, and the process is repeated.
When the value is found, the search has succeeded.
Binary searches are much more efficient than linear searches, especially on large datasets.
what is sequence
Sequence refers to the order in which the code is executed.
bubble sort
Start at the beginning of the list, compare the value at position 1 to the next one up (at position 2).
Swap the positions of these if the second is bigger than the first.
Then, move both positions up one, to position 2 and 3.
Swap if they are in the wrong order.
Repeat until the end of the list.
Start back from the beginning and repeat this until it is in order.
basic programming definiitinos
Variables: A value stored in memory that can change.
Constants: A value stored in memory that cannot change once defined.
Operators: Logic applied to numbers, e.g. equal, subtract, less than.
Inputs: data inputted to programs. In Python, x = input(“enter string: “)
Outputs: data the program shows to users. print(“output”)
Assignment: giving a value data. e.g. x = 2. You are assigning the value x to the data, which is 2, an integer.
what is selection
Where a choice is made in a program depending on a condition or outcome
pattern recognition
used to identify where the constructs such as selection and iteration could be used, where functions and procedures can be reused, reuse code from past programs to carry out similar functions in new program.
merge sort
Split the list in half repeatedly until all values are separate
Compares two values next to each other and organise.
Go to the next pair of values and repeat. If something is smaller than the existing smallest value, then place it there instead. (Same with biggest values)
Repeat until all values are in order
large data sets better w/ merge sorts as theyre more efficient
insertion sort
More efficient than bubble sort, but less complex and efficient than a merge sort
Compare values of 1 and 2.
If 1 is bigger than 2, then 2 is moved to the start.
Compare the values of 2 and 3. Move 3 to the left until it cannot be moved any more as the number is smaller than it.
Repeat for all values.
Insertion sorts work best when used with smaller data sets.
what is iteration
Iteration is a loop. There are count and condition-controlled loops.
whats !=
!=
Not equal to. Only True when the value it is comparing against is NOT the first value.
opoerators
There are comparison and arithmetic operators. (They will give the boolean value of True if their criteria are met)
count conrolled loops
Count-controlled loops are controlled by a number. For example, if x > 10: will run until the value of x is greater than 10.
whats <
<
Less than. Only True when the value in front of it is less than the value after it. if x < 3 means if x is less than 3.
whats >
> Greater than. Only True when the value in front of it is more than the value after it. if x > 3 means if x is greater than 3.
condition controlled loops
Condition-controlled loops are controlled by a specific value. This is most often True or False; these will run until this value is changed. For example, if x == True: will run the code until the value ofx is no longer equal to True.
what is ==
==
Equal to. Used only to check if a value is something else. Do not get confused with a single equals which is used to specify a value.
whats <=
<=
Less than or equal to. Only True when the value in front of it is less OR equal to the value after it.
what are: ==, !=, <, >, <=, >=
compariosn operators
data types
Integer: Positive or negative whole numbers
Real/float: Numbers with decimal places
Boolean: True or False (1 or 0)
Character: A single character
String: Numbers and letters together.
how to obtain length of string using string manipulation
The length of a string can be obtained by doing len(string), where string is a variable holding a string value.
whats >=
> =
Greater than or equal to. Only True when the value in front of it is more OR equal to the value after it.
boolean operators
AND - only True when the two values are True.
OR - only True if one or more values are True.
NOT - everything that is not the value.