3.10 Lists Summary Notes
Lists allow algorithms to work with any number of inputs without changing the code.
NOTE: Pseudocode lists begin at index 1
Using a List
Hover over each item below to learn more.
-
Creating
- list ← []Create an empty list
- list ← [value1, value2, ...]Create a list with values
-
Processing
- list[index]Access an element stored at an index in a list
- LENGTH(list)Get the length of a list
- FOR EACH value IN listIterate through every element of a list
-
Altering
- list[i] ← valueAssign a value to a list's index
- INSERT(list, index, value)Insert a value at an index, shifting all elements after that index to the right
- APPEND(list, value)Add a value to the end of a list
- REMOVE(list, index)Remove an element stored at an index from a list, shifting all elements after that index to the left
Linear Search Pseudocode
PROCEDURE linearSearch(list, value)
{
index ← 1
REPEAT UNTIL(index > LENGTH(list))
{
IF(list[index] = value)
{
RETURN(index)
}
index ← index + 1
}
}
Practice problems can be found in this and this Khan Academy link.
Go Back