COEN201 Algorithm Development 2021 2022
COEN201 Algorithm Development 2021 2022
COEN201
COMPUTATIONAL THINKING
2021 - 2022
1
Computational Thinking teaches students
how to:
✓ Describe a problem
Pupil
responds
Is the
Say that s
Answer
wrong
correct?
❑A compact and informal high level ✓ Search Engines such as Google or Bing
✓ Combine ingredients
information you want is an essential if it’s the right word, and repeat this
possible to perform many tasks online, checking each word in turn until we get
Internet selling the perfect coffee pot ✓ we could pick a word in the middle,
for your office. decide whether our word is before or
after that, pick a word in the middle of
that half, and keep narrowing down
Random Search Start
No
Stop
Linear Search
Linear Search
Stop
Start Binary Search
Binary Search
Set lower limit
✓This search algorithm works on the principle
Set upper limit of divide and conquer.
Is
Stop number < No
collection.
guess?
✓If a match occurs, then the index of item is
Yes
returned.
Set upper =
Set lower = guess
guess - 1 ✓If the middle item is greater than the item,
then the item is searched in the sub-array to
the left of the middle item
17
Binary search versus Linear Search
SEARCHING ALGORITHMS
Brute Force Algorithm Common Brute Force Algorithm
simplest possible approach to solving the ✓This technique begins at the root node,
problem. explores each of the child nodes first, and
✓The advantage of this approach is that you only then moves down to the next level.
don’t need any domain-specific knowledge to ✓It progresses level by level until it finds a
use one of these algorithms. solution.
✓The disadvantage is that a brute-force ✓Advantage: it can check for duplicate nodes,
approach works well only for a small number which saves time, and it always comes up
of nodes. with a solution.
f(n) = h(n)
22
Greedy Algorithm Applications of Greedy Algorithm
❑A greedy algorithm always makes the choice
❑Optimal solutions:
that looks best at the moment
✓Change making for “normal” coin
❑Examples:
denominations
✓Playing cards
✓Minimum spanning tree (MST)
✓Invest on stocks
✓single-source shortest paths
✓Choose a university
✓Simple scheduling problems
❑Two elements are essential for distinguishing
✓Huffman codes
a greedy algorithm:
❑Approximations
✓At each turn, you always make the best
decision you can at that particular instant. ✓Traveling salesman problem (TSP)
decisions results in the best final solution. ✓Other combinatorial optimization problems
23