Lecture 2 - Fundamentals of algorithms and problem solving Flashcards
Process of designing algorithms:
- Understanding the problem
- Ascertaining the capabilities of the device
- Choosing between exact and approximate problem
- Deciding an appropriate language and data structure
- Implement any solution
- Improve on your initial solution (generate more solutions)
Factors that need to be taken into consideration when thinking of a solution:
Very important factors:
• How often are you going to need the algorithm?
• What is the typical problem size you are trying to solve?
Less important factors:
• What language are you going use to implement your algorithm?
• What is the cost-benefit of an efficient algorithm?
How do you analyze an algorithm?
By in investigating an algorithm’s efficiency in respect of two resources:
• Running time
• Memory space
Why is it not always possible to study algorithm’s efficiency in terms of its input size?
There are algorithms that require more than one parameter (e.g. Graph algorithms)
The input size may not be well-defined as one would wish (eg. Matrix multiplication)
What are the problems of using a standard unit for time measurement?
We’d face serious drawbacks:
• Dependence on the speed of a particular computer
• Dependence on the quality of the program implementing the algorithm
• Dependence on the quality of the compiler used to generate the executable
• Difficulty of clocking the time precisely
How is time efficiency measured in an algorithm?
The standard approach is to identify the basic operation(s) and count how many times it is executed.
What are the basic operations for matrix multiplication ?
multiplications and additions
What is the basic operation for sorting ?
comparisons
What is the established framework for counting operations?
Count the number of times the algorithm’s basic operation is executed for inputs of size n (Where n is clearly defined)
Machine-independent algorithm design depend on what hypothetical computer?
The Random Access Machine or RAM
What are the characteristics of the RAM?
- Each simple operation (+, *, -, /, =, memory call) takes 1 time step;
- The count of operations of the algorithm is equal to n 1
- Loops and subroutines are the compositions of many single-step operations.
- Takes no notice of whether an item is in cache or on the disk.
Algorithm Design Manual Steve Skiena : RAM advantages
- Under the RAM model, we measure the run time of an algorithm by counting up the number of steps it takes on a given problem instance.
- By assuming that our RAM executes a given number of steps per second, the operation count converts easily to the actual run time.
RAM Disadvantages:
- A common complaint is that it is too simple, that these assumptions make the conclusions and analysis too coarse to believe in practice.
- Multiplying two numbers takes more time than adding two numbers on most processors, which violates the first assumption of the model.
- Memory access times differ greatly depending on whether data sits in cache or on the disk, thus violating the third assumption.
What type of functions are 2n and n! ?
Exponential. Solutions with these running times are only practical for very small input sizes. Problems having solutions in this class are called “intractable”.
Common growth functions:
- ~1: Constant Time.
- ~log n: Logarithmic.
- ~n: Linear.
- ~nk log n: Polylogarithmic.
- n2: Quadratic.
- n3: Cubic.
- nk where k is a constant: Polynomial.
- 2n: Exponential.