What is the difference between ordered, unordered and sorted?

13

These terms are used in some data structures to define how the elements are inserted and maintained, what does each one mean? Sorted and ordered mean the same thing? Unordered does it mean it is random?

    
asked by anonymous 29.11.2016 / 16:38

1 answer

14

Ordered

Or Sorted means that the structure data collection is in some order. In general this means that the input order is used. But it is not defined to be exactly so, only that it has an order. The term is used when regardless of the value added 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 not sorted means that the elements do not have a clearly defined order. It does not mean that it is random, and in general you can list all the elements and have the same result every time you do it on the same data, but since it will not have a definition. There is no guarantee what order this is.

But this is implementation detail. It may be that the next version is not in the same order. It may even be that the next execution is not. The hash function 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 this way with the same roll of data entered, so it is not known to exist. Even if it remains the same, it can not be considered relevant as a characteristic of that structure.

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

There are no guarantees that is the order of input of the values, that the key is a sequence, that is an order according to its values or keys. What can fool people, and so I always say, working is different from being right. Even if you observe a certain order do not take it as something stable. Do not trust what you notice, behind the scenes may be different.

Thereistheunorderedrandomaswell.

Ahashtableisthebestexample.

Sorted

Orsortedmeansthatthereisanorderdefinedbyapreviouslyestablishedcriteriabasedonthevalueoftheelementinsertedinthedatacollection.Thisvaluecaneitherbeakeyortheprimaryvalue.Theneveryclassifiedcollectionisalsoordered.

Atree,initsvariousforms,isthebestexampleofthis.

Somestructuresthatarenormallyorderedmayenduphavingtheirdatasorted,butitdoesnotmeanthatthestructureisconsideredclassified,onlythatinstanceatthatmomenthasthischaracteristic,itiscircumstantial.Soforastructuretobeconsideredsorteditmustguaranteethiscondition.Ingeneralthereisakeythatdeterminestheclassification,aslongasthekeyisconsideredaspartofthevalueoftheelement.Anarrayhasasortedkey,whichisitsindex,butitisnotpartofthevalueoftheelement.

Adatabasetableisordered,ifithasaIDasakey,andthisisalmostmandatory,itcanbeconsideredclassifiedaswell.Anindexisranked,atleastmostofthem.

Otherfeatures

Regardlessoftheseforms,itispossibletounderstandcollectionsasmono-ormultivalued,wherethekeyorvalueisallowedtoberepeated,inthiscaseitisalsonecessarytoanalyzewhetherornottherepeatedonesareorderlyornot,whetherornottheyareclassifiedintheirsubset.

Ifthedataisheterogeneoushowdoesithandleorderorsorting?

I'mcertainlylettingsomethinggo.

Confusionofterms

It'sverycommon,Idoitmyself,peopleusethetermordainedwhentheyactuallymeanclassified.Whatdoesthetag> sorting is almost always wrong in the questions.

    
29.11.2016 / 16:38