Dynamic Array vs Associative Array

What is the advantage of Dynamic array over Associative array?
Why we use dynamic array if we have associative array?

In reply to Aviiinash:
Must be interview season.

A dynamic array gets created with a variable size and stays that size in a contiguous block of memory. Its elements are indexed starting with integer 0. This is most efficient way of accessing a block of memory, especially when you need to access to the entire array.

Each element of an associative array gets allocated as you access them. So there is a lot more overhead for the creation of an associative array versus the same size dynamic array. And since the elements of an associative array are not always in a contiguous block of memory, there is overhead in accessing each element. (i.e. have to check if the element is allocated, and then where is it located)

The benefit of an associative array is since each element gets allocated individually, you don’t need to allocate a contiguous set of array elements. This is useful when you only plan to access a relatively few (sparse) elements of an memory address space. Another benefit is that you don’t have to use an integer as an index to each element. You can associate any type of key, like a string to access each element.

In reply to dave_59:

thanks dave!
have a nice day…