Skip to main content
added 7 characters in body
Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

From Wikipedia,

In computer science, random access (more precisely and more generally called direct access) is the ability to access an item of data at any given coordinates in a population of addressable elements.

In terms of arrays, this basically means that, given the index of an element that you want to get/access from an array, you can directly access this element.

This is a constant-time operation — it always takes you a fixed number of steps to get it done.

If you're curious to know how, given an array a that starts at location 100 in memory, if you're trying to access a[120] (assuming the array has at least 121 elements), this index (i.e., 120) is added to the starting location of the array (i.e., 100) and you get 220 which is the location of a[120] in memory.

This clearly relies on the fact that array elements are contiguous in memory — they live next to each others in order.

When you deal with recursive data structures (e.g., linked-lists, hash tables, etc.) you use dynamic memory allocation. Unlike arrays, the elements of these data structures could be in different locations in memory. So you can never rely on a fact that these elements are contiguous as it's the case with arrays. Therefore, to access an element, you need to access it through a previous/next element. This clearly means that this is not a constant-time operation and thus, you don't have random/direct access.

As for tries, they use a combination of dynamic memory allocation and arrays. We can probably think of them as having random-access either although accessingin case we know the maximum length a word incould have assuming the process of allocating memory is a trieconstant operation. If we don't know the maximum length that a word could have however, then accessing a word mainly depends on theits length of this word.

From Wikipedia,

In computer science, random access (more precisely and more generally called direct access) is the ability to access an item of data at any given coordinates in a population of addressable elements.

In terms of arrays, this basically means that, given the index of an element that you want to get/access from an array, you can directly access this element.

This is a constant-time operation — it always takes you a fixed number of steps to get it done.

If you're curious to know how, given an array a that starts at location 100 in memory, if you're trying to access a[120] (assuming the array has at least 121 elements), this index (i.e., 120) is added to the starting location of the array (i.e., 100) and you get 220 which is the location of a[120] in memory.

This clearly relies on the fact that array elements are contiguous in memory — they live next to each others in order.

When you deal with recursive data structures (e.g., linked-lists, hash tables, etc.) you use dynamic memory allocation. Unlike arrays, the elements of these data structures could be in different locations in memory. So you can never rely on a fact that these elements are contiguous as it's the case with arrays. Therefore, to access an element, you need to access it through a previous/next element. This clearly means that this is not a constant-time operation and thus, you don't have random/direct access.

As for tries, they use a combination of dynamic memory allocation and arrays. We can probably think of them as having random-access either although accessing a word in a trie mainly depends on the length of this word.

From Wikipedia,

In computer science, random access (more precisely and more generally called direct access) is the ability to access an item of data at any given coordinates in a population of addressable elements.

In terms of arrays, this basically means that, given the index of an element that you want to get/access from an array, you can directly access this element.

This is a constant-time operation — it always takes you a fixed number of steps to get it done.

If you're curious to know how, given an array a that starts at location 100 in memory, if you're trying to access a[120] (assuming the array has at least 121 elements), this index (i.e., 120) is added to the starting location of the array (i.e., 100) and you get 220 which is the location of a[120] in memory.

This clearly relies on the fact that array elements are contiguous in memory — they live next to each others in order.

When you deal with recursive data structures (e.g., linked-lists, hash tables, etc.) you use dynamic memory allocation. Unlike arrays, the elements of these data structures could be in different locations in memory. So you can never rely on a fact that these elements are contiguous as it's the case with arrays. Therefore, to access an element, you need to access it through a previous/next element. This clearly means that this is not a constant-time operation and thus, you don't have random/direct access.

As for tries, they use a combination of dynamic memory allocation and arrays. We can probably think of them as having random-access either in case we know the maximum length a word could have assuming the process of allocating memory is a constant operation. If we don't know the maximum length that a word could have however, then accessing a word mainly depends on its length.

added 7 characters in body
Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

From Wikipedia,

In computer science, random access (more precisely and more generally called direct access) is the ability to access an item of data at any given coordinates in a population of addressable elements.

In terms of arrays, this basically means that, given the index of an element that you want to get/access from an array, you can directly access this element.

This is a constant-time operation — it always takes you a fixed number of steps to get it done.

