Presentation is loading. Please wait.

Presentation is loading. Please wait.

Abstraction & Automation

Similar presentations


Presentation on theme: "Abstraction & Automation"— Presentation transcript:

1 Abstraction & Automation
Theory of Computation Abstraction & Automation

2 Theory of Computation: Abstraction & Automation
Problem Solving A key part (arguably the key part) to being a computer scientist is in being able to solve problems Not so much programming More thinking about how a problem could be solved We call this Problem Solving, and typically involves two steps (that have sub-steps) Analysing a problem Designing a solution Theory of Computation: Abstraction & Automation

3 Theory of Computation: Abstraction & Automation
Problem Solving We’ll start simple and work out way up The first thing we need to be able to do is solve ‘simple’ logic problems And check our solutions for them This involves being given a small problem, then stating how we would solve them Theory of Computation: Abstraction & Automation

4 Theory of Computation: Abstraction & Automation
See if you can come up with a good solution for the following problem Be sure to discuss amongst the whole class! A group of philosophers are out to lunch in a fancy restaurant. Each philosopher can do only one of two things at a time: think and eat. They are around a circular table, with bowls of spaghetti in front of them. To the left and right of each philosopher is a fork. A philosopher can only eat if they use both forks. Think of a system the philosophers can use so that they eat as often as possible (before they starve)! Theory of Computation: Abstraction & Automation

5 Theory of Computation: Abstraction & Automation
Problem Solving There’s no wrong answer to this problem But some solutions are better than others Here is one possible way of solving this problem Start with a random philosopher around the table, and let them pick up both forks to eat with. After an arbitrary amount of time, make them put down their forks and move over to the next philosopher clockwise! Theory of Computation: Abstraction & Automation

6 Theory of Computation: Abstraction & Automation
Creating Algorithms Any time we create a solution for a problem, we have different ways of representing that solution Two such ways are Pseudocode Flowcharts An important term to bring up before looking at these is algorithm “A sequence of steps that can be followed to complete a task, and that always terminates” Theory of Computation: Abstraction & Automation

7 Theory of Computation: Abstraction & Automation
Creating Algorithms The strict definition of an algorithm simply means listing the steps required to solve a problem There is no requirements on the representation of these steps We could write a paragraph of text, list the steps in bullet-point form, and more Paragraphs of text are not the best formats to use Makes the steps difficult to spot or understand Theory of Computation: Abstraction & Automation

8 Theory of Computation: Abstraction & Automation
Creating Algorithms This is where those two representation formats we mentioned earlier come in We will focus on pseudocode for the A Level Means “fake code” Is syntactically similar to most programming languages Though nowhere near as strict Theory of Computation: Abstraction & Automation

9 Theory of Computation: Abstraction & Automation
Creating Algorithms Let’s take the philosopher solution example from earlier and turn it into pseudocode BEGIN FeedPhilosophers(philosophers) startingPhilosopher  RANDOM(0, SIZE(philosophers)) currentPhilosopher  startingPhilosopher BEGIN DO FeedPhilosopher(philosophers, currentPhilosopher) currentPhilosopher  currentPhilosopher + 1 IF currentPhilosopher > SIZE(philosophers) currentPhilosopher  0 END IF END WHILE(currentPhilosopher != startingPhilosopher) END FeedPhilosophers Theory of Computation: Abstraction & Automation

10 Theory of Computation: Abstraction & Automation
Creating Algorithms Some things to note here We still use indentation To show scope We begin and end scope Keywords are capitalised BEGIN FeedPhilosophers(philosophers) startingPhilosopher  RANDOM(0, SIZE(philosophers)) currentPhilosopher  startingPhilosopher BEGIN DO FeedPhilosopher(philosophers, currentPhilosopher) currentPhilosopher  currentPhilosopher + 1 IF currentPhilosopher > SIZE(philosophers) currentPhilosopher  0 END IF END WHILE(currentPhilosopher != startingPhilosopher) END FeedPhilosophers Theory of Computation: Abstraction & Automation

11 Theory of Computation: Abstraction & Automation
Take the solution you created earlier and turn it into pseudocode Don’t worry too much about the correct words to use for now Just turn it into something that looks like code We’ll look at pseudocode standards after this exercise Theory of Computation: Abstraction & Automation

12 Theory of Computation: Abstraction & Automation
Pseudocode Standards Every construct usable in a programming language can be included in pseudocode too This includes Sequence Selection Iteration To make all pseudocode easy to read (especially when reading different algorithms), standards are used Theory of Computation: Abstraction & Automation

