PROJECTENGRAM

COMMON ARRAY OPERATIONS & CONSIDERATIONS

Common Array Operations & Considerations

Tags: #◇CCPROG2 #◇C Programming #◇Programming #◇Computer Science #◇Data Structures #◇Data Types #◇Structured Programming #◇Memory Management


◇Overview

Searching: Linear Search, Binary Search (if sorted)

◇Key Concepts

Searching Sorting Insertion/Deletion Size Calculation Assignment

◇Details / Theory

Searching: Linear Search, Binary Search (if sorted) Sorting: Bubble Sort, Selection Sort, Merge Sort, Quick Sort Insertion/Deletion: In static arrays, this requires shifting elements Size Calculation:

『』
C
int size = sizeof(array) / sizeof(array[0]);

Only valid in the scope where the array is defined
Assignment:

『』
C
int a[3] = {1,2,3};
int b[3];
for (int i = 0; i < 3; i++) b[i] = a[i];

◇Common Pitfalls

Using sizeof(arr) inside a function to calculate array size — it returns the pointer size instead; pass the size as a separate parameter Assigning arrays directly (b = a) — C does not support array assignment; use a loop or memcpy() to copy elements Inserting/deleting in the middle without shifting — you must manually shift subsequent elements, which is O(n)O(n) Forgetting to check bounds before accessing or modifying elements — out-of-bounds access is undefined behavior

◇Summary

TL;DR — Common array operations: searching (linear/binary), sorting (bubble/selection/insertion), insertion/deletion (requires shifting, O(n)O(n)), size calculation (sizeof(arr)/sizeof(arr[0]) in declaring scope only), and element-wise copying (loop or memcpy, not direct assignment).

Related: Source / Reference:

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

Which operation generally requires an O(n)O(n) time complexity in an array?

Q2

Why is deleting an element from the middle of an array inefficient?

Q3

What consideration must programmers manually manage when inserting elements into an array?

Common Array Operations & Considerations | PROJECT ENGRAM