What is the difference between ordered, unordered and Sorted?

Asked

Viewed 1,515 times

17

These terms are used in some data structures to define how elements are inserted and maintained, which means each? Sorted and ordered wants to say the same thing? Unordered means it’s random?

1 answer

18


Ordered

Or ordained, means that the structure’s data collection is in some order. In general this means that the input order is used. But it is not defined that it is exactly so, only that it has an order. The term is used when regardless of the added value in the element, it is placed in some order.

In most cases the same data entered in different order will produce a different result.

The array is the best example of this type of structure. But most structures are ordered in some way.

Unordered

Or unwarranted, means that the elements do not have a clearly defined order. It doesn’t mean it’s random, and in general you can list all the elements and get the same result every time you do it on the same data, but how they come doesn’t have a definition. There is no guarantee that this order is.

This is implementation detail. It may be that in the next version it is not in the same order. It may be that in the next execution it is not.

For example in a scattering table, the function of hash does not determine the index, it determines a code that will be used to find an index, the index depends on some factors, among them the size of the structure. There will be an order, it will not be random, but it is not guaranteed that it will always be so with the same roll of data entered, then it is not considered to exist. Even if it remains the same, it cannot be considered relevant as characteristic of that structure.

Differences can occur because of the compiler and version used, library, operating system, hardware, configuration, entry order, data volume at the time and even version of the code that creates the objects that are elements of this collection. No matter the reason, do not trust the order you are willing.

There are no guarantees which is the input order of the values, which the key is a sequence, which is an order according to its values or keys. What can fool people, and so I always say: Working is different than being right.

Even if you observe a certain order do not take it as something stable. Do not trust what you observe, behind the scenes can be different.

Os bastidores são diferentes

There is random unordered as well.

A table hash is the best example, at least from a certain point of view.

Sorted

Or ranked means that there is an order defined by a previously established criterion based on the value of the element entered in the data collection. This value can be a key or the main value. So every classified collection is also sorted.

A tree, in its various forms, is the best example of this.

Some structures that are normally ordered may end up having their data sorted, but that doesn’t mean that the structure is considered classified, only that instance at that moment has this characteristic, it’s circumstantial. So for a structure to be considered Sorted She must ensure this condition. In general there is a key that determines the classification, provided that the key is considered as part of the element value.

A array has a classified key, which is its index, but it is not part of the element value.

A database table is sorted if it has a ID as key, and this is almost mandatory, can be considered classified as well. An index is classified, at least most of them.

Other characteristics

Regardless of these forms it is possible to understand the collections as mono or multivariate, where the key or value can be repeated, in this case you also need to analyze whether the repeaters have order or not, whether they are classified or not in their subset.

Whether the data is heterogeneous as it deals with the order or classification?

Surely I’m missing something.

Muddle

It’s very common, I do it myself, people use the term orderly when they actually mean sorted. Which means that the tag is almost always wrong in the questions (why she was renamed).

  • I have a little difficulty understanding the concept of unordered. If a hash function will determine the element’s index in an array, in a sense it is determining an order. No?

  • @bfavaretto took long but edited, pity that I forgot something important I was going to post :)

  • Thanks @Maniero, clarified my question :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.