Course contentsShow
← Computer Science
Lesson 239 of 2,8726. Arrays and Basic CollectionsFree lesson

Common Array Operations

Performing basic operations like insertion, deletion, search, and update on array elements.

Common Array Operations

What you'll learn: The four essential ways to manipulate data inside an array: inserting, deleting, searching, and updating elements.

The Core Operations

Now that you understand what arrays are and how to access their elements, let's look at the everyday tasks you'll perform with them.

Insertion

Adding a new element to an array. In a static array, you typically place values into existing positions. You might add to the end, or shift elements to make room at a specific position.

Example thinking: "I want to add the number 42 at index 2, so I need to move everything from index 2 onward one spot to the right first."

Deletion

Removing an element from an array. Since arrays occupy continuous memory, you often shift remaining elements left to fill the gap, or simply mark a position as "unused."

Example thinking: "Remove the element at index 3, then shift elements 4, 5, 6... each one position left."

Search

Finding whether a value exists in the array and, if so, at what index. You iterate through the array comparing each element until you find a match (or reach the end).

Example thinking: "Does the array contain the value 15? Let me check index 0, then 1, then 2... until I find it or run out of elements."

Update

Changing the value at a specific index. This is the simplest operation—just assign a new value to array[index].

Example thinking: "Change the value at index 4 from 10 to 99."

Think of It Like This

Imagine a row of numbered mailboxes. Inserting means adding a new mailbox and renumbering. Deleting removes one and shifts the rest. Searching is checking each mailbox until you find what you need. Updating simply replaces the contents of one mailbox.

Key Takeaway: The four fundamental array operations—insert, delete, search, and update—form the foundation of working with collections of data in programming.