1 / 64

For science!

For science!. Tower of Hanoi – Link 1 Tower of Hanoi – Link 2. ALGORITHMS. MMC. Radu Sorici. The University of Texas at Dallas. What are algorithms? . What are algorithms? . An algorithm is a procedure which takes some values ( inputs ) and produces another set of values ( outputs ).

renata
Download Presentation

For science!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. For science! • Tower of Hanoi – Link 1 • Tower of Hanoi – Link 2

  2. ALGORITHMS MMC RaduSorici The University of Texas at Dallas

  3. What are algorithms?

  4. What are algorithms? • An algorithm is a procedure which takes some values (inputs) and produces another set of values (outputs)

  5. What are algorithms? • 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)

  6. What are 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.

  7. Inputs and outputs • So what are the inputs?

  8. Inputs and outputs • So what are the inputs? • The inputs are a series of numbers • And the output?

  9. Inputs and outputs • 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.

  10. Inputs and outputs • 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. • Such an input is called an instance of the maximum problem.

  11. Inputs and outputs • 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. • Such an input is called an instance of the maximum problem. • What are some other computational problems?

  12. What are algorithms? • 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. • Such an input is called an instance of the maximum problem. • What are some other computational problems? • Do not forget about sorting!

  13. What are algorithms? • We will call an algorithm correct if it halts with correct outputs. If an algorithm is correct then it solves the problem.

  14. What are algorithms? • 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.

  15. Correctness • 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" ).

  16. Correctness • 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.

  17. Usage • What other problems are solved by algorithms?

  18. Usage • 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.

  19. Usage • Let us not also forget about the Human Genome Project (1990-2003) which ended in a complete deciphering of the human DNA!

  20. Usage • Let us not also forget about the Human Genome Project (1990-2003) 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.

  21. Usage • Let us not also forget about the Human Genome Project (1990-2003) 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.

  22. Problems and Examples • Problem: Create an algorithm that solves the sorting problem.

  23. Problems and Examples • Problem: Create an algorithm that solves the sorting problem. • Solution: Bubble Sort!

  24. Problems and Examples • 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.

  25. Problems and Examples • 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.

  26. Insertion Sort • Insertion Sort: • Chose a number from a given set and place it on a line

  27. Insertion Sort • Insertion Sort: • Chose a number from a given set and place it on a line • 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

  28. Insertion Sort • Insertion Sort: • Chose a number from a given set and place it on a line • 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 • 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

  29. Insertion Sort • Insertion Sort • Why is insertion sorting correct?

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

  31. efficiency • 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!

  32. efficiency • 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?

  33. 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.

  34. 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.

  35. 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. • Thus in total we make at most (n-1)*(n-1)=n^2-2n+1 steps.

  36. efficiency • 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

  37. Complexity • The complexity of the algorithm is the number it takes to transform the inputs into the outputs.

  38. Complexity • 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.

  39. Complexity • 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.

  40. Complexity • 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).

  41. Complexity • Problem: What is the complexity of the Insertion Sort?

  42. Complexity • Problem: What is the complexity of the Insertion Sort? • Answer: O(n^2).

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

  44. Complexity • 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

  45. Complexity

  46. Complexity • 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.

  47. Complexity • 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?

  48. Complexity • 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.

  49. Complexity • 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

  50. Whewww, Moving on • 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.

More Related