Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between indexed and sequential data structure

What exactly is the difference between indexed and sequential data structures? For example, HashSet is an indexed data structure but TreeSet is sequential.

like image 579
Varshh KS Avatar asked May 25 '26 20:05

Varshh KS


1 Answers

Within java, those terms don't have set meanings. The meanings will be obtained from everyday English usage, and from an examination of the types which you listed.

'Indexed' would mean that there is an index associated with a data structure and which can be used to reference elements of the data structure, with the most basic example being an array, which is indexed by integer offset, or Map, which is indexed by key values. Note that this omits a sense of the data structure having a natural order. We can see that arrays have a natural order but Map does not.

'Sequential' would mean that the data structure has an order which may be used to order operations on the elements of the data structure. There is a sense that this should be a natural order, but the term could also mean that there is an order imposed on the data structure which enables iterative operations.

In neither case should the meanings include a reference to particular operations. A data structure may support reading, or writing, or iteration, but won't necessarily support any or all of these. For example, a sequential data structure could support a findFirst operation without allowing iteration as an external operation.

For the two referenced types, HashSet and TreeMap, since these are implementation types, the terms can be used to describe the general properties of the data structure, or can be used to describe properties of the implementation. I'm not sure that is very useful, since the implementation can change.

Note that 'indexed' doesn't imply 'sequential', unless the index values are themselves sequential.

like image 142
Thomas Bitonti Avatar answered May 28 '26 11:05

Thomas Bitonti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!