Newbie to Newbie Blog Part Two

As I come to the end of the Data Structures and Algorithms class, I've accepted that java really isn't much different from C++, yet in some ways it has been easier to manage. Maybe the software options that are available now are much better than the ones I used many years ago, and also provide better help when there are errors with the code.

When starting to think about how to write a program, according to Shaffer (2013), two important things to consider are making sure the algorithm is easy to understand and troubleshoot, and also that it makes efficient use of the system resources. We all use algorithms as part of our daily life. Simply put, an algorithm is the steps we take to do something. Lets take for example my commute to work. I live between two train stations and at one station I have a better chance of getting a seat than the other, however it will take me a couple extra minutes to get there. Once I'm on the train, I can take that train all the way to work, or transfer to another train. If I take only one train all the way, I have a much longer distance to walk. On the other hand, if I transfer I have a shorter walk. At a minimum, my trip to work could take 50 minutes, and at most 90 minutes. When analyzing algorithms, this minimum and maximum is referred to as the upper and lower bounds. Every day we make decisions on which sequence of events would yield the best result with the most efficient use of our time and energy. I could decide to track multiple version of routes to work and compare the results to definitively see which route works best. This is the same way many GPS systems give is driving directions; they all use different algorithms to make the best use of time.

Data Structures are used to house the data that algorithms access to accomplish tasks. When considering efficiency, the amount of space needed to house the data while its being processed is also taken into consideration. There are a few common types of data structures that are used: lists, stacks and queues. Each has different characteristics in how they function what they are best used for. Every year I decorate the Christmas tree and have to unpack the decorations. Some of the balls that hang on the tree comes in long tubes. I really hate it when the color ball I want to use was the first ball I put away the previous Christmas, since it is at the bottom of the tube. I have to take out all the balls to get to that one.  This example of the tubes is the way stacks work. Similarly, a queue would have the balls in the tube, but the first ball I put in would have been the first ball I'd get out. However, I have some decorations that are in flat boxes with partitions and I can easily reach in and grab the ball I want without having to remove other balls. This is how lists work. The efficiency of each depends on the task you're trying to accomplish.

No matter what kind of program you are writing, always consider the data as well as the outcomes you want to achieve in terms of the space the data will use and the time it will take to accomplish your task. I hope this post was useful in helping you understand the process by which you can choose an algorithm and structure for your program.

Reference:

Shaffer, C. A. (2013). Data structures and algorithm analysis (Links to an external site.)Links to an external site. (3.2 ed.). Retrieved from http://people.cs.vt.edu/~shaffer/Book/JAVA3elatest.pdf

Post a Comment