How do you get from your home to your office, or the nearest store? If you live in a city, the answer may be complicated, and it might depend on whether you are walking, driving, riding a bicycle or taking public transportation. Even for one mode of transportation, there might be several possible ways, some of which are faster or more reliable than others. Deciding how to make this journey is analogous to deciding how to design an algorithm.
What are the main properties of an algorithm?
An algorithm is an arrangement of steps that describes operations to be performed in order to achieve a goal and purpose of its design. For an algorithm to be considered whole and comprehensive, it must encompass following qualities:
This basically means that an algorithm has to at some point end. It must have a finite number of steps that eventually terminate the algorithm.
Each line of the algorithm’s code must be accurately determined and must fulfill a particular well-specified function.
“Most algorithms are designed to work with inputs of arbitrary length” (Analysis of algorithms, 2016), which means that a well-designed algorithm should have an input defined, even if it’s configured with a zero value.
An algorithm takes inputs and outputs the processed results that reflect the purpose of the algorithm. All algorithm outputs should be analysed and verified. Many times, especially for centralized applications that may store certain large quantities of data, we also need to define the storage requirements of the algorithm in question.
All processes or steps described in the algorithm need to be optimized, so they’re efficient and done exactly without additional unnecessary computing cycles. “You can apply the measure of efficiency to time or storage.” (UKL1_CKIT_501, 2016)
Ambiguity involved in algorithm specifications.
Sometimes, an algorithm isn’t described in sufficient detail, which creates all sorts of ambiguity problems. This holds truth especially in cases of pseudo-code algorithms and it is typically happening because there are no rules attached to writing a pseudo-code. The result of such un-ruled expressions of often a pseudo-code that will always be inherently different from one another. Thus making it often hard to interpret. My personal learning is, that reading someone’s pseudo-code is like learning a new language.
This problem can be alleviated by accompanying the code with comments and flowcharts that will depict algorithm building blocks visually, thus making it easier to interpret.
How you determine an algorithm’s qualities.
A well-designed algorithm is expected to have a definition that is concise and elegant. A good algorithm should never experience any infiniteness that would cause it to run in a never ending loop. It should do exactly what it’s designed to do and should not include any functionality that either doesn’t return any values or serves no purpose. As far as design goes, it should be easy to read and be well commented out. So, everyone who is reading algorithm’s instructions can easily decipher the meaning. Algorithm should only consist of functions that are built in an expected fashion. Meaning that the algorithm should not include any complex features copied from some other procedures, especially if there is a risk that they may contain constructs whose functionality and quality may negatively impact it. On the other hand, a re-use of the components of an algorithm is always encouraged, mainly to increase effectiveness and limit duplication.
Compare examples of strong and poor algorithms to support your arguments.
Assignment: Design an algorithm that prints whether a student passes or fails a class depending on his/her grade. If it equals or it’s higher than 60, student passes successfully.
Good Algorithm (pseudocode)
- Define ‘Student Grade’ variable as Integer
- If ‘Student Grade’ is not empty continue to Step 3, otherwise Exit with error message
- If ‘Student Grade’ is greater than or equal to 60
- Print “Passed”
- Print “Failed”
Bad Algorithm (pseudocode)
- What is Student If more than 60 is result of student grade (print pass) otherwise fail
In a bad algorithm example, we are not able to see the differences between variables and the natural language of the pseudocode. A bad code doesn’t have any error handling, such as the proper code on line 2. It’s also very clear that cramming everything on a single line in a bad example doesn’t serve any purpose. A bad algorithm also doesn’t convey what is the purpose of it, which is evident in an example of a suitable algorithm. A bad code example also shows a mistake in a classification of a variable; it doesn’t print pass if Student’s Grade equals 60.
Algorithms Intro problem solving in computer science (2012) Available at: http://courses.cs.vt.edu/cs2104/Fall12/notes/T16_Algorithms.pdf (Accessed: 17 September 2016).
UKL1_CKIT_501 (2016) Available at: https://elearning.uol.ohecampus.com/bbcswebdav/institution/UKL1/201680_JULY/MS_CKIT/CKIT_501/readings/UKL1_CKIT_501_Week08_LectureNotes.pdf (Accessed: 17 September 2016).
Analysis of algorithms (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Analysis_of_algorithms (Accessed: 17 September 2016).
Algorithm (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Algorithm (Accessed: 17 September 2016).
Regise, D. (2016) What are examples of bad algorithm design?. Available at: https://www.quora.com/What-are-examples-of-bad-algorithm-design (Accessed: 17 September 2016).