Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the most efficient solution to some problems require mutable data?

Tags:

haskell

I've been dabbling in Haskell - so still very much a beginner.

I'm been thinking about the counting the frequency of items in a list. In languages with mutable data structures, this is typically solved using a hash table - a dict in Python or a HashMap in Java for example. The complexity of such a solution is O(n) - assuming the hash table can fit entirely in memory.

In Haskell, there seem to be two (mainstream) choices - to sort the data then group and count it or use a Data.Map. If a sort is used, it dominates the run-time of the solution, so the complexity is O(n log n). Likewise, Data.Map uses a balanced tree, so inserting n elements into it will also have complexity O(n log n).

If my analysis is correct, then I assume that this particular problem is most efficiently solved by resorting to a mutable data structure. Are there other types of problems where this is also true? How in general do people using Haskell approach something like this?

like image 436
Eric Fredine Avatar asked Feb 27 '14 17:02

Eric Fredine


People also ask

What is a mutable database?

Mutable data refers to a database structure in which data can be changed. Any data changes made simply overwrite and replace the previous record. This means that previous iterations of data are lost unless there is a system of back-ups and transaction logs that track changes. Mutable databases are record-based, so there are limited spaces for data.

When is an immutable data store the best option?

But, when capturing trends or a traceable history are critical, an immutable data store is the best option. Selecting the appropriate storage for data is critical in today’s data-centric world. With traditional mutable database structures, data changes replace the previous record data.

What are the most common data quality issues?

With this in mind, here are five of the most common data quality issues you're likely to encounter, as well as what to do about them. 1. Duplicated data Duplicated data is an issue every business will have to deal with. This often comes about as the result of siloed processes and multiple systems that record the same information.

What are the benefits of immutable healthcare data structures?

With the deployment of immutable data structures, people will realize the benefit of increased engagement and ownership of their personal healthcare data. Furthermore, clinicians will be better able to deliver appropriate care based on a full and trusted history of patient information. An immutable ledger of all health events would provide:


1 Answers

The question whether we can implement any algorithm with optimal complexity in a pure language is currently unknown. Nicholas Pippenger has proven that there is a problem that must necessarily have a log(n) penalty in a pure strict language compared to the optimal algorithm. However, there is a followup paper which shows that this problem have an optimal solution in a lazy language. So at the end of the day we really don't know. Though it seems that most people think that there is an inherent log(n) penalty for some problems, even for lazy languages.

like image 179
svenningsson Avatar answered Oct 21 '22 11:10

svenningsson