Why it is important to study data structures?

What are the benefits and why we use to study Data structure and algorithms.

Why it is important to study data structures?

Sometimes it is difficult for students to view where they can apply knowledge that they get during studies. When we (software engineers, developers and etc) were in bachelor degree we learnt a lot of different kind of data structures. Binary Search Tree (BST), AVL Tree, Queue, Stack, Red-Black Tree are the only small part of data structures that we passed.
But after finals most of those data structures, or even all of them will be forgotten. Even if we didn't forget them, we still lack the experience to use them in real application.
Why we need to bother about abstract data structure when we already have implemented array list, vectors, hashmaps in Java (or any other high developed language). 
In this post I would like to give 3 reasons why it is important to learn complex data structures.

Reason #1: Job Interviews

Almost every company, that is hiring a software engineer would ask about data structures or ask you to implement an efficient algorithm for given problem, which will require you to know the needed data structure. And this is where the second reason is coming.

Reason #2: Implement Efficient Algorithms

Choosing the right data structure for the algorithm is one of the key components. Is it better to use array, ArrayList, Vector, or Heap? Depending on what kind of data structure you have chosen, the run time of the algorithm will change drastically.
Consider the problem:
Provide a code for an efficient procedure runningMedian that takes a double parameter and returns a double. Every time runningMedian is called, it returns the median of all the parameters with which it has been called, up to and including the current call. For example, calling runningMedian(5), runningMedian(2), runningMedian(9), runningMedian(12), runningMedian(1) should produce the following return values: 5.0, 3.5, 5.0, 7.0, 5.0
The first and obvious solution that come to mind is to use array to store all previous values, and every time when the runningMedian is called we need to add the input to the array and resort it, then return the median. But the problem is that adding new value to the array requires O(n) time (if you don't have enough space) and the fastest sort algorithm to sort the array  requires O(nlogn) time. At total you will require: O(n) + O(nlogn) time to return the median. Of course you can improve the performance by using dynamic array such as ArrayList or Vector. Despite all of these tweaks (fixes) in worst case you will still need: O(n) + O(nlogn) time.
So what you can do to create  efficient algorithm for the given problem? One effective solution is to use to 1 max-heap and 1 min-heap. Which will give you worst case O(logn) runtime for runningMedian. 
PS: try to solve it by yourself.
PSS: I will write about 3rd reason in another post.
Thank you so much.....

Comments

Popular posts from this blog

Cloud Computing?

C And C++ Programming Languages — Biggest Differences