 Tower of Hanoi – Link 1 Tower of Hanoi – Link 1  Tower of Hanoi – Link 2 Tower of Hanoi – Link 2.

Slides:



Advertisements
Similar presentations
Week 6 - Wednesday CS322.
Advertisements

CSED101 INTRODUCTION TO COMPUTING GREEDY APPROACH, DIVIDE AND CONQUER Hwanjo Yu.
Problems and Their Classes
MATH 224 – Discrete Mathematics
Analyzing Algorithms and Problems Prof. Sin-Min Lee Department of Computer Science.
Lecture 3: Parallel Algorithm Design
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
Partitioning and Divide-and-Conquer Strategies ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, Jan 23, 2013.
CSE 830: Design and Theory of Algorithms
Analysis of Algorithms CS 477/677
Computational Complexity, Physical Mapping III + Perl CIS 667 March 4, 2004.
Complexity (Running Time)
Algorithm Efficiency and Sorting
Copyright © Cengage Learning. All rights reserved. CHAPTER 11 ANALYSIS OF ALGORITHM EFFICIENCY ANALYSIS OF ALGORITHM EFFICIENCY.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
1 1.1 © 2012 Pearson Education, Inc. Linear Equations in Linear Algebra SYSTEMS OF LINEAR EQUATIONS.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
Difficult Problems. Polynomial-time algorithms A polynomial-time algorithm is an algorithm whose running time is O(f(n)), where f(n) is a polynomial A.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Analysis of Algorithms
10/14/ Algorithms1 Algorithms - Ch2 - Sorting.
Problems you shouldn’t tackle. Problem Complexity.
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
+ Simulation Design. + Types event-advance and unit-time advance. Both these designs are event-based but utilize different ways of advancing the time.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 1: The Role of Algorithms in Computing (slides by N. Adlai A. DePano)
1. The Role of the Algorithms in Computer Algorithms – 1/2 Algorithm: Any well-defined computation procedure that takes some value, or set of values,
Computer programming.
Chapter 5 Review Advanced Algebra 1. System of Equations and Inequalities - System of Linear Equations in Two Variables - Solutions of Linear Inequalities.
Lesson Objective: Understand what an algorithm is and be able to use them to solve a simple problem.
1Computer Sciences Department. Book: Introduction to Algorithms, by: Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Electronic:
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
In section 11.9, we were able to find power series representations for a certain restricted class of functions. Here, we investigate more general problems.
Data Structure Introduction.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Algorithm Analysis Part of slides are borrowed from UST.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
NP-complete Problems Prof. Sin-Min Lee Department of Computer Science.
Limits to Computation How do you analyze a new algorithm? –Put it in the form of existing algorithms that you know the analysis. –For example, given 2.
ALGORITHMS.
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)
Complexity & Computability. Limitations of computer science  Major reasons useful calculations cannot be done:  execution time of program is too long.
Dynamic Programming.  Decomposes a problem into a series of sub- problems  Builds up correct solutions to larger and larger sub- problems  Examples.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 9: The Tower of Hanoi.
Chapter 12 Theory of Computation Introduction to CS 1 st Semester, 2014 Sanghyun Park.
Data Structures and Algorithms Instructor: Tesfaye Guta [M.Sc.] Haramaya University.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Copyright © 2014 Curt Hill Algorithm Analysis How Do We Determine the Complexity of Algorithms.
1 Recursion Recursive function: a function that calls itself (directly or indirectly). Recursion is often a good alternative to iteration (loops). Its.
1 Computability Tractable, Intractable and Non-computable functions.
CS1022 Computer Programming & Principles
CMPT 438 Algorithms.
Lecture 3: Parallel Algorithm Design
Warmup What is an abstract class?
Auburn University COMP7330/7336 Advanced Parallel and Distributed Computing Data Partition Dr. Xiao Qin Auburn University.
Analysis and design of algorithm
Objective of This Course
Chapter 11 Limitations of Algorithm Power
Core Assessments Core #1: This Friday (5/4) Core #2: Tuesday, 5/8.
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Presentation transcript:

 Tower of Hanoi – Link 1 Tower of Hanoi – Link 1  Tower of Hanoi – Link 2 Tower of Hanoi – Link 2

Radu Sorici The University of Texas at Dallas

 An algorithm is a procedure which takes some values (inputs) and produces another set of values (outputs)

 Algorithms appear as early as computational problems. They are nothing but a set of rules by which some values are calculated from some inputs (and as such can be thought of as algorithms)

 Example: Someone needs to find the maximum value out of a series of recorded values. This problem may arise, for example, when we look for the highest temperature during a period of time.

 So what are the inputs?

 The inputs are a series of numbers  And the output?

 The output is a the number m, such that  For example if the inputs are the numbers 1, 2, 3, 1000, 2^10 then the maximum is 1024.

 And the output?  The output is a the number m, such that  For example if the inputs are the numbers 1, 2, 3, 1000, 2^10 then the maximum is  Such an input is called an instance of the maximum problem.

 And the output?  The output is a the number m, such that  For example if the inputs are the numbers 1, 2, 3, 1000, 2^10 then the maximum is  Such an input is called an instance of the maximum problem.  What are some other computational problems?

 And the output?  The output is a the number m, such that  For example if the inputs are the numbers 1, 2, 3, 1000, 2^10 then the maximum is  Such an input is called an instance of the maximum problem.  What are some other computational problems?  Do not forget about sorting!

 We will call an algorithm correct if it halts with correct outputs. If an algorithm is correct then it solves the problem.

 An algorithm which is incorrect can (and usually does) produce incorrect output. It may also halt or not depending on the inputs.

 We will call an algorithm correct if it halts with correct outputs. If an algorithm is correct then it solves the problem.  An algorithm which is incorrect can (and usually does) produce incorrect output. It may also halt or not depending on the inputs.  An incorrect algorithm does not necessarily mean failure. Sometimes a partially correct answer is quite satisfactory. It is called a heuristic (Greek: "Ε ὑ ρίσκω", "find" or "discover" ).

 In modern days heuristics are used in anti- viruses. They check for known viruses and attempt to guess new ones according to some rules.

 What other problems are solved by algorithms?

 Wal-Mart uses an advanced algorithm which enables them to have very precise shipping and restocking schedule. They use statistical variables to predict the demand for certain items.  The Internet! It uses multiple algorithms in order to manage data transfer and authentication. If we think of a computer as a node in a graph it suddenly becomes a graph theory problem! In addition, we can see more and more cloud services which require complex algorithms to manage virtually unlimited amounts of information.

 Let us not also forget about the Human Genome Project ( ) which ended in a complete deciphering of the human DNA!

 In the end approximately 3.3 billion base- pairs were mapped. Not sure what that means but it sounds very complicated.

 Let us not also forget about the Human Genome Project ( ) which ended in a complete deciphering of the human DNA!  In the end approximately 3.3 billion base- pairs were mapped. Not sure what that means but it sounds very complicated.  Last but not least cryptography. Our data is encrypted based on number theory and numerical manipulations.

 Problem: Create an algorithm that solves the sorting problem.

 Solution: Bubble Sort!

 Problem: Create an algorithm that solves the sorting problem.  Solution: Bubble Sort! Even though it is my favorite algorithm to solve the sorting problem it is far from efficient. A far more efficient algorithm is the insertion sort.

 Problem: Create an algorithm that solves the sorting problem.  Solution: Bubble Sort! Even though it is my favorite algorithm to solve the sorting problem it is far from efficient. A far more efficient algorithm is the insertion sort.  Usually the best way to describe an algorithm is in English. It is also advisable to be as concise as possible.

 Insertion Sort: 1. Chose a number from a given set and place it on a line

 Insertion Sort: 1. Chose a number from a given set and place it on a line 2. Chose another number and place it on the same line but in the right position. This is either to the right if it is larger or equal or to the left if it is smaller

 Insertion Sort: 1. Chose a number from a given set and place it on a line 2. Chose another number and place it on the same line but in the right position. This is either to the right if it is larger or equal or to the left if it is smaller 3. Repeat step two until all of the numbers are in ascending order (note that if the actions in step two are reversed we would have obtained a descending sequence). Also note that at every step the number on the line are always sorted

 Insertion Sort  Why is insertion sorting correct?

 Efficiency  Of course the most widely used characteristic of efficiency is speed.

 Efficiency  Of course the most widely used characteristic of efficiency is speed  Since we are interested in computer science as well, speed may refer to the capability of the computer processor to execute commands. Everyone likes a computer that can run the newest games!

 Efficiency  Of course the most widely used characteristic of efficiency is speed  Since we are interested in computer science as well, speed may refer to the capability of the computer processor to execute commands. Everyone likes a computer that can run the newest games!  What are other characteristics that we might look at if we are interested in efficiency and in general why are we interested in efficiency?

 Case Study: The Bubble Sort! The basic idea is that if we have n, numbers we arrange them in a line. Then we compare any two numbers and change their location depending on which one is larger or smaller.

 Take the first number and compare it to the rest and change the order when necessary. This takes n-1 steps.

 Case Study: The Bubble Sort! The basic idea is that if we have n, numbers we arrange them in a line. Then we compare any two numbers and change their location depending on which one is larger or smaller.  Take the first number and compare it to the rest and change the order when necessary. This takes n-1 steps.  Thus in total we make at most (n-1)*(n- 1)=n^2-2n+1 steps.

 Now suppose that a computer can execute 1,000,000 commands per second. If we are given 10,000 numbers to sort we will need approximately

 The complexity of the algorithm is the number it takes to transform the inputs into the outputs.

 The algorithms we are looking at have polynomial complexities which means that the number of steps required to solve it can be represented as a polynomial.

 The complexity of the algorithm is the number it takes to transform the inputs into the outputs.  The algorithms we are looking at have polynomial complexities which means that the number of steps required to solve it can be represented as a polynomial.  Very often we will represent this complexity with a big O notation which in simple terms represents the rate of growth of a function.

 With polynomials we are used to thinking in terms of degrees. Similarly the complexities of algorithms can be represented as classes of polynomial degrees. For example all problems that can be solved in a linear amount of steps (ax+b – steps) has complexity O(n). Then Bubble Sort has complexity O(n^2).

 Problem: What is the complexity of the Insertion Sort?

 Answer: O(n^2).

 Of course there are algorithms which are not solved in polynomial time ( for example: find all perfect squares less than a given number).

 There are a number of complexity classes. A famous picture circulating in most textbooks relating complexity classes is the following

 P: In simple terms a problem that can be solved in polynomial time  NP: These are problems that can be solved in non-deterministic polynomial time.

 P: In simple terms a problem that can be solved in polynomial time  NP: These are problems that can be solved in non-deterministic polynomial time.  P=NP?

 P: In simple terms a problem that can be solved in polynomial time  NP: These are problems that can be solved in non-deterministic polynomial time.  P=NP?  The travelling salesman problem is in the NP class.

 P: In simple terms a problem that can be solved in polynomial time  NP: These are problems that can be solved in non-deterministic polynomial time.  P=NP?  The travelling salesman problem is in the NP class  A solution can be verified in polynomial time

 So far we have seen algorithms which are called incremental. These are algorithms are basically recursion which repeat a certain step in order to get us closer to the output.

 Another famous approach and the most important in my opinion is the divide and conquer.

 The main goal of this technique is to divide a problem into multiple similar problems with smaller inputs.

 Another famous approach and the most important in my opinion is the divide and conquer.  The main goal of this technique is to divide a problem into multiple similar problems with smaller inputs.  It consists of three steps 1. Divide the problem into similar sub problems 2. Conquer the sub problems by solving them in the same way 3. Combine the results together to get the final output

 Use the divide and conquer technique to solve the sorting problem

 The analysis of the complexities yielded by divide and conquer algorithms is very interesting but unfortunately is beyond the scope of this lecture. It is enough to say that they produce far better results then other techniques

 Use the divide and conquer technique to solve the sorting problem  The analysis of the complexities yielded by divide and conquer algorithms is very interesting but unfortunately is beyond the scope of this lecture. It is enough to say that they produce far better results then other techniques  Propose a problem that might benefit from the divide and conquer technique

 Alternating between the smallest and the next- smallest disks, follow the steps for the appropriate case:  For an even number of disks:  make the legal move between pegs A and B  make the legal move between pegs A and C  make the legal move between pegs B and C  repeat until complete  For an odd number of disks:  make the legal move between pegs A and C  make the legal move between pegs A and B  make the legal move between pegs B and C  repeat until complete

 Recursive solution  A key to solving this puzzle is to recognize that it can be solved by breaking the problem down into a collection of smaller problems and further breaking those problems down into even smaller problems until a solution is reached. The following procedure demonstrates this approach.  label the pegs A, B, C—these labels may move at different steps  let n be the total number of discs  number the discs from 1 (smallest, topmost) to n (largest, bottommost)  To move n discs from peg A to peg C:  move n−1 discs from A to B. This leaves disc n alone on peg A  move disc n from A to C  move n−1 discs from B to C so they sit on disc n

 For a set of points X in the plane find the minimal convex set containing X.  For a set of points X in the plane find a polygon that contains all of the points from X.  Four numbers are written on a circle. The final goal is to move the numbers to the right, by one position, without moving the circle. The only operations available are 1. Assignment and recording of one value 2. Assignment, addition, and subtraction 3. Assignment, multiplication, and division

 Let f be a function such that f(0)=0, f(1)=1, f(2n)=n, f(2n+1)=f(n)+f(n+1). Devise an algorithm that computes f(N) for some N.

 Let f be a function such that f(0)=0, f(1)=1, f(2n)=n, f(2n+1)=f(n)+f(n+1). Devise an algorithm that computes f(N) for some N. (Recursion)  Consider a set of 10 numbers. Find an algorithm that extracts subsets out of these 10 numbers such that they are divisible by a) 2 b) 3 c) 5 d) 7

 Consider a matrix of size m x n with numbers written in it. A number is called amazing if it is at the same time the smallest number in its row and the largest in its column. Devise an algorithm that finds all such numbers in a given matrix.

 Check if a given points is located inside a given triangle (generalize to convex polygon).