810 likes | 1.06k Views
Abstraction and Abstract Thinking Part 1 “Algorithms” Part 2 “Abstract Networks”. Recap Statement of The Problem Theory of the Problem Modelling of the Problem Algorithmic description Programming the Algorithm Executing the Program. Future delights. today. done. done. Abstraction.
E N D
Abstraction and Abstract Thinking Part 1 “Algorithms” Part 2 “Abstract Networks”
Recap Statement of The Problem Theory of the Problem Modelling of the Problem Algorithmic description Programming the Algorithm Executing the Program Future delights today done done
Abstraction The ability to separate the high level view of an entity or an operation from the low-level details of its implementation.
Abstract Process / (Data) Non-Abstract Process / (Data)
A Fun Algorithm Take the first three digits of your phone number and multiply by 80 Add 1 to the result Now Multiply by 250 and add the last 4 digits of your phone number Add the last 4 digits of your phone number again Subtract 250 and divide by 2. What do you see?
A Serious Algorithm – Sum of a List Get the list of numbers Set sum to zero Move through the list until it is ended get the next number in the list add it to the sum Output the sum
A fun Algorithm - Stable Marriage The Gale-Shapley algorithm involves a number of iterations. Each unengaged man proposes to the preferred woman to whom he has not yet proposed. Each woman then considers all her suitors and tells the one she most prefers "Maybe" and all the rest of them "No". She is then provisionally "engaged". In each subsequent round, each unengaged man proposes to one woman to whom he has not yet proposed. The women once again replies with one "maybe" and rejects the rest.
Stable Marriage - Example A W B X C Y D Z A W B X C Y D Z A W B X C Y D Z A W B X C Y D Z
A W B X C Y D Z A W B X C Y D Z A W B X C Y D Z A W B X C Y D Z A W B X C Y D Z
Definition of an Algorithm An algorithm is a well-ordered collection of unambiguous and effectively computable operations that, when executed, produces a result, and halts in a finite amount of time. Schneider and Gersting (2004). Algorithms are concepts which exist outside programming languages. They are abstract method for computing something, whereas a program is an embodiment of this method. Donald Knuth (1966)
Is this an Algorithm? • Consider this example taken from the instructions on the back of a shampoo bottle: • Wet hair • Lather • Rinse • Repeat
Algorithmic Process Non-Algorithmic Process
Examples of Recent Serious Algorithms • Matching of kidney donor – recipients • Traffic-flow engineering • Cancer Research. Examples of “Standard” Computing Algorithms (1a) Sequential Search (1b) Binary Search (2a) Selection Sort (2c) Quicksort
Sequential Search Algorithm - Description Anne Bob Carol Daniel Grant Nathan Sue
Sequential Search Algorithm - Example Anne Bob Carol Daniel Grant Nathan Sue
Binary Search Algorithm - Description • Get the list of names 1,2,3,…N • Set “begin” to 1 and “end” to N • Set “found” to no • While “found” is no • Set “m” to middle value between “begin” and “end” • If “name” is “asked name” • Set “found” to yes • Else if “name” precedes “asked name” set “end” = m - 1 • Else set “begin” to m + 1
Binary Search Algorithm - Example Anne Bob Carol Daniel Grant Nathan Sue
Binary Search (Tree Representation) Daniel Bob Nathan Anne Carol Grant Sue
Depth of a Binary Tree (complete) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 4 2 6 1 3 5 7
Depth of a Binary Tree (incomplete) 1 2 3 4 5 6 7 8 4 2 6 1 3 5 7 8
Selection Sort Algorithm - Description • Get the list of numbers • Put the wall at the beginning • While there are more elements in the unsorted part • Find the smallest element • Swap with the first element in the unsorted part • Move the wall one element to the right
Quick Sort Algorithm - Description • Get the list • Choose a “pivot” from the list • Move all elements less than the pivot to the left of the pivot and the greater elements to the right of the pivot. • Recursively apply 2,3 to the sub-lists generated