13 Theory of Computation: Abstraction & Automation
Pseudocode Standards First, we use capital letters for keywords Starting/ending scope Using constructs Use the arrow () symbol to represent assignment Leaving equals (=) for equality checking OUTPUT FOR WHILE IF FOR EACH DO ELSE ELSE IF WHILE playing IF number is even … … END WHILE END IF pivot ← length / 2 Theory of Computation: Abstraction & Automation

14 Theory of Computation: Abstraction & Automation
Create a solution for the following problem (and represent it using pseudocode) “Given two numbers (which are assigned the words Fizz and Buzz respectively), how could we output the numbers from 1 to 100, replacing the number with Fizz and/or Buzz whenever it is a multiple of them? Theory of Computation: Abstraction & Automation

15 Pseudocode to Programming Language
If we use the given standards for pseudocode, converting pseudocode to a programming language is relatively simple Depending on the programming language we use As we use the name of the construct in the pseudocode, we simply write code for that construct in the language As the pseudocode works in a sequence, we also write the code in the same order Theory of Computation: Abstraction & Automation

16 Pseudocode to Programming Language
BEGIN FeedPhilosophers(philosophers) startingPhilosopher  RANDOM(0, SIZE(philosophers)) currentPhilosopher  startingPhilosopher BEGIN DO FeedPhilosopher(philosophers, currentPhilosopher) currentPhilosopher  currentPhilosopher + 1 IF currentPhilosopher > SIZE(philosophers) currentPhilosopher  0 END IF END WHILE(currentPhilosopher != startingPhilosopher) END FeedPhilosophers Python Java C# Theory of Computation: Abstraction & Automation

17 Theory of Computation: Abstraction & Automation
Implement your algorithm in a programming language Python, Java, or C# Don’t worry about testing it Only make sure there are no syntax errors Theory of Computation: Abstraction & Automation

18 Theory of Computation: Abstraction & Automation
When it comes to creating a solution for a problem, there may be times when there is too much information Data that isn’t needed for the solution Stripping away (or hiding) this information is known as abstraction Keeping only the key details/pieces of information needed to solve the problem There are multiple types of abstraction, that deal with removing different details Representational Abstraction Abstraction by Generalisation/Categorisation Theory of Computation: Abstraction & Automation

19 Representational Abstraction
This type of abstraction involves removing unnecessary information from the problem itself For example, if the problem involves calculating the number of computers needed in a lab, we may not need to know The tutor’s name The types of computer What programs the computers will be running If this information is included in the problem, we can hide it and only focus on the bits we need Theory of Computation: Abstraction & Automation

20 Representational Abstraction
For example, take this problem Casey is playing a game with her students in school. She has six boxes in front of her, each for a subject (Maths, Biology, Physics, Chemistry, Geography, and History). She asks one of her students to roll a die, and depending on the number picks a random question from one of the boxes (1  Maths, 2  Biology, 3  Physics, 4  Chemistry, 5  Geography, 6  History) and then asks the student that rolled the die that question. If they get it right, they earn a point. If they don’t, any student can answer the question (and earn a point if they get it right). In either case, the next student rolls the die and repeats the same steps. Theory of Computation: Abstraction & Automation

21 Representational Abstraction
We can ‘cross out’ any unnecessary information (leaving only what we need to solve this problem) Casey is playing a game with her students in school. She has six boxes in front of her, each for a subject (Maths, Biology, Physics, Chemistry, Geography, and History). She asks one of her students to roll a die, and depending on the number picks a random question from one of the boxes (1  Maths, 2  Biology, 3  Physics, 4  Chemistry, 5  Geography, 6  History) and then asks the student that rolled the die that question. If they get it right, they earn a point. If they don’t, any student can answer the question (and earn a point if they get it right). In either case, the next student rolls the die and repeats the same steps. Theory of Computation: Abstraction & Automation

22 Representational Abstraction
Can also apply to remove details from an object For example, we have a cat Certain fur colour Tail length Eye colours We don’t need to know the details Only the general structure Also an example of information hiding Though more obvious on practice Used in public, private, protected Theory of Computation: Abstraction & Automation

23 Abstraction by Generalisation
This type of abstraction impacts the design of the solution more than the problem itself It’s main goal is to put pieces of information in a problem into categories And the state how they relate to each other in some way Generalisation/categorisation works hand-in-hand with object-orientated-programming Theory of Computation: Abstraction & Automation

24 Abstraction by Generalisation
For example, we’re working on a solution that involves collecting cats We have a Cat class for this We could collect these cats in different ways Arrays, Lists, LinkedLists, Stacks, Queues, etc. Making a ‘groom’ function to apply to a series of cats would be tedious groom(Cat[]), groom(List<Cat>), groom(LinkedList<Cat>), etc. We can make a more general function that applies to a whole range of possibilities groom(Collection<Cat>) Theory of Computation: Abstraction & Automation

25 Abstraction by Generalisation
This also applies in inheritance Imagine we have different animals that we want to groom Dogs, Lizards, Birds We can make each one an Animal Then apply the function to that groom(Collection<Animal>) Theory of Computation: Abstraction & Automation

26 Abstraction There are more types of abstraction techniques too
That involve different aspects of the problem/solution These are Procedural Abstraction Functional Abstraction Data Abstraction Problem Abstraction/Reduction Involving the solution Involving the problem Theory of Computation: Abstraction & Automation

27 Procedural Abstraction
Goes hand-in-hand with decomposition We’ll see that later Involves breaking parts of a solution off into their own procedure Takes the ‘complexity’ away from the actual solution Means we don’t need to know how that part is done Only that it works as intended A very important part to any complex solution The procedure we make ends up not caring about the data used Only how it works We supply the data when we run this procedure Here register_user is the abstracted procedure Theory of Computation: Abstraction & Automation

28 Functional Abstraction
This is a variant of Procedural Abstraction Involves functions instead of procedures That means a value is expected after running the function Here length_between_points is the abstracted function Theory of Computation: Abstraction & Automation

29 Theory of Computation: Abstraction & Automation
Data Abstraction This is all about hiding how specific data-types/data-structures work from the user They can still use it But do not need to know how it works For example, we could create a MyList class Acts like a List (dynamic storage of values) It works by making an array and recreating arrays every time an item is added/deleted The user doesn’t need to know this Only that the MyList dynamically resizes Theory of Computation: Abstraction & Automation

30 Problem Abstraction/Reduction
Occurs more in mathematical problems than others Used when a problem may be difficult to solve Involves transforming a problem into a different problem Which is easily solvable We then use the result of solving that problem in the solution for the original problem For example, if we’re calculating the Lowest Common Multiple of two numbers Can find the Greatest Common Divider instead Then use it in a calculation to get the Lowest Common Multiple GCD/LCM Example Find Lowest Common Multiple of 24 and 36: Find Greatest Common Divider first: 12 Use in calculation: (23 * 36) / 12 = 72 So Lowest Common Multiple is 72 Theory of Computation: Abstraction & Automation

31 Theory of Computation: Abstraction & Automation
(De)Composition The final aspect of abstraction is the idea of a problem’s makeup Its composition If a problem is too big/complex to tackle in one chunk We break it down into smaller chunks Technically, this is breaking down its composition Known as decomposition Theory of Computation: Abstraction & Automation

32 Theory of Computation: Abstraction & Automation
(De)Composition When decomposing a problem, it’s worth finding the key areas For example, the Binary Search algorithm has two distinct steps Order the collection (from least-to-greatest or greatest-to-least) Continuously divide the list in two until the item is found, or not found We can tackle these in two different functions sortItems searchForItem And can then run them from a single function binarySearch This is an example of Composition Abstraction Combining procedures/functions to form compound procedures/functions Theory of Computation: Abstraction & Automation

33 Theory of Computation: Abstraction & Automation
(De)Composition We can also apply Composition Abstraction to create more complex data types From simpler ones That’s Object-Orientation! For example, we could make a Dog data-type From integers, strings, and other primitive types The same applies to data-structures (like Graphs and Trees) Theory of Computation: Abstraction & Automation

34 Theory of Computation: Abstraction & Automation
All of this problem/solution abstraction feeds into a very interesting topic in computer science Automation Generally put: involves making systems that can create/monitor other systems, or solve problems, without any human input Quite a common example comes in the form of automated cars Theory of Computation: Abstraction & Automation

35 Theory of Computation: Abstraction & Automation
Computer scientists have been looking into automating cars for a few years Involves huge amounts of complexity, as systems need to think about Cars around the system Traffic rules in the area Objects around the system They need to be able to recognise other vehicles and objects So they know how to act in different situations Theory of Computation: Abstraction & Automation

36 Theory of Computation: Abstraction & Automation
We’re bringing this up now because automation relies on thorough abstraction On the visual recognition side, a camera in an automated car needs to be able to recognise other cars Cars can have different makes, models, sizes, colours, and more Proper abstraction needs to be put in place so a camera can recognise any car Can take lots of work, involving other aspects of computer science Like Genetic Programming Theory of Computation: Abstraction & Automation

37


Download ppt "Abstraction & Automation"

Similar presentations


Ads by Google