If you're curious to know how, given an array a that starts at location 100 in memory, if you're trying to access a[120] (assuming the array has at least 121 elements), this index (i.e., 120) is added to the starting location of the array (i.e., 100) and you get 220 which is the location of a[120] in memory.

This clearly relies on the fact that array elements are contiguous in memory — they live next to each others in order.

When you deal with recursive data structures (e.g., linked-lists, hash tables, tries, etc.) you use dynamic memory allocation. Unlike arrays, the elements of these data structures could be in different locations in memory. So you can never rely on a fact that these elements are contiguous as it's the case with arrays. Therefore, to access an element, you need to access it through a previous/next element. This clearly means that this is not a constant-time operation and thus, you don't have random/direct access.

As for tries, they use a combination of dynamic memory allocation and arrays. We can probably think of them as having random-access either although accessing a word in a trie mainly depends on the length of this word.

From Wikipedia,

In computer science, random access (more precisely and more generally called direct access) is the ability to access an item of data at any given coordinates in a population of addressable elements.

In terms of arrays, this basically means that, given the index of an element that you want to get/access from an array, you can directly access this element.

This is a constant-time operation — it always takes you a fixed number of steps to get it done.

If you're curious to know how, given an array a that starts at location 100 in memory, if you're trying to access a[120] (assuming the array has at least 121 elements), this index (i.e., 120) is added to the starting location of the array (i.e., 100) and you get 220 which is the location of a[120] in memory.

This clearly relies on the fact that array elements are contiguous in memory — they live next to each others in order.

When you deal with recursive data structures (e.g., hash tables, tries, etc.) you use dynamic memory allocation. Unlike arrays, the elements of these data structures could be in different locations in memory. So you can never rely on a fact that these elements are contiguous as it's the case with arrays. Therefore, to access an element, you need to access it through a previous/next element. This clearly means that this is not a constant-time operation and thus, you don't have random/direct access.

From Wikipedia,

In computer science, random access (more precisely and more generally called direct access) is the ability to access an item of data at any given coordinates in a population of addressable elements.

In terms of arrays, this basically means that, given the index of an element that you want to get/access from an array, you can directly access this element.

This is a constant-time operation — it always takes you a fixed number of steps to get it done.

If you're curious to know how, given an array a that starts at location 100 in memory, if you're trying to access a[120] (assuming the array has at least 121 elements), this index (i.e., 120) is added to the starting location of the array (i.e., 100) and you get 220 which is the location of a[120] in memory.

This clearly relies on the fact that array elements are contiguous in memory — they live next to each others in order.

When you deal with recursive data structures (e.g., linked-lists, hash tables, etc.) you use dynamic memory allocation. Unlike arrays, the elements of these data structures could be in different locations in memory. So you can never rely on a fact that these elements are contiguous as it's the case with arrays. Therefore, to access an element, you need to access it through a previous/next element. This clearly means that this is not a constant-time operation and thus, you don't have random/direct access.

As for tries, they use a combination of dynamic memory allocation and arrays. We can probably think of them as having random-access either although accessing a word in a trie mainly depends on the length of this word.

Source Link
kzidane
  • 17.7k
  • 3
  • 28
  • 100

From Wikipedia,

In computer science, random access (more precisely and more generally called direct access) is the ability to access an item of data at any given coordinates in a population of addressable elements.

In terms of arrays, this basically means that, given the index of an element that you want to get/access from an array, you can directly access this element.

This is a constant-time operation — it always takes you a fixed number of steps to get it done.

If you're curious to know how, given an array a that starts at location 100 in memory, if you're trying to access a[120] (assuming the array has at least 121 elements), this index (i.e., 120) is added to the starting location of the array (i.e., 100) and you get 220 which is the location of a[120] in memory.

This clearly relies on the fact that array elements are contiguous in memory — they live next to each others in order.

When you deal with recursive data structures (e.g., hash tables, tries, etc.) you use dynamic memory allocation. Unlike arrays, the elements of these data structures could be in different locations in memory. So you can never rely on a fact that these elements are contiguous as it's the case with arrays. Therefore, to access an element, you need to access it through a previous/next element. This clearly means that this is not a constant-time operation and thus, you don't have random/direct access.