Differences between Array and Dictionary Data Structure Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 3 Likes Like Report Arrays:The array is a collection of the same type of elements at contiguous memory locations under the same name. It is easier to access the element in the case of an array. The size is the key issue in the case of an array which must be known in advance so as to store the elements in it. Insertion and deletion operations are costly in the case of an array since the elements are stored at contiguous memory locations. No modification is possible at the runtime after the array is created and memory wastage can also occur if the size of the array is greater than the number of elements stored in the array.Array representation: C++ // C++ code for creating an array #include <iostream> using namespace std; // Driver Code int main() { // Creating an array int arr[10]={1,2,3,4,5,6,7,8,9,10}; // Printing the array for (int i = 0; i < 10; i++) { cout << arr[i] << " "; } return 0; } Java /*package whatever //do not write package name here */ import java.io.*; class GFG { public static void main (String[] args) { // Creating an array int arr[] = {1,2,3,4,5,6,7,8,9,10}; // Printing the array for (int i = 0; i < 10; i++){ System.out.print(arr[i]+" "); } } } // This code is contributed by aadityaburujwale. Python # Python code for Creation of Array # importing "array" for array creation import array as arr # creating an array with integer type a = arr.array('i', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) # printing the array for i in range(0, 10): # comma is used to generate spaces print(a[i]), C# // C# code for creating an array using System; // Driver Code public class GFG { static public void Main() { // Declaring an array int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Printing the array for (int i = 0; i < arr.Length; i++) { Console.Write(arr[i] + " "); } } } JavaScript <script> // Creating an array let arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] // Printing the array for(let i = 0; i < 10; i++){ document.write(arr[i] + " "); } // This code is contributed by lokesh </script> Output1 2 3 4 5 6 7 8 9 10 Time Complexity: O(1)Auxiliary Space: O(1) Dictionary:A dictionary is a collection of data values. It holds a key: value pair in which we can easily access a value if the key is known. It improves the readability of your code and makes it easier to debugIt is fast as the access of a value through a key is a constant time operationDictionary representation: C++ // C++ program to demonstrate functionality of unordered_map #include <iostream> #include <unordered_map> using namespace std; int main() { // Declare a Dictionary unordered_map<string, int> my_dict; // Adding Elements to the Dictionary my_dict["key1"] = 1; my_dict["key2"] = 2; my_dict["key3"] = 3; // Printing the Dictionary for (auto key : my_dict) cout << "Key: " << key.first << " Value: " << key.second << endl; } // This code is contributed by aadityaburujwale. Java /*package whatever //do not write package name here */ import java.io.*; import java.util.*; class GFG { public static void main (String[] args) { // Declare a Dictionary HashMap<String,Integer> my_dict = new HashMap<>(); // Adding Elements to the Dictionary my_dict.put("key1", 1); my_dict.put("key2", 2); my_dict.put("key3", 3); // Printing the Dictionary for(String key:my_dict.keySet()) { System.out.println("Key: "+ key +", Value: " + my_dict.get(key)); } } } Python # Declaring and initializing a dictionary my_dict = { "key1": 1, "key2": 2, "key3": 3 } # Printing the dictionary print(my_dict) C# using System; using System.Collections.Generic; public class GFG { static public void Main() { // Declare a Dictionary IDictionary<string, int> my_dict= new Dictionary<string, int>(); // Adding Elements to the Dictionary my_dict.Add("key1", 1); my_dict.Add("key2", 2); my_dict.Add("key3", 3); // Printing the Dictionary foreach(var kvp in my_dict) { Console.WriteLine("Key: {0}, Value: {1}", kvp.Key, kvp.Value); } } } JavaScript <script> // Javascript program to demonstrate functionality of map // Declare a Dictionary var my_dict = new Map(); // Adding Elements to the Dictionary my_dict.set("key1", 1); my_dict.set("key2", 2); my_dict.set("key3", 3); // Printing the Dictionary console.log(my_dict); // This code is contributed by Shubham Singh </script> Output{'key3': 3, 'key2': 2, 'key1': 1} Time Complexity: O(1)Auxiliary Space: O(1) Comparison Between Array and Dictionary:#ArrayDictionary 1Stores just a set of objectsRepresents the relationship between pair of objects2 Lookup time is more in the case of array O(N) where N is the size of the array Lookup time is less compared to an array. Generally, it is O(1) 3Elements are stored at contiguous memory locations.Elements may or may not be stored at a contiguous memory location.4Items are unordered, changeable, and do allow duplicatesItems are ordered, changeable, and do not allow duplicates5Items are not represented as key: value pairItems are represented as key: value pair6The values in the array are of the same data typeThe values in dictionary items can be of any data type7Values can be accessed randomly without the need for any keyTo access a value the key is required Create Quiz Comment K kishanpandeyrkt Follow 3 Improve K kishanpandeyrkt Follow 3 Improve Article Tags : DSA Java-Dictionary Explore DSA FundamentalsLogic Building Problems 2 min read Analysis of Algorithms 1 min read Data StructuresArray Data Structure 3 min read String in Data Structure 2 min read Hashing in Data Structure 2 min read Linked List Data Structure 3 min read Stack Data Structure 2 min read Queue Data Structure 2 min read Tree Data Structure 2 min read Graph Data Structure 3 min read Trie Data Structure 15+ min read AlgorithmsSearching Algorithms 2 min read Sorting Algorithms 3 min read Introduction to Recursion 15 min read Greedy Algorithms 3 min read Graph Algorithms 3 min read Dynamic Programming or DP 3 min read Bitwise Algorithms 4 min read AdvancedSegment Tree 2 min read Binary Indexed Tree or Fenwick Tree 15 min read Square Root (Sqrt) Decomposition Algorithm 15+ min read Binary Lifting 15+ min read Geometry 2 min read Interview PreparationInterview Corner 3 min read GfG160 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding Platform 1 min read Problem of The Day - Develop the Habit of Coding 5 min read Like