Abstraction & Automation

Slides:



Advertisements
Similar presentations
Chapter 2 - Problem Solving
Advertisements

8 Algorithms Foundations of Computer Science ã Cengage Learning.
Computer Science 1620 Programming & Problem Solving.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
General Programming Introduction to Computing Science and Programming I.
CS1Q Computer Systems Lecture 8
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Algorithms and Pseudocode
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
All materials copyright UMBC unless otherwise noted CMSC201 Computer Science I for Majors Lecture 02 – Algorithmic Thinking.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
AP CSP: Creating Functions & Top-Down Design
Recursion Version 1.0.
Software Development.
Introduction to Computing Science and Programming I
CMSC201 Computer Science I for Majors Lecture 02 – Algorithmic Thinking Prof. Katherine Gibson Based on slides by Shawn Lupoli and Max Morawski at UMBC.
Algorithms and Problem Solving
3.1 Fundamentals of algorithms
Topics Designing a Program Input, Processing, and Output
Top 50 Data Structures Interview Questions
Basics of Computer Programming
Chapter 2: Input, Processing, and Output
7 - Programming 7P, Q, R - Testing.
GC211Data Structure Lecture2 Sara Alhajjam.
ALGORITHMS AND FLOWCHARTS
UNIT 3 – LESSON 5 Creating Functions.
Teaching design techniques to design efficient solutions to problems
Introduction to Programmng in Python
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Algorithm and Ambiguity
Print slides for students reference
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Problem Solving Techniques
Introduction to Computer Programming
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Objective of This Course
Fundamentals of Programming
Coding Concepts (Sub- Programs)
Theory of Computation Turing Machines.
Coding Concepts (Data Structures)
Theory of Computation Languages.
Topic 1: Problem Solving
We’re moving on to more recap from other programming languages
Computational Thinking for KS3
Coding Concepts (Basics)
Topic 1: Problem Solving
Coding Concepts (Standards and Testing)
Fundamentals of Data Representation
Topic 1: Problem Solving
Coding Concepts (Data- Types)
Algorithm and Ambiguity
Problem Solving Designing Algorithms.
Topic 1: Problem Solving
Flowcharting & Algorithms
Algorithms and Problem Solving
Flowcharts and Pseudo Code
Topics Designing a Program Input, Processing, and Output
Workshop for Programming And Systems Management Teachers
COMPUTATIONAL THINKING COMPUTATIONAL THINKING IN PROGRAMMING
Topics Designing a Program Input, Processing, and Output
Chapter 2: Input, Processing, and Output
Computational Thinking
WJEC GCSE Computer Science
Software Development Techniques
Presentation transcript:

Abstraction & Automation Theory of Computation Abstraction & Automation

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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