Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:09:30+00:00 2026-06-16T05:09:30+00:00

I am writing program to implement k-means clustering. consider a simple input with 4

  • 0

I am writing program to implement k-means clustering.

consider a simple input with 4 vertices a,b,c and d with following edge costs

[vertex1] [vertex2] [edge cost]
a b 1
a c 2
a d 3
b d 4
c d 5

Now I need to make the program run until i get 2 clusters.

My doubt is, in the first step when calculate the minimum distance it is a->b (edge cost 1). Now I should consider ab as a single cluster. If that is the case, what will be the distance of ab from c and d?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:09:31+00:00Added an answer on June 16, 2026 at 5:09 am

    The K-means algorithm works as follows:

    1. choose k points as initial centroids (hence, K-*);
    2. calculate the distance from all vertices to the k centroids choosen;
    3. assign each vertex to the closest centroid;
    4. recalculate the position of the centroids by generating the mean between all the vertices that belong to the centroid (hence, k-means, one mean calculation for each of the k centroids);
    5. go to step 2 and stop when, in step 3, no vertex get assigned to another centroid — or until your error condition gets satisfied.

    In your case, as you have an undirected graph, it’d be better for you to generate the coordinates of each vertex considering the edge distances, and then, apply the algorithm.

    If you don’t want to do this initial process, you may calculate the distance from a vertex to all other reachable vertices, but you’d have to do this for every iteration — which is quite an unnecessary overhead.

    For your undirected graph:

    [vertex1] [vertex2] [edge cost]
    a b 1
    a c 2
    a d 3
    b d 4
    c d 5
    

    The table of distances would be something like:

         a    b    c    d
    a    0    1    2    3
    b    1    0   (1)   4
    c    2   (1)   0    5
    d    3    4    5    0
    
    (1) - b to c = (b to a, a to c) = 3
    

    If this should be your table, simply apply the Dijkstra algorithm on your graph, for each vertex, and consider the resultant table your table of distances.

    The table would have the minimal distances, but, if you have any other policy to calculate it, it’s totally up to you saying how to calculate it.

    Notice also that, if your graph is directed, the matrix will not be symmetric, as it is, in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I am needing to implement regular expressions in a C++ program I am writing,
I decided to implement a very simple program recursively, to see how well Java
I'm writing a program trying to implement a toy XML processor. Right now the
I'm writing a program for an assignment which has to implement LZW compression/decompression. I'm
I am writing following program : ***import os filepath=r'C:\TestData\openfolder.html' abc=open(filepath,'w') abc.writelines('<html><head></head><body>') abc.writelines('<a href=os.startfile(filepath)>First Link</a>\n')
I'm writing a program to implement an algorithm I found in the literature. In
I was writing a C++ program to implement a linked list. On compilation it's
I am currently writing a program to implement an arraylist (or dynamic array) in
I am writing a program that and like to implement data verification system. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.