Developing applications often
involve algorithmic designs and the use of data structures. An algorithm is
merely a set of instructions that allow a program to complete a task, like
solving a particular problem. Of course, very complex algorithms exist that
require a strong mathematical background, such as those used in asymmetric
cryptography. However, many programming languages include libraries, methods, and
conditional and control flow statements that minimize the complexity of
applying algorithms in an application. For example, Fibonacci numbers follow a
particular sequence: 0, 1, 1, 2, 3, 5, 8, 13, and so on. Each subsequent number
is a result of the following mathematical formula Fn
= Fn-1
+ Fn-2,
with seed values of F0 = 0 and F1
= 1 (GeeksforGeeks, 2022, para. 1). In Java, an object-oriented programming
language, the Fibonacci numbers can be produced using simple algorithms like For
and While loops or recursion, which is a method that calls itself. Figure 1 illustrates
a simple For loop to print a sequence of Fibonacci numbers in Java, while
Figure 2 illustrates the output.
Figure 1
Fibonacci Program Example
Figure 2
Fibonacci Program Example
Output
Like most things in the
physical world, data structures are common. In programming, data structures allow
developers to organize data for computers to use effectively. Consider a
grocery list as an example. Shoppers need to refer to a list of items to
purchase at the grocery store. Consequently, programming languages have data
structures to create lists that hold items, which can be simple data types like
a string or more complex items like objects. A Java program can represent a grocery
list using a variety of data structures. However, for simplicity, Figure 3
illustrates a Java program using a String array to hold a list of items to
purchase at a grocery store and outputs the list to the console, while Figure 4
displays its output.
Figure 3
Grocery List Program
Example
Figure 4
Grocery List Program
Example Output
Lastly, applying a particular algorithm or data structure to a problem can have neutral, positive, or negative benefits to the application’s overall performance and costs. An algorithm can be mathematically calculated using Big O notation, which essentially describes the time complexity of the code through algebraic terms, e.g., O(n). As a result, through Big O notation, one can determine how long an operation can take and the memory it needs to complete. Therefore, in practice, it is essential to consider the implications of using one particular algorithm over another. For example, Amazon contains millions of products, and searching through its catalog requires the most efficient searching and sorting algorithms. Hence, learning about algorithms like selection versus insert sort, or linear versus binary search is vital in a real-world application. While applying algorithmic design and familiarizing yourself with various data structures across many programming languages may seem overwhelming, these concepts, like anything else, become easier to grasp with time and practice.
References
GeeksforGeeks. (2022,
June 28). Program for Fibonacci numbers. https://www.geeksforgeeks.org/program-for-nth-fibonacci-number/
Comments
Post a Comment