Algorithms + Programming Languages (Week 5) Flashcards
What do many problems in computer science involve?
Searching for data, e.g. text search in Word document, Google search, etc.
How does Binary Search work? Assume the list is already sorted.
Step 1: Identify the middle of the list and split it into two halves
Step 2: If the element we look for is earlier/later in the alphabet than the middle, reduce the list to the lower/upper half
Step 3: Continue with step 1 unless the list contains only 1 element
Step 4: element found
Definition : Runtime Complexity
A function that describes the amount of time it takes to run an algorithm.
What is the Runtime Complexity of Binary Search?
Log2 N
How common of a task is sorting data items?
A) Very common
B) Not common
C) Never done
A) Very common
What are some methods of sorting?
Quicksort, Bubble sort, Selection sort
What is the Runtime Complexity of Quicksort?
N x Log2 N
What is the Runtime Complexity of Bubble sort?
N^2
What is the Runtime Complexity of Selection sort?
N^2
Definition : “Easy” Problem
Algorithms with runtime complexities like Log N, N, N × Log N or N2 - these complexities are called polynomial.
Problems that can be solved by algorithms with a complexity that looks like Nx are considered to be “easy” – N is a factor in this formula.
Definition : “Hard” Problem
“Hard” problems can only be solved by algorithms with exponential runtime complexity like this: x^N (N is an exponent here, e.g. 2^N)
Nature of exponential problems: if problem size increases by 1, runtime multiplies, e.g., doubles, triples, quadruples etc.
What situations would need a fast solution?
e.g., brake or swerve
What situation would need a slow solution?
e.g. cryptography (decrypting data without knowing the key is “hard”)
What are some possible runtime complexities?
From fastest to slowest :
Log N
N
N x Log2 N
N^2
2^N
What are computers? (In terms of what they are able to process)
Computers are general purpose computing machines – without software, they don’t know what to do
Definition : Software
The term “software” refers to instructions that make a computer do something useful => the “program”
Data is also considered to be software
Differences between hardware and software?
Software is intangible – it is not easy to see or put your hands on a sequence of bits (e.g. represented by electrical signals)
Software is more flexible, easier and often cheaper to change (update) than hardware.