1 Flashcards
what is a binary search?
looks for items in an ordered list
how does binary search work?
compare your number to the middle one
if it comes before the middle, get rid of the second half
if it comes after, get rid of the first half
repeat until you get your number
what is a linear search?
used to find items in an unsorted list
how does a linear search work?
checks each item to see if it is the correct one
if it is, it stops
if it isn’t, it continues checking until it finds it or has checked the entire list
what is a search algorithm?
computers use them to find items in a list
examples of search algorithms
binary search
linear search
what is a sorting algorithm?
used to order lists of values
examples of sorting algorithms?
bubble sort
merge sort
insertion sort
what is bubble sort?
used to sort an unordered list
how does bubble sort work?
compares two values at a time, keeps going through the list even after swapping two values
pros of bubble sort?
simple algorithm
efficient way check numbers are in order, only has to check once
doesn’t use much memory as it is done using the original list
cons of bubble sort?
inefficient way to sort a long list
what is merge sort?
divide and conquer algorithm
splits the list apart then merges it back together
how does merge sort work?
split the list in half into sub-lists until each sub list contains one item
merge pairs of sub lists and order them
repeat until you’ve merged all the sub lists together
pros of merge sort?
much more efficient and quicker than bubble
consistent running time regardless of amount of numbers
cons of merge sort?
slower than others on small lists
even if the list is sorted it goes through the whole process - taking a long time
uses more memory to create separate lists
what is insertion sort?
orders items by following one item through the list until it is in the correct place
how does insertion sort work?
follows one item until it is in the correct place then goes back to the start and follows the next number
pros of insertion sort?
can be easily coded
good with small lists
doesn’t need much additional memory
quick to check an already sorted list
integar
code, characteristics, example
int
whole number
6, 204, -987
real/float
code, characteristics, example
real
decimal number
1.00, 4.5, -7.8
boolean
code, characteristics, example
bool
either true or false
true/false, yes/no, 1/0
character
code, characteristics, example
char
a single letter, number or symbol
A, 8, !
string
code, characteristics, example
string
a collection of characters
isla!, pizzaisready, 7Azo59!?
what is casting?
changing between data types
what is DIV?
how many times the number can go into the other, without a fractional part
what is MOD?
the remainder after division
= meaning
assigns the variable to a number
eg: age = 25
== meaning?
checks if the variable/value is equal to it
eg: age == 25 (checks if age is 25)
what is a variable?
stores a value that can be changed
what is concatenation?
joining together two strings
what is the process of joining together two strings?
concatenation
how to concatenate?
use a + within speech
EG:
string1 = “my fave colour is”
string2 = “red”
newstring = string1 + “ “ + string2
print(newstring)
PRINTS: my fave colour is red
x.upper
changes all characters in string x to uppercase
eg: HELLO
x.lower
changes all characters in string x to lowercase
eg: hello
x.length
returns the number of characters in string x
eg: 5
what is an IF statement?
contains a condition
if
elif
else
what is a FOR loop?
repeats a section of code a certain number of times
what is a WHILE loop?
controlled by a condition which must be true
types of boolean gates?
AND
OR
NOT
what is an AND gate?
both inputs must be true for the outcome to be true
what is an OR gate?
only one input has to be true for a true outcome
what is a NOT gate?
output is the opposite of the input
AND gate diagram
__
——| \__
——|__/
OR gate diagram?
___
—–\ \___
—–/___/
NOT gate diagram
_____|\______
|/
what is an array?
a data structure that can store a collection of similar data values under one name
what is “for i in range”
repeats the section of code however many times
eg: for i in range(5)
repeats five times
how to open a file in code?
file = open(“file.txt”)
what is a record?
stores a collection of different data types in a data structure
what is a field?
an item in a record with a data type
what does SQL stand for?
structured query language
what is SQL?
used to search tables for specific data and output it
how to do SQL?
SELECT
FROM
WHERE
what is a sub program?
small programs within a larger one used to save time and simplify code
what is a procedure?
a set of instructions stored under one name
what is a function?
set of instructions that return a value
what is a parameter?
special variables used to pass values into a sub program
what is an argument?
the actual values that a parameter takes when a sub program is called
example of a parameter?
(name)
(age)
what is a local variable?
can be used within the structure they’re declared in
local scope
what is a global variable?
can be used any time after their declaration
global scope