Question

what is Associative array – the languages that have them and how it is implemented. •...

what is Associative array – the languages that have them and how it is implemented.

• Difference between regular arrays and associative arrays – implement in code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Associative arrays are abstract data types that are supported in certain languages.These are collection of key value pairs. Associative arrays basically helps to form an assocaition between the key and the data it stores.

In a normal array elements are indexed starting from 0.In associative arrays the key could be any data type user's wants.For example :

arr={}

arr['Derrick'] = 80

arr['Ben']=90

In this example we have fromed assocaition between name of a student and the marks of the student.

Associative arrays offer faster access time as compared to linear data structure like array.

Associative arrays are supported by various languages like Perl, Python, Ruby, PHP, Lua, JavaScript,C/C++ etc.

Independent of the language associative arrys offer for the following operations in every platform add(),remove(),delete(),search().

Now let us look at the difference in implementation of a normal array and associative array in C++.

In C++ associative arrays are called map or dictionaries.In the next lines of code we'll make use of map stl to implement associative arrays.

C++ implementation of highlighting difference between array and associative array.

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
int arr[3]={80,90,100}; //this array stores the marks of the student
cout<<arr[0]<<endl;; //print the marks of the first student

map <string,int> m; //this is declaration of map that stores string and integer key value pair
m["Derrick"]=80;
m["Ben"]=90;
m["Shawn"]=100;

cout<<m["Ben"]; //this is different from normal array as we can print marks by searching
//the key inside the associative array.Hence it provides faster searching
//than normal array
return 0;
}


Add a comment
Know the answer?
Add Answer to:
what is Associative array – the languages that have them and how it is implemented. •...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT