Algorithms and their Applications CS2004 (2012-2013) Dr Stephen Swift 1.2 Introduction to Algorithms.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

1 CS101 Introduction to Computing Lecture 17 Algorithms II.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
CS 111: Introduction to Programming Midterm Exam NAME _________________ UIN __________________ 10/30/08 1.Who is our hero? 2.Why is this person our hero?
S.T.A.I.R.. General problem solving strategy that can be applied to a range problems.
6-1 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer problem-solving process and relate it to Polya’s.
Problem Solving and Algorithm Design
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Chapter 1 - An Introduction to Computers and Problem Solving
8 Algorithms Foundations of Computer Science ã Cengage Learning.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Chapter 2: Algorithm Discovery and Design
CS107 Introduction to Computer Science Lecture 2.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Invitation to Computer Science, Java Version, Second Edition.
Program Development Life Cycle (PDLC)
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Algorithms and their Applications CS2004 ( ) Dr Stephen Swift 4.1 Time Complexity and Asymptotic Notation.
“The study of algorithms is the cornerstone of computer science.” Algorithms Fall 2011.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Algorithm Design.
Lecture 11 Data Structures, Algorithms & Complexity Introduction Dr Kevin Casey BSc, MSc, PhD GRIFFITH COLLEGE DUBLIN.
Computer Science, Algorithms, Abstractions, & Information CSC 2001.
The Hashemite University Computer Engineering Department
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
In the news: A recently security study suggests that a computer worm that ran rampant several years ago is still running on many machines, including 50%
Algorithms and Pseudocode
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Design and Analysis of Algorithms Faculty Name : Ruhi Fatima Course Description This course provides techniques to prove.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
Introduction to Algorithms
ICS 3UI - Introduction to Computer Science
Algorithms and Problem Solving
Introduction Algorithms Order Analysis of Algorithm
CS1001 Programming Fundamentals 3(3-0) Lecture 2
Introduction to Computer Programming
Algorithm and Ambiguity
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Problem Solving Techniques
Objective of This Course
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Theory of Computation Turing Machines.
Chapter 1 Introduction(1.1)
Algorithm and Ambiguity
Algorithms and Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Introduction to Algorithms
ICT Gaming Lesson 2.
Programming Fundamentals (750113) Ch1. Problem Solving
Basic Concepts of Algorithm
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Presentation transcript:

Algorithms and their Applications CS2004 ( ) Dr Stephen Swift 1.2 Introduction to Algorithms

Introduction to AlgorithmsSlide 2 Introduction In this topic we will look at: What is a computer? What is computer science? What is an algorithm? Other concepts we should already know will also be discussed: Software Programming Language Implementation

Introduction to AlgorithmsSlide 3 Where Did it all Start? – Part 1 How did the computer come about? David Hilbert In ~1900, a very famous German Mathematician called David Hilbert ( ) listed 23 unsolved mathematical problems He later refined problem number ten to ask “is there a way of determining if an arbitrary first- order symbolic logic statement is true or false?” (Do not worry what this means!)

Introduction to AlgorithmsSlide 4 Where Did it all Start? – Part 2 This became known as the “Entscheidungsproblem” or “Decision Problem” In 1936 Alan Turing ( ) created two concepts called a “Turing Machine” and a “Universal Turing Machine” These were used to show that the “Decision Problem” was impossible to solve

Introduction to AlgorithmsSlide 5 Where Did it all Start? – Part 3 In 1939 Alan Turing used his ideas to create a machine called “The Bombe” which helped crack the German enigma code In 1948, the first computer (called the Baby) and associated computer program were developed at Manchester University, UK, based on Turing’s ideas

Introduction to AlgorithmsSlide 6 Computer Science Computer science is the study of computation A discipline that studies computable problems and computational structures A discipline that involves the understanding and design of computers and computational processes Is it a mathematical, scientific or engineering discipline? Interdisciplinary

Introduction to AlgorithmsSlide 7 What is Computation Computation is the procedure of calculating i.e. determining something by mathematical or logical methods “In natural science, Nature has given us a world and we’re just to discover its laws. In computers, we can stuff laws into it and create a world”, by A. Kay Computability is about what computers can do and cannot do Algorithmically Characterises problems that can be solved Algorithmically Exhibit problems that cannot be solved (e.g. the proof of the insolvability of the “halting problem”)

Introduction to AlgorithmsSlide 8 So What is a Computer and Computer Program? computer A computer is a device for carrying out certain types of algorithms algorithm An algorithm (in our context) is a set of steps for solving a problem computer programming language A computer programming language is a “language” for describing algorithms to computers computer program A computer program is (usually) a description of a single algorithm and/or problem Computer software Computer software is a collection of programs that carry out a similar task or related E.g. Windows

Introduction to AlgorithmsSlide 9 Why use a Computer? A computer can perform many mundane tasks much faster than people, E.g. adding up a large number of figures Some tasks can only be done by computers E.g. high precision robotics However there are many tasks that computer’s are no good at E.g. critically appraising a film

Introduction to AlgorithmsSlide 10 What is an Algorithm? InputOutput Algorithm An algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values as output An algorithm can be seen as a tool for solving a well-specified computational problem

Introduction to AlgorithmsSlide 11 What is Implementation? Implementation is the task of turning an algorithm into a computer program Depending on the level of abstraction of the description of the algorithm, implementation can be anything between a straightforward translating task and a lengthy, difficult job

Introduction to AlgorithmsSlide 12 Programming Languages – Part 1 Computers really just understand binary, which is just sequences of zeros and ones A computer language is a method of allowing us (the user) to describe to a computer what we want it to do I.e. The specification of an Algorithm It is then translated (by the computer!) into binary so the computer can then understand it

Introduction to AlgorithmsSlide 13 Programming Languages – Part 2 Computer programming languages are similar to spoken languages They have structure and grammar They have words and phrases A incorrectly written program will not be understood by the computer and will result in an error Programmers usually use previously written programs if possible and combine them to solve new problems I.e. They try not to “reinvent the wheel”!

Introduction to AlgorithmsSlide 14 Why Study Algorithms? – Part 1 So why do we want to study algorithms? Some algorithms that solve the same problem can differ massively in their efficiency Computers may be getting faster but they are not infinitely fast! For example, sorting a list of billions of numbers could take a computer a very long time If we do not make the algorithms we write efficient then they may take too long to run If we do not analyse our algorithms we do not know how long they will take 4 years two weeks I am currently trying to make a program more efficient (by changing the algorithms and developing new algorithms) which will take about 4 years to run in its current state! I am hoping to get this down to around two weeks!!!

Introduction to AlgorithmsSlide 15 Why Study Algorithms? – Part 2 What makes the difference between a truly skilled programmer and an average one? Strong algorithmic knowledge and technique It might be that you can perform certain programming tasks without knowing much about algorithms However with a good grounding in algorithms, you can accomplish much more

Introduction to AlgorithmsSlide 16 What is the Analysis of an Algorithm? This is an indication of the time a computer will take to solve a problem given the size of the problem Time is abstract, and is usually measured in operations Multiplications, additions, swaps This allows us to compare two algorithms that try and solve the same problem Independent of the speed of a computer Also known as the computational complexity of an algorithm

Introduction to AlgorithmsSlide 17 Algorithm Example – Part 1 You have 70 coins (N=70) which are all “supposed” to be gold coins of the same weight, although you know that one coin is fake and weighs less than the others You have a balance scale; you can put any number of coins on each side of the scale at one time, and it will tell you if the two sides weigh the same, or which side is lighter if they don’t weigh the same

Introduction to AlgorithmsSlide 18 Algorithm Example – Part 2 Outline an algorithm for finding the fake coin How many times do you have to weigh? Easiest approach is not necessarily the best approach! Ideally, we want to design an algorithm that will take the shortest period of time We want an algorithm that is efficient, for example, what if we are then given 10,000 (N=10,000) coins and told that one is fake?

Introduction to AlgorithmsSlide 19 Example Solution One – Part 1 Take two coins at a time, one on each side of the scales: If weight(Left) = weight(Right) Then Take the next two coins Else Coin at the lighter side is fake End If Repeat the above until either the fake coin is found or you have checked all the coins

Introduction to AlgorithmsSlide 20 Example Solution One – Part 2 In the worst case, e.g. the fake coin is the last or the last but one, the IF Then-Else statement will have to run N/2 (35) times In the best case, e.g. the fake coin is the first or second, the same statement will only have to run once

Introduction to AlgorithmsSlide 21 Example Solution Two – Part 1 Divide-and-Conquer: Split the set of coins into two subsets of equal size; N/2 go to the left side of the scale, N/2 go to the right side If weight(left) ≠ weight(right) Then The lighter side contains the fake coin Split the lighter N/2 coins … Else Neither side contains the fake coin End If

Introduction to AlgorithmsSlide 22 Example Solution Two – Part 2 Binary Search Essentially this is a form of Binary Search This will be discussed later in the module The number of splits is equivalent to the number of levels (k) in the corresponding complete binary tree (we will cover this later) Since there is only one comparison on each level, the worst case is to conduct log 2 (N+1) comparisons Note: 2 x =y, log 2 (y) = x, e.g. log 2 (8) = 3 So when N=70 this will be less than 7 in total

Introduction to AlgorithmsSlide 23 Example Solution Comparison Solution 1: F1(N) = N/2, F1 ∈ O(N) Solution 2: F2(N) = log 2 (N+1), F2 ∈ O(log 2 (N))

Introduction to AlgorithmsSlide 24 The Analysis of Algorithms So there can be many competing algorithms for solving a given problem This module will enable you to gain experience in analysing and comparing different algorithms Later on in the module we will discuss that there are some problems that are impossible to solve computationally

Introduction to AlgorithmsSlide 25 Next Topic Lecture We will next look at algorithm analysis in more detail Laboratory There are no formal laboratories this week This weeks laboratory is a worksheet for you to attempt in your own time (practice)