Algorithmic Design and Data Structure: From one beginner to another

 Algorithmic Design and Data Structure: From one beginner to another 

Introduction 

In developing structured programs, having a good data structure and choosing the right design is essential for efficiency, scalability, readability, and maintainability. Good program structure breaks problems into smaller manageable segments.  

Algorithm Design 

An Algorithm is a series of steps followed to solve a problem. The design of an algorithm is the approach used to solve that problem. It is important to choose an efficient algorithm, as this will impact performance. We measure this performance in time and space complexity. Time complexity is a measure of how much time an algorithm takes, whereas space complexity is a measure of the space that an algorithm takes up in storage. While you may be able to get away with a simple algorithm, it may be that it is inefficient according to these two complexities. For example, you may choose to use a simple linear search algorithm in a program. This algorithm is quick to begin with, but as more elements are added to the array, the algorithm takes more time as it must search every single element in the array. A more efficient algorithm would be the binary search algorithm, as it cuts the elements it must search in half after each step. We can use big O notation to measure these efficiencies.  

Big O notation 

Big O notation is how a programmer measures time and space complexity. Typically following the order of big O notation will help you decide why some algorithms are better than others. The notation is ordered as followed from slowest to fastest 

  • O(n!) - Factorial Time / Space 
  • O(2n) - Exponential Time / Space 

  • O(n2) - Quadratic Time / Space 

  • O(n log n) - Linear Time / Space 

  • O(n) - Linear Time / Space 

  • O(log n) - Logarithmic Time / Space 

  • O(1) - Constant time / Space 

Typically, an algorithm that has better O notation ranking, may be a faster or more efficient algorithm. Looking back at our example from earlier, a linear search algorithm has big O notation of O(n), and binary search has notation O(log n).  

Data Structures 

Data structures define how data is stored, accessed, and manipulated. Some common data structures include arrays, linked lists, stacks, queues, and trees. Each structure has its strengths and weaknesses. These structures also contain big O notation measurements, though with data structures, it may be more beneficial to focus on how you would like to manipulate the structure, rather than the complexity. Understanding the strengths and weaknesses of these data structures will help you make an informed decision on which is best for your program.  

Conclusion 

When thinking about algorithmic design and data structure, it is best to take into account what you want your program to achieve. How can your program achieve that as efficiently as possible. You may use Big O notation as a guide to help you in deciding what structure or algorithm you want to use. Not only should you keep these complexities in mind to efficiently utilize tie and space, but you may want to consider other programmers. If your code were to be looked at by a beginner programmer, would they understand it without much issue? Often a program will be edited in the future by either a different programmer or yourself, so it is essential to keep your code simple and easy to understand if the parameters allow.  

Comments