CST 370 Week 1
This was our first week in CST 370 - Design and Analysis of Algorithms.
What is an algorithm?
Our textbook, Introduction to the design and analysis of algorithms, defines an algorithm as a sequence of unambigous instructions for solving a problem. It also gives a list of important points for algorithm design (p. 29):
- The nonambiguity requirement for each step of an algorithm cannot be compromised.
- The range of inputs for which an algorithm works has to be specified carefully.
- The same algorithm can be represented in several different ways.
- There may exist several algorithms for solving the same problem.
- Algorithms for the same problem can be based on very different ideas and
can solve the problem with dramatically different speeds.
Another important idea is that algorithms are system agnostic. They can be implemented in any programming language, or even done manually. The textbook presents algorithms using psuedocode.
Algorithm Examples
Euclid's Algorithm
The first algorithm the textbook discusses is Euclid's algorithm. This, along with the first few algorithms, are used to try and find the greatest common divisor of two numbers.
Consecutive Integer Checking Algorithm
Middle-School Procedure
Types of Problems
The textbook covers a handful of important types of problems in algorithm design.
- The sorting problem is to rearrange the items of a given list in a certain order.
- The searching problem deals with finding a given value in a given set.
- String problems deal with analyzing and manipulating strings, sequences of alphabetic characters.
- Graph problems deal with graphs, collections of connected points. Types of graphs include directed and undirected graphs, weighted and unweighted graphs, and trees.
- Combinatorial problems ask to find a combinatorial object, such as a permutation, a combination, or a subset that satisfies certain constraints.
- Geometric problems deal with geometric objects such as points, lines, and polygons.
- Numerical problems deal with numbers, equations, functions, and other mathematical operations.
Orders of Growth
In analysizing the efficiency of algorithms, we often use an algoritm's order of growth to show how long it takes to complete for a certain input size.
Algorithm efficiency is often measured using best-case and worst-case scenarios.
- An algorithm's best-case scenario is one where the algorithm is completed as quickly as possible. An example of this is finding the correct value in the first element of an array.
- An algorithm's worst-case scenario is one where the algorithm is completed as slowly as possible. An example of this is finding the correct value in the last element of an array, or not at all.
Comments
Post a Comment