# 2014 1. úkol - optimized data storing

## řešení

```function hw1_optimized_data_storing_scheme
clc;

A = oldStorage;

n = size(A,1); % number of records (nodes)
m = size(A,2); % number of records (nodes)
X(:,:) = inf;

for i = 1:n;
for j = i+1:n;
x = A(i,:);
if i ~= j
index = find(A(i,:) == -1, 1);
if index > 0
x(index:m) = [];
end

y = A(j,:);
index = find(A(j,:) == -1, 1);
if index > 0
y(index:m) = [];
end

dist = levenshtein(x, y);
X(i,j) = dist;
X(j,i) = dist;
end
end
end

g = graph(X);
g = spanningtree(g);
mat = edges2matrixparam(g);

sum(mat(mat<inf)) % suma neinf prvku cele matice

graphedit(g)
end```
```function dist = levenshtein(w1, w2)
% calculation of levenshtein distance of two input vectors
m=length(w1);
n=length(w2);
v=zeros(m+1,n+1);
for x=1:m
v(x+1,1)=x;
end
for y=1:n
v(1,y+1)=y;
end
for x=1:m
for y=1:n
if (w1(x) == w2(y))
v(x+1,y+1)=v(x,y);
else
v(x+1,y+1)=1+min(min(v(x+1,y),v(x,y+1)),v(x,y));
end
end
end
dist = v(m+1,n+1);
end```
courses/a4b35ko/ukol-2014-1.txt · Poslední úprava: 2019/01/10 18:46 (upraveno mimo DokuWiki)
Nahoru