codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🧮

Data Structures & Algorithms

3 / 65 topics
3Arrays4Linked Lists5Doubly Linked Lists6Circular Linked Lists
Tutorials/Data Structures & Algorithms/Arrays
🧮Data Structures & Algorithms

Arrays

Updated 2026-05-15
10 min read

Arrays

Introduction

In the world of programming, data structures are fundamental building blocks that help organize and manage data efficiently. One of the most basic and widely used data structures is the array. An array is a collection of elements stored in contiguous memory locations, allowing for efficient access and manipulation of data.

Arrays can hold elements of the same type, such as integers, strings, or objects. They are essential for tasks like sorting, searching, and managing collections of items. In this tutorial, we will explore the basics of arrays, their operations, and how to implement them in various programming languages.

Concept

An array consists of a fixed number of elements, each identified by an index. The index typically starts at 0 for most programming languages, meaning the first element is accessed with index 0, the second with index 1, and so on. Arrays can be one-dimensional (a single row or column), two-dimensional (like a table), or multi-dimensional.

Key Characteristics of Arrays

  • Fixed Size: The size of an array is determined at the time of creation and cannot be changed dynamically.
  • Homogeneous Elements: All elements in an array must be of the same data type.
  • Contiguous Memory Allocation: Elements are stored next to each other in memory, which allows for fast access using indices.

Common Operations on Arrays

  1. Accessing Elements: Retrieve the value at a specific index.
  2. Insertion: Add an element at a specified position.
  3. Deletion: Remove an element from a specified position.
  4. Traversal: Iterate through all elements in the array.
  5. Searching: Find the position of a specific element.
  6. Sorting: Arrange elements in ascending or descending order.

Examples

Let's explore how arrays are implemented and used in different programming languages with some practical examples.

Example 1: Creating and Accessing Arrays

Python

# Create an array (list in Python)
my_array = [10, 20, 30, 40, 50]

# Access elements
print(my_array[0])  # Output: 10
print(my_array[2])  # Output: 30

JavaScript

// Create an array
let myArray = [10, 20, 30, 40, 50];

// Access elements
console.log(myArray[0]);  // Output: 10
console.log(myArray[2]);  // Output: 30

Example 2: Insertion and Deletion

Python

# Insert an element at a specific position
my_array.insert(2, 25)  # Inserts 25 at index 2
print(my_array)         # Output: [10, 20, 25, 30, 40, 50]

# Delete an element at a specific position
del my_array[3]        # Deletes the element at index 3 (which is 30)
print(my_array)         # Output: [10, 20, 25, 40, 50]

JavaScript

// Insert an element at a specific position
myArray.splice(2, 0, 25);  // Inserts 25 at index 2
console.log(myArray);       // Output: [10, 20, 25, 30, 40, 50]

// Delete an element at a specific position
myArray.splice(3, 1);     // Deletes the element at index 3 (which is 30)
console.log(myArray);       // Output: [10, 20, 25, 40, 50]

Example 3: Traversal and Searching

Python

# Traverse the array
for element in my_array:
    print(element)

# Search for an element
index = my_array.index(40)  # Returns the index of 40
print(index)                # Output: 3

JavaScript

// Traverse the array
myArray.forEach(element => {
    console.log(element);
});

// Search for an element
let index = myArray.indexOf(40);  // Returns the index of 40
console.log(index);              // Output: 3

What's Next?

After mastering arrays, the next step is to explore more complex data structures like Linked Lists. Linked lists are dynamic and allow for efficient insertion and deletion operations compared to arrays.

Stay tuned for our upcoming tutorial on "Linked Lists" where we will delve into their structure, operations, and implementation in various programming languages.

Info

Arrays are a foundational concept in computer science and programming. Understanding them thoroughly is crucial before moving on to more advanced data structures.


PreviousTypes of Data StructuresNext Linked Lists

Recommended Gear

Types of Data StructuresLinked Lists