AlgoScope

Array Insert

Make room by shifting everything after the slot one place right, then write.

Array algorithms and techniques, algorithm, beginner
Slot 2 is empty. Writing 7 into it.5011724324856i
Slot 2 is empty. Writing 7 into it.5011724324856i

Array: Insert 7 at index 2

Step, step 5 of 6

Index 2 is free. Place 7 there.

Cost

Best
O(1)
Average
O(n)
Worst
O(n)
Space
O(1)

Best case is insertion at the end.

Before this

Taught by the same lesson

Array covers these too, in the same run.