Sorting, Searching, and the Basics of Algorithmic Design


Hello again, newbie Java programmers. This post is a bit more broad than just Java, but it's how I got here so most of my examples might use it. When I first heard about "algorithmic design" my brain almost split in two. Since algorithms, algebra, and well, math in general are very right-brained mechanical concepts and design has always been (to me) a more left-brained, artistic, creative work. But as you'll see here, algorithmic design simply means using the tools of algebra that Java, Python, and other programming languages are so good at implementing to create a good app for your needs. Think of algorithmic methods as tools in your toolbox or brushes in you paint kit and use them to create useful and widely applicable data structure.


How to apply the paint, I mean, algorithms:

To start, take stock of what your functions must do with the data. What kind of sorting needs to take place? In what ways will searching be used to find the right datum for the given need? Sorting and Searching are the places in you program where good algorithmic design really shines. early on, declare variables to give you some framework to work with. You may find that in most cases starting with x = 1 and y = 1 might be the right move. From there you can building sorting methods to suit your needs. 

One example would be for the "insertion sort" (Lysecky, 2015). With insertion sorts, you would sort by check each item (string or integer) compared to the one behind it. If it shows as not sorted by your method, such x<y or x>y, then you would pull one item out (like x) and move it to a temporary storage list, then move the back item up ( like y), then put the item you stored where the y previously was. That's how I think of it as an insertion sort, because you literally take a number out and insert it back. 

Are some algorithms and data structure designs better than others?

This one might immediately illicit an eye roll. You would guess that of course no one algorithm is better than another. But, I would say consider having a default answer of "yes" in your mind when programming. For your specific needs, some algorithms will be much better for you than others. The insertion sort may not fit the bill particularly well. In the case of deciding, consider both the time and space complexity of the algorithm's function (Complexity Analysis). In other words, How much time does it take to run through your lists, and how much memory does it need to run? In some cases, a shell sort may be the better option, but will it work with the specific data structure have? A simple selection sort may require less space and be a better bet. 

In the end, I would apply algorithmic design in a way that would keep the application small and fast. I just needs to work, every time. If it can do that with a few swaps of a selection sort, then that would be the best bet. In other cases, we might need a partitioning algorithm to pivot around a high and low--hint hint: use variables h and l--for those items first (Lysecky, 2015). In all cases, the secret to good design is usability and clarity, but the key to good algorithmic design in time and space complexity. 



References:
Complexity analysis (Links to an external site.)Links to an external site.. (n.d.). Retrieved from http://www.cs.utexas.edu/users/djimenez/utsa/cs1723/lecture2.html

Lysecky, R., Vahid, F., Lysecky, S., & Givargis, T. (2015). Data structures essentials. Retrieved from https://zybooks.zyante.com/#/zybook/DataStructuresEssentialsR25/chapter/1/section/3










Comments