When we look at a computer screen everything seems to work
seamlessly. We click buttons and are instantly rewarded with what we requested.
There is a lot that goes on behind the scenes to make that type of magic
happen. When we get beyond all of the hardware making that possible, there is
an equivalent amount of software. When that software is broken down, we end up
looking at a lot of data. Data structures and algorithms are the concept of
taking and organizing that data so that the data works effectively within a
program to make that aforementioned magic happen.
As a newbie to using data structures and algorithmic design
its important to note that there are many different data structures. You can
think of a data structure as the different ways of storing data, and algorithms
as the instructions and steps that you can use for a particular data structure.
They work together in tandem. Data structures can be things like lists, arrays,
trees, queues, graphs and matrices. Each of these have specific strengths and
weaknesses. Because of this, one data structure doesn’t predominantly become
the best. They are all situational. It is up to us as programmers to learn when
it is best to use each data structure type.
Let’s say we were creating a program that would run a
playlist of music. We need a data structure to store all of the songs data
within the program. We couldn’t use a tree because that data structure just
doesn’t work for our problem. In our case, a list makes sense. But what kind? A
stack would allow us to go backwards in the order that we added the songs
because if follows LIFO. A queue would do the exact opposite due to it
following FIFO. However, we could use a doubly-linked list which would allow us
to move both backwards and forwards through data.
As you can see by the previous example, there isn’t one
particular data type that will fit each problem. Therefore, when developing
structured programs I would say that it is important to think about the problem
and figure it out what exactly we are attempting to do. From there, we will be
able to decide which data structure will be the most feasible solution to the
problem. Understanding data structures and their strengths and weaknesses will
help you write better programs.
No comments:
Post a Comment