Please enable JavaScript.
Coggle requires JavaScript to display documents.
computer science paper 1 - Coggle Diagram
topic 2 (programming)
Data types
-
Data type: integer - INT, real = REAL, Boolean = BOOL, character = CHAR, string = STRING
Operators
-
+= +, - = -, x = *, division = /, integer division = DIV, eg 20 DIV 6 = 3. Remainder = 20 MOD 6 = 2. DIV is the whole number it goes into. MOD just gives the remainder
Computers follow to rules of BIDMAS e.g 2 + 8 2 will give 18. To do the addition first, (2 + 8) 2 will give 20
Constants and variables
Data values can be stored as constant or variables. A constant is assigned a value at design time that can’t be changed. If you attempted to change the value of a constant in a program, the interpreter or compiler will return with error.
-
Strings
-
-
-
-
Fro example, SUBSTRING(0,2, town) <- this extracts the first 3 characters from the customers town
Strings are made up of multiple characters. These can consist of letters, numbers, spaces, symbols etc.
Selection
The flow of a program in the order the steps are carried in. One way you can control the program flow is by using selection statements.
Iteration
-
-
Iteration allows algorithms to be simplified by stating that certain steps will repeat until told otherwise. This makes designing algorithms quicker and simpler because they don’t need to include lots of unnecessary steps.
-
Random number generation
an example is: dice ← RANDOM_INT(1,6)
OUTPUT “you rolled a ” + INT_TO_STRING(dice) + “!”
Sometimes a programmer needs the program to generate a number or letter within a specific range. This requires the program to create a random number. Programming games that involve chance, such as dice, require random numbers as do many types of program that need to be unpredictable.
Arrays
-
An array is a data structure that holds similar, related data. An array is like a collection of boxes, each of which is called an element . Each element has a position in the array, and can hold a value. The data in an array must all be of the same data type .
a linear data structure that collects elements of the same data type and stores them in contiguous and adjacent memory locations.
-
-
-
topic 1 (algorithms)
computational thinking
decomposition, breaking a comples probelm down into smaller ones
abstraction- picking out the important bits of infomation from the problem, ignoring the specific details
algorithmic thinking- a logical way of getting from the problem to the solution. if the steps you take to solve a problem follow an algorithm, they can be reused
-
-
search algorithms
binary search
1) find the middle item in the ordered list 2) if this is the item your looking for, then stop the search - youve found it. 3) if not, compare the item your looking for to the middle item. if it comes before the middle item, get rid of the second half of the list. if it comes after the middle item, get rid of the first half of the list. 4) you will be left with a list half the size, keep finding the mid point of this even smaller list until you get your item
linear search
1) look at the first item, in the unordered list 2) if this is the item your looking for, then stop the search - you've found your item. 3) if not then look at the next item in the list 4) keep repeating these steps until you've found the item that your looking for until youve found your item
sorting algoithms
bubble sort
-
compare each pair and swap them until the list is sorted ( bold fonts represents each pair being swapped/ sorted)
PROS :check: : simple algorithm that can be easily implimented on a computer. its an efficient way to check if a list is already in order. doesnt use much memory as all the sorting is done in the original list
CONS :red_cross: : it is an effiecent way to sort a list. due to it being inefficent, the bubble sort algorithm is pretty slow for very large lists of items
merge sorts
1) split the algorithm in half (these 2 smaller lists are called sub lists)- the second sub-list should start at the middle item. 2) keep repeating step 1 on each sub list until all the lists only contain one item. 3) merge pairs of sub-lists so that each sub list has twice as many items. Each time you merge the 2 sub lists, sort the items into the right order.4) keep repeating until you have merged all the sub lists together.
-