Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are data structures used in higher level languages?

I am currently still in school and taking a class on implementing data structures in c++. In my spare time I enjoy programming in "higher level" languages (mostly Ruby with some c#).

So since these higher level languages manage the memory for you, what would you use data structures for? I can understand the need for queues and stacks but would you ever need to use a binary tree in Ruby? or a 2-3-4 tree? Why?

Thanks.

like image 449
vrish88 Avatar asked Mar 24 '09 01:03

vrish88


People also ask

Do data structures exist in all languages?

Data structures and algorithms are not language specific and hence you can use any language be it JavaScript, C, C++, Java or Python.

What is high-level data structure?

Because data structures are higher-level abstractions, they present to us operations on groups of data, such as adding an item to a list, or looking up the highest-priority item in a queue. When a data structure provides operations, we can call the data structure an abstract data type (sometimes abbreviated as ADT).

Which language is best for data structures?

C++: C++ is an object-oriented programming, imperative programming, and generic programming language. It's used in every organization for solving problems based on data structures and algorithms during a coding interview.

Why data structure is not a programming language?

The data structure isn't a programming language like C, C++, Java, etc. It is a set of algorithms that can be used in any programming language to organize the data in the memory. 'n' number of algorithms were proposed to organize the data in memory. These algorithms are referred to as Abstract data types.


2 Answers

So since these higher level languages manage the memory for you, what would you use data structures for?

The main reason for using a data structure is not about garbage collection. But it is about storing data in a way that is efficient in some way. So what matters most is HOW you are organizing the data. Which is exactly what the language can't automatically figure out for you.

Sure the high level language will come with several preloaded data structures (and you should 100% use these preloaded data structures when they are provided instead of making your own), but not all data structures are provided that you may need.

Data structures organize the storage of memory in some way so that the algorithms that run on them can be implemented giving efficient results.

For most tasks you wouldn't need to implement your own data structures. But this depends fully on what you are coding.

I can understand the need for queues and stacks but would you ever need to use a binary tree in Ruby?

There are a lot of examples for using a binary tree, but not in common every day projects, for example you may need to implement huffman coding.

Other data structures can be used to have the space savings and fast lookups of using a trie, or you may need to store a LOT of data with fast lookup by using a btree. Several data structures have specific uses and are optimized for different things. Whether the language is modern or not and whether it has garbage collection or not doesn't change that.

The trend though, is that custom implemented data structures are coded less, and thought about less. A similar argument happens with common algorithms. In more modern languages, like LINQ you simply specify to sort. You don't actually say how to sort.

like image 174
Brian R. Bondy Avatar answered Oct 06 '22 20:10

Brian R. Bondy


In my experience with Python (superficially similar to Ruby), I've never had to implement a binary tree or a hashmap or anything like that. But the reason why has very little to do with managed memory. There are implementations of the most useful structures, like dictionaries (hashmaps) and lists, in the standard library; for speed and efficiency, they're (at least partially) implemented in whatever lower-level language the interpreter is written in and they will almost certainly outperform any custom implementation you may come up with.

like image 21
David Z Avatar answered Oct 06 '22 20:10

David Z