function ordering = Greedy_TSP(cities)
disp('Greedy TSP:')
tic
N = length(cities);
visit = zeros(1, N);
ordering(1) = ceil(rand*N);
visit(ordering(1)) = 1;
min_dis = 0;
i = 2;
while i<=N
    dis = [];
    for j = 1:N
        if  visit(j) == 0
            dis(j) = sqrt((cities(j,1)-cities(ordering(i-1),1))^2 + (cities(j,2)-cities(ordering(i-1),2))^2);
        end
    end
    [sorted_dis, indx] = sort(dis);
    for k = 1:length(sorted_dis)
        if sorted_dis(k) ~=0
            min_dis = min_dis+sorted_dis(k);
            visit(indx(k)) = 1;
            ordering(i) = indx(k);
            break;
        end
    end  
    i = i+1;
end

ordering(N+1) = ordering(1);
toc
min_dis = min_dis + sqrt((cities(ordering(N),1)-cities(ordering(N+1),1))^2 + (cities(ordering(N),2)-cities(ordering(N+1),2))^2);

%plot the resulting ordering of cities as
figure;
plot(cities(ordering,1),cities(ordering,2), '-o')
title('Greedy TSP');
hold on
for k = 1:N
    text(cities(ordering(k),1),cities(ordering(k),2), num2str(k), 'color', 'r', 'FontSize',18);
end
hold off


min_dis
ordering