Arrays
Arrays
Definition
• Array: A data structure that stores multiple elements of the same data
type, which can be accessed using the same identifier.
Types of Arrays
o Example:
▪ Lower Bound: 0
▪ Upper Bound: 8
Declaration in Pseudocode:
o Example:
Declaration in Pseudocode:
Importance of Arrays
• Efficiently store and manage multiple data items of the same type.
• Arrays enable:
Linear Search
Process:
To search for an item in a 1D array (myList), the algorithm follows these steps:
Declare Variables:
Steps:
upperBound ← 8
lowerBound ← 0
INPUT item
found ← FALSE
index ← lowerBound
REPEAT
found ← TRUE
ENDIF
index ← index + 1
IF found THEN
ELSE
ENDIF
Explanation
✓ The loop stops immediately when the item is found, saving unnecessary
comparisons.
Identifier Description
Process:
o Repeat the process for all elements until no swaps are needed.
upperBound <= 8
lowerBound <= 0
top = upperBound
REPEAT
ENDIF
NEXT index
top = top - 1
Variable Description
✓ First Pass:
✓ Subsequent Passes:
✓ Final Pass:
i. Initial list: [19, 27, 36, 16, 42, 21, 89, 55]
ii. Pass 1: [19, 27, 16, 36, 21, 42, 55, 89]
iii. Pass 2: [19, 16, 27, 21, 36, 42, 55, 89]
iv. Pass 3: [16, 19, 21, 27, 36, 42, 55, 89]
v. Sorted list: [16, 19, 21, 27, 36, 42, 55, 89]