Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are "Algorithms" and "Data Structures" treated as separate disciplines?

This question was the last straw; and I've been wondering for a long time about it,

Why do people think about "Algorithms" and "Data structures" as about something that can be separated from each other?

I see a lot of evidence that they're separated in programmers' minds.

  • they request "Data Structures & Algorithms" books
  • they refer to "Data Structures" and "Algorithms" as separate university courses
  • they "know Algorithms", but are "weak in Data Structures" (can't find the link, sorry).
  • etc.

In my opinion "Data Structures" are algorithms, since the concept of "Data Structure" is about Algorithms to operate data that go in and out of the structures. But the opinion seems not a mainstream. What do I miss?

Edit: unfortunately, I did not formulate the question well. A separation of data structures and algorithms in programs people write is natural, since, well, the former is data, and the latter is functions (and in semi-functional frameworks like STL it's the core of the whole thing).

But the points above, and the question itself, refers to the way people think, to the way they arrange the knowledge in their heads. This doesn't have to even relate to the code writing.


Here are some links where people separate "algorithms" and "data structures" when they're the same thing:

  • Revisions: algorithm and data structure
like image 203
P Shved Avatar asked Mar 14 '10 10:03

P Shved


People also ask

Why data structure and algorithm are inseparable from each other?

Data structure are closely tied to algorithms that manipulate the data. So closely tied those algorithms are considered part of the data structure. For example Lined List data structure tells you how the data is saved and also how the data is read and manipulated.

Why is it important that data structure and algorithms should be applied together?

Data structure and algorithms are two of the most important aspects of computer science. Data structures allow us to organize and store data, while algorithms allow us to process that data in a meaningful way. Learning data structure and algorithms will help you become a better programmer.

What is the relationship between data structure and algorithm?

A data structure is a named location that can be used to store and organize data. And, an algorithm is a collection of steps to solve a particular problem. Learning data structures and algorithms allow us to write efficient and optimized computer programs.

Why do we need different data structures?

Data structures make it easy for users to access and work with the data they need in appropriate ways. Most importantly, data structures frame the organization of information so that machines and humans can better understand it.


3 Answers

They are different. Consider graphs, or trees to be more specific. Now, a tree appears to only be a tree. But you can browse it in preorder, inorder or postorder (3 algorithms for one structure).

You can have multiple or only 2 children for one node. The tree can be balanced (like AVL) or contain additional information (like B-tree indexes in data bases). That's different structures. But still you traverse them with the same algorithm.

See it now?

Another point: Algorithms sometimes are and sometimes are not independent from data structures. Certain algorithms have different complexity over different structures (finding paths in graph represented as list or a 2D table).

like image 72
Konrad Garus Avatar answered Sep 20 '22 05:09

Konrad Garus


Algorithms and Data Structures are tightly wound together. Algorithm depends on data structures, if you change either of them, complexity will change considerably. They are not same, but are definitely two sides of the same coin. Selecting a good Data Structure is itself a path towards better algorithm.

For instance, Priority Queues can be implemented using binary heaps and binomial heaps, binary heaps allow peeking at highest priority element in constant time, whereas binomial heaps require O(log N) time for peeking.

So, a particular algorithm works best for that particular data-structure (in a particular context), hence Algorithms and Data Structures go hand-in-hand!

like image 28
N 1.1 Avatar answered Sep 21 '22 05:09

N 1.1


People refer to them as different entities because they are. Suppose I want to find an element from a set of data. If I put that data into an array, the array is a data-structure. Once it's in the array, I can use multiple different algorithms to find the element I'm interested in. I could sort the array (with any of multiple sorts) then use a binary search, I could just check each element linearly, etc. The choice of the array as the data structure I would use as opposed to say, a linked list, is not choosing an algorithm.

That said, it is important to understand one to understand the other. If you do not understand algorithms well then it is not obvious what the advantages and disadvantages of different data structures are, and vice versa. As such, it makes sense to teach them simultaneously. They are however different entities.

[Edit] Think about this: If you look at pseudo-code for most algorithms, a data structure isn't specified. You may have a "list" of elements to iterate through etc, but the exact implementation of that list is unimportant to the correctness of the algorithm.

like image 26
MBennett Avatar answered Sep 19 '22 05:09

MBennett