This week's resource article describes an algorithm as, "a procedure that you can write as a C function or program, or any other language. An algorithm states explicitly how the data will be manipulated." (Complexity Analysis, n.d.).
The length of time a program takes to complete a given task depends on its algorithm. The algorithm deals with how data is organized and how it is accessed. The biggest considerations for creating applications are time complexity and space complexity.
With time complexity, this refers to the number of operations needed and the time it takes it takes for them to run. This is typically measured in milliseconds. Operations are typically: 'compare', 'swap', 'fetch from memory' and 'send to memory'. While each operation takes only a small amount of time; the number of operations that are necessary grow exponentially. As the list of operations grows, so too does the time it takes for them to be enacted.
Space complexity refers to the space or memory an algorithm uses to solve a problem. Exponential growth doesn't occur with space complexity, as it does with time complexity. As an algorithm uses more data, space may be freed up with each computer cycle or keep growing. Running out of memory is something that may occur and must be accounted for.
"Big O notations" or algebraic calculations ultimately determine if time grows by a number equal to the input or if there is an exponential growth in time as input increases. This can also be used to determine if memory usage remains constant or continues to grow with data input.
Are some algorithms and data structure designs better than others?
Algorithms should be selected based on the type of input that is being received. Selecting the appropriate algorithm will have varying effects on performance. With the example of a binary search algorithm, this is an algorithm that should only be used on data that is, or can be, sorted. This refers to when we have a list of sorted numbers and are looking for a specific number. In this scenario, a binary search is more beneficial and faster than a linear search or sequential search.
Developing The Application
When software developers are building a structured program, it is important to scope the project. To know exactly what the purpose will be. Once we clearly define the problem, we can then measure the constraints such as input size, output format and whether or not there are limitations. When that is known, we can then choose an algorithm that best suits this need. Trail and error is the next phase of the process. Testing the algorithm with different inputs will ensure that it works as predicted.
Michael Streat
Works Cited:
Complexity analysis. (n.d.). Retrieved from http://www.cs.utexas.edu/users/djimenez/utsa/cs1723/lecture2.html
Comments
Post a Comment