answersLogoWhite

0

An array stores elements in a sequential order from zero (or one) up to the size of the array (possibly minus one, if starting from zero). Arrays come from the classic days of computer programming performed with assembler code, where one would often have a base pointer (BP or BX) plus an index (SI or DI) plus a constant offset, if any.

To address the fourth element in an array, one would specify the BP of the array's initial index (index 0), then add an index to it. For example, add [bp+di], ax would add the contents of AX (a 16-bit register) to the memory location referenced by BP with DI added to it, both also 16-bit registers in classic assembler. Some languages, such as BASIC, ignored the zero index or used it for other purposes.

Arrays are generally fixed in size-- reallocation is necessary to increase or decrease the size of the array. They must also be initially allocated with some amount of memory before they can be used. Newer languages offer dynamic arrays, sometimes called vectors (a point with a line that has an infinite length) to represent arrays that automatically scale capacity as it is filled.

Hashes, in contrast, do not use traditional indexes; they are not represented by the bp + di model, but instead use objects as their indices. This leads to certain inconveniences, because objects are not necessarily sorted from smallest to largest, or lexicographical order, but simply by computed indexes based on the key's hash. Most languages smooth out this limitation by using b-trees (binary trees) to store the keys and their indices, so that iterations over the values of the hash are in key order, but this is not strictly a requirement.

Hashes have no maximum size, unlike traditional arrays. Increasing the size of the hash is a simple as assigning a new key a value. In this respect, they are similar to vectors, but they answer an important question: how does one find an element in a vector in constant time? The answer, of course, is that vectors must be traversed from the first index to the target index in order to find the value, so searches require linear time to find a value.

By using keys, the search complexity is reduced from linear time to constant time, offering a significant advantage on looking up data versus using a vector, linked list, or even an array of objects. Hashes use constant time look ups, just like an array does, but gives the added flexibility of specifying how the data is indexed, instead of just a number. This is especially useful for algorithms involving translating data (ETL) or looking up data that meets a certain criteria repeatedly in constant time, which can have a savings factor of hundreds or thousands times more than an array.

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What is the difference between a hash set and a linked hash set?

The only difference is that the LinkedHashSet maintains the order of the items added to the Set but HashSet doesn't maintain any order.


What difference does it make if you remove a period in a hash?

It makes a big difference because if you compared the hash: abcde.fg = hash 1 to abcdefg = hash 3 The results hash 1 and hash 3 are not equal.


What is the difference between hash browns and fancy hash browns?

Not really anything. I've never heard of fancy hash browns but they sound more detailed and have a better taste.


What is the difference between numeric array and associative array?

Numeric array has numbers(+integers) that represent the values Associative array has strings that represent the values


What is the difference between array and string of array?

When we declare an array of characters it has to be terminated by the NULL , but termination by NULL in case of string is automatic.


What is the difference between AES Rijndael symmetric algorithm encryption and a hash algorithm?

678


Difference between vector and array list?

Vectors are thread safe but array lists are not. Hence array lists are faster than Vectors.


What is the minimum absolute difference between any two elements in a given array?

The minimum absolute difference between any two elements in a given array is the smallest positive number that can be obtained by subtracting one element from another in the array.


What are the differences between the NFL hash marks and college hash marks on a football field?

The main difference between NFL and college hash marks on a football field is their width. In the NFL, the hash marks are narrower, measuring 18 feet 6 inches apart, while in college football, the hash marks are wider, measuring 40 feet apart. This difference affects the positioning of the ball for plays and can impact game strategies.


What is the difference between a Magician and a Chorus Line?

A Magician has a cunning array of stunts ...........................................................................


What is Difference between programmable logic array and programmable array logic?

Using and gate - pla is programmable while pal is fixed


What is the difference between a period and a hash symbol in declaring CSS classes?

Period which specifies to a class using (.) or dot operator Where as hash or # specifies to id of a particular attribute of HTML tags