A collection of elements.
- Insertion of element
e
into thei
th position of the listinsert(e, i)
- Removal of element at the
i
th position in the listremove(i)
Example,
Starting with the empty list []
:
insert(1, 0)
yields[1]
insert(3, 1)
yields[1, 3]
insert(5, 2)
yields[1, 3, 5]
insert(2, 1)
yields[1, 2, 3, 5]
remove(2)
yields[1, 2, 5]
- Concatenation of lists
L = concatenate(L1, L2)
Example,
concatenate([1, 2, 5], [1, 3, 8]) = [1, 2, 5, 1, 3, 8]
- Get element at the
i
th position of the listget(i)
- Set element at the
i
th position of the list to the valuee
set(e, i)
- Length
- Total number of elements in the list
Two lists, L1
, L2
, are equal iff.:
L1
andL2
have the same elementsL1
andL2
have the same ordering of elements
Example,
[1, 2, 3] == [1, 2, 3]
[1, 2, 3] != [1, 3, 2]
[1, 1, 1, 2] != [1, 2]
A list L'
is a sublist of the list L
iff.:
L'
has at least one element that is also inL
L'
has the same ordering of these elements as the elements inL
Example,
[1, 2, 3]
is a sublist of[1, 2, 3, 4]
[]
is a sublist of every list[1]
is a sublist of[1, 2]
[1]
is a sublist of[1]
[2, 3]
is not a sublist of[1, 3, 2]
[1, 1, 1, 1, 1]
is not a sublist of[1, 2, 3]
A collection of elements.
- Push element
e
onto the top of the stackpush(e)
- Pop element at the top of the stack off of the stack
pop()
Example,
Starting with the empty stack []
:
push(1)
yields[1]
push(2)
yields[2, 1]
push(3)
yields[3, 2, 1]
pop()
yields[2, 1]
push(4)
yields[4, 2, 1]
- Get the element at the top of the stack
peek()
- Height
- The total number of elements in the stack
Two stacks, S1
, S2
, are equal iff.:
S1
andS2
have the same elementsS1
andS2
have the same ordering of elements
Example,
[1, 2, 3] == [1, 2, 3]
[1, 2, 3] != [1, 3, 2]
[1, 1, 1, 2] != [1, 2]
A stack S'
is a substack of the stack S
iff.:
S'
has at least one element that is also inS
S'
has the same ordering of these elements as the elements inS
Example,
[1, 2, 3]
is a substack of[1, 2, 3, 4]
[]
is a substack of every stack[1]
is a substack of[1, 2]
[1]
is a substack of[1]
[2, 3]
is not a substack of[1, 3, 2]
[1, 1, 1, 1, 1]
is not a substack of[1, 2, 3]
A collection of elements.
- Push element
e
onto the back of the queuepush(e)
- Pop the element at the front of the queue off of the queue
pop()
Example,
Starting with the empty queue []
:
push(1)
yields[1]
push(2)
yields[1, 2]
push(3)
yields[1, 2, 3]
pop()
yields[2, 3]
pop()
yields[3]
- Get the element at the front of the queue
peek()
- Length
- The total number of elements in the queue
Two queues, Q1
, Q2
, are equal iff.:
Q1
andQ2
have the same elementsQ1
andQ2
have the same ordering of elements
Example,
[1, 2, 3] == [1, 2, 3]
[1, 2, 3] != [1, 3, 2]
[1, 1, 1, 2] != [1, 2]
A queue Q'
is a subqueue of the queue Q
iff.:
Q'
has at least one element that is also inQ
Q'
has the same ordering of these elements as the elements inQ
Example,
[1, 2, 3]
is a subqueue of[1, 2, 3, 4]
[]
is a subqueue of every queue[1]
is a subqueue of[1, 2]
[1]
is a subqueue of[1]
[2, 3]
is not a subqueue of[1, 3, 2]
[1, 1, 1, 1, 1]
is not a subqueue of[1, 2, 3]
A collection of elements that does not allow repetition (i.e. every element of the collection is unique) and is unordered.
- Add the element
e
to the setadd(e)
- Remove the element
e
from the setremove(e)
Example,
Starting with the empty set, {}
:
add(1)
yields{1}
add(1)
yields{1}
remove(1)
yields{}
- Intersection of sets
S = intersect(S1, S2)
- Union of sets
S = union(S1, S2)
- Difference of sets
S = difference(S1, S2)
Example,
intersect({1, 2, 3, 4}, {3, 4, 5, 6}) = {3, 4}
union({1, 2, 3}, {4, 5, 6}) = {1, 2, 3, 4, 5, 6}
difference({1, 2, 3}, {3, 4, 5}) = {1, 2}
- Carindality
- The total number of elements in the set
Two sets, S1
, S2
, are equal iff.:
S1
andS2
have the same elements
A corrollary of this is that both sets are subsets of each other.
Example,
{1, 2, 3} == {1, 2, 3}
{3, 2, 1} == {2, 3, 1} == {1, 2, 3}
{} != {0}
{1, 1, 1, 1, 1, 2} == {1, 2}
A set S'
is a subset of the set S
iff.:
- If an element
e
is inS'
, it is also inS
Example,
{}
is a subset of every set- Every set is a subset of itself
{1}
is a subset of{1, 2}
{1, 2, 3}
is a subset of{3, 2, 1}
{1, 2, 3}
is not a subset of{1, 2, 4}
A collection of elements that is unordered.
- Add the element
e
to the multisetadd(e)
- Remove the element
e
from the multisetremove(e)
Example,
Starting with the empty multiset, {}
:
add(1)
yields{1}
add(1)
yields{1, 1}
add(1)
yields{1, 1, 1}
add (2)
yields{1, 1, 1, 2}
remove(1)
yields{1, 1, 2}
remove(2)
yields{1, 1}
- Intersection of multisets
insersect(M1, M2)
- Union of multisets
union(M1, M2)
- Difference of multisets
difference(M1, M2)
- Cardinality
- Total number of elements in multiset
- Multiplicity
- The number of times a given element occurs in the multiset
Two multisets, M1
, M2
, are equal iff.:
M1
andM2
have the same elementsM1
andM2
have the same multiplicities of these elements
Example,
{1, 1, 2, 3} == {3, 1, 2, 1}
{1, 2, 3} != {1, 1, 2, 3}
{1} != {1, 1}
A multiset M'
is a submultiset of the set M
iff.:
- If an element
e
is inM'
, it is also inM
Example,
{}
is a submultiset of every multiset- Every multiset is a submultiset of itself
{1}
is a submultiset of{1, 2}
{1, 2, 3}
is a submultiset of{1, 1, 3, 2}
{1, 2, 3}
is not a submultiset of{1, 2, 4}