The Basis is a data structure that maintains a set by maintaining a set such that
where .
This requires space.
Add
Add updates to in time and space.
Algorithm
- If , it is easy to prove that is a set such that .
- Otherwise, let , then it is easy to prove that . Update to recursively.
This algorithm solves the problem in time and space.
void add(std::vector<double> x) {
for (int i = 0; i < n; i++) {
if (x[i] == 0) {
continue;
}
if (!b[i]) {
b[i] = x;
break;
}
double d = x[i] / (*b[i])[i];
for (int j = 0; j < n; j++) {
x[j] -= d * (*b[i])[j];
}
}
}Find
Find checks if in time and space.
Algorithm
Lemma
- If , it is easy to prove that .
- Otherwise, let , then it is easy to prove that . Check if recursively.
This algorithm solves the problem in time and space.
bool find(std::vector<double> x) {
for (int i = 0; i < n; i++) {
if (x[i] == 0) {
continue;
}
if (!b[i]) {
return false;
}
double d = x[i] / (*b[i])[i];
for (int j = 0; j < n; j++) {
x[j] -= d * (*b[i])[j];
}
}
return true;
}