Insertion Operations

Introduction

Inserting an element into an array sounds trivial until you look at what the machine actually has to do. Because array elements occupy contiguous positions and are reached by index, adding a value anywhere other than the very end forces every element after that point to shift one slot to the right. That shifting is the whole story of insertion: it determines the algorithm you write, the edge cases you must handle, and the cost you pay.

In this topic we work through three cases. Insertion at the end is the cheap case, usually a constant-time operation (amortized, when a dynamic array occasionally has to grow and copy). Insertion at the beginning is the expensive case, because every existing element has to move. Insertion at an arbitrary position sits in between but is analyzed the same way in Big O terms. Alongside JavaScript's built-in methods such as push, unshift, and splice, you should be able to write the manual algorithm yourself: loop backward from the last element, copy each value one position forward, then place the new value in the opened slot.

As you watch the videos below, keep two questions in mind. First, how many elements move for this insertion, and how does that number depend on the insertion position and the array length? Second, what happens to capacity when the array is full? The examples are shown in C in two of the videos and in JavaScript in the third, but the underlying shifting behavior and the resulting O(n) worst case are the same in both languages.

Video 1: Arrays: Insertion — Data Structures in C | 2.7

Glass Box Computing · 6:24 · 3 views · 2mo ago · captions — Watch on YouTube

About this video

A short, focused lesson on inserting an element into an array, presented as part of a sequenced data structures course in C. Based on its title and description, it walks through what happens step by step during an insertion and what it costs to keep the array structure valid, which means handling the shifting of subsequent elements and the position where the new value lands.

Why this video

It isolates insertion as its own operation rather than burying it in a long survey video, so it maps directly onto the Understanding Array Insertion and Manual Insertion Algorithm subtopics.

Video 2: Dynamic Arrays: Access, Insert & Delete — Data Structures in C | 3.7

Glass Box Computing · 5:14 · 6 views · 2mo ago · captions — Watch on YouTube

About this video

This video covers three operations on a dynamic array — access, insertion, and deletion — and contrasts their costs. Its description states the key comparison explicitly: get and set remain O(1), while inserting or deleting in the middle still requires the array's O(n) shift. Expect discussion of how a dynamic (resizable) array behaves differently from a fixed-size one.

Why this video

It supplies the complexity framing for this topic, giving you the constant-time versus linear-time contrast you need for the Time and Space Complexity of Insertion subtopic and for reasoning about insertion position.

Video 3: Array Methods: Adding and Removing Elements | JavaScript Fundamentals Series

Code with Carrie · 4:04 · 7 views · 4mo ago · captions — Watch on YouTube

About this video

A brief JavaScript-focused walkthrough of the built-in array methods used to add and remove elements, aimed at managing lists without manually targeting index numbers. Expect coverage of the standard mutating methods for adding to the end and the front of an array, and how they compare to hand-written index manipulation.

Why this video

It connects the language-agnostic algorithm to the JavaScript syntax this course uses, supporting the Insertion at the End and Insertion at the Beginning subtopics with the built-in methods you will actually call in your code.

How These Videos Support the Learning Outcomes

Together these videos cover both halves of MO1: the Code with Carrie video demonstrates insertion using JavaScript built-in methods, while the two Glass Box Computing videos expose the underlying manual shifting algorithm that you will reimplement yourself. The dynamic array video directly serves MO3 by naming the complexities of access, insertion, and deletion and explaining why middle insertions cost O(n), and it supports MO4 by giving you the constant-time versus linear-time trade-off needed to choose an insertion strategy based on position. Note that these videos do not address searching or multi-dimensional traversal, so MO2 and MO5 are developed through other resources in this module.

About These Videos

These videos were chosen from YouTube on October 2, 2026. Each has captions; the player turns them on. Videos on YouTube can be changed or removed — if one no longer plays, tell your instructor. If a player does not appear, use its Watch on YouTube link.