Download presentation
Presentation is loading. Please wait.
Published byJade Lynch Modified over 9 years ago
2
The amount of time it takes a computer to solve a particular problem depends on: The hardware capabilities of the computer The efficiency of the software used to solve the problem.
3
The more that you use your computer, the slower it gets, primarily because people tend to customize their systems to make work easier. Therefore these customizations typically make the boot process take much longer than when the computer was new. Adding these improvements can also make the computer less stable and more prone to crashing.
4
Often when you install free software, that software installs other software which can use your system resources which tends to slow your system down. Free software always has to be paid for. Sometimes this is done by increasing sales for other products by the same vendor. Other times other vendors pay the original vendor to piggyback their software on the install. Still other software brings ads with the software. The net result is that over time most computers become slower.
5
Computational Complexity is the study of the complexity of algorithms. Problems can often be solved in several ways. So we measure the complexity of the particular solution rather than the complexity of the problem. Complexity refers to the amount of resources an algorithm takes, not how difficult the algorithm is to understand.
6
The resources an algorithm typically needs are space and time. Space measures the amount of memory necessary to store the data used in implementing the algorithm. Time measures the number of steps used in executing the algorithm. We do not use seconds because faster computers might take fewer seconds than slower computers.
7
Both time and space are typically measured based on the amount of data to be processed. For example the process of alphabetizing 100 names will take more space and more steps than alphabetizing 25 names. Thus computational complexity typically is measured based on the number of items, n, being processed.
8
Since we are interested in speed we will only examine the number of steps that are taken to execute an algorithm.
9
To determine if an integer is odd or even one only needs look at the last digit so the time this problem takes to solve is independent of the number of digits in the number. This algorithm has time constant time complexity. To add two integers with n digits (as we learned in elementary school) we start at the end, add the two digits, write down the answer and either carry one or not, and back up one space and repeat this process until the numbers are finished. This algorithm has time complexity n,
10
Multiplying two n digit integers: This process has time complexity n 2. Start at the right most digit of the bottom number and multiply it by the last digit of the above number and write down the last digit and carry something to the previous column of the top number. Then repeat this step adding the amount carried at the end. This process will occur n times since the top number has n digits. Now repeat this n step process for each of the previous digits of the bottom number, moving the results one place to the left each time. This is a total of n groups of n steps, or n 2 steps total. Then we add the columns up which takes n more steps.
11
If we have a list of n items we could search for a particular value by starting at the beginning and going through the list until we either found the value or got to the end of the list. This takes N steps, so the algorithm has complexity n. It is called the linear search. On the other hand if the list is in order we can use the binary search. First look at the value in the middle. If it’s too small then it is eliminated but so are all the values before it. We then perform the same step on the part of the list that’s still left. Each time we eliminate half the data, until we have either found the value or exhausted the list. This algorithm has complexity log n because doubling the size of the list only adds one more step to the process.
12
A salesman must meet with clients and chooses the order to meet with them so as to minimize travel time or mileage or expense or … One possible method of finding the most efficient order to choose for meeting the clients is to look at all the possibilities and choose the best one. This method is referred to as exhaustive search. For example if there are three clients, A, B and C then the salesman could go from Home to A to B to C and back to home, HABCH. There are five other possible choices: HACBH, HBACH, HBCAH, HCABH, and HCBAH.
13
For N clients there are N! (N factorial) possible orders to meet the clients. N! = 1*2*3*…*N, so 4! = 1*2*3*4 = 24 different routes. Why? If the salesman had 10 clients, there would be 10! Different routes to check. Thus the time complexity of this algorithm is therefore N!
14
In chess, the two opponents are referred to as white and black, based on the color of the pieces that each player uses. White always moves first. A move in chess is completed when white has moved followed by black making a move. Half a move is referred to as a ply. One method of determining what move to make is to examine how your opponent will respond to your move and see which move that you might make is best.
15
In order to refine your estimation you will need to see how you might respond to the move that your opponent makes in response to your move. So for example, if you use a 4 ply search you would evaluate a move by looking at how your opponent would respond to the move you made in response to his move in response to yours. This algorithm assumes that your opponent will always make the best move. Typically at any given position, there are about 20 reasonable moves that you can make in chess.
16
Thus a four ply depth search would mean examining 20x20x20x20 = 20 4 positions. This algorithm has an exponential time complexity.
17
Constant time complexity means that an algorithm requires approximately the same amount of time regardless of the data. Linear time complexity doubles the time when the amount of data doubles N 2 time complexity quadruples the time when the amount of data doubles. Log n time complexity adds only one step when the amount of data doubles.
18
With exponential and factorial time complexity the time can become intractable. For example with the chess problem and a computer that can analyze one billion moves per second, (which may be faster than any computer currently in existence), a depth of 2, 4 or 6 ply could evaluated in less than one second. But 8 ply depth takes 25.6 seconds per move and 10 ply depth takes almost 3 hours per move.
19
Factorial complexity is even worse. Consider the traveling salesman problem and a computer that can compute a billion routes per second: 3 or 5 or 10 clients can be evaluated in less than one second. But 15 clients takes almost 22 seconds to evaluate And 20 clients takes more than 77 years to evaluate.
20
Some time complexity levels do not scale. For both exponential and factorial time complexity as the data increases in size, algorithms of this level of complexity cannot be solved in a practical manner. The only solution in this case is to use a different algorithm or find a sub-optimal solution to the problem, i.e. find a good route or a good chess move but not necessarily the best one.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.