Graph Theory
Vector Similarity
Star Graphs
Mathematical Modeling
Network Analysis

similarity between two vectors representing star graphs

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

In the realm of graph theory, star graphs represent an elegant and insightful structure that can be used to model various phenomena. Mathematically, a star graph SnS_n is a tree with one internal node (called the center) and nn leaves. When considering star graphs in computational applications, vectors arising from these graphs often become a focal point. This article delves into the similarities between two vectors representing star graphs, exploring foundational theories, technical examples, and the mathematical underpinnings of such representations.

Vector Representation of Star Graphs

For a star graph SnS_n, it is intuitive to consider a vector representation that character encapsulates the graph's structural properties. In a simplified form, a star graph can be represented with a vector of size equal to the number of nodes. Typically, the center node is assigned a distinct value (often higher or lower), while the leaf nodes are assigned uniform values. Consider the star graph S4S_4:

Center Node: 0 • Leaf Nodes: 1, 1, 1, 1

Its vector representation could be `[0, 1, 1, 1, 1]`.

Defining Similarity

The similarity between two vectors derived from star graphs can be analyzed using various measures:

  1. Cosine Similarity: It measures the cosine of the angle between two vectors, maintaining directionality properties. Simcos(a,b)=abab\text{Sim}_{\cos}(\mathbf{a}, \mathbf{b}) = \frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{a}\| \|\mathbf{b}\|}
    For star graphs, cosine similarity highlights whether two graph vectors have similar orientations.
  2. Euclidean Distance: As a measure of dissimilarity, it calculates the straight-line distance between two points in a multi-dimensional space. d(a,b)=i=1n(aibi)2d(\mathbf{a}, \mathbf{b}) = \sqrt{\sum_{i=1}^{n}(a_i - b_i)^2}
    When applied to star graph vectors, lower Euclidean distances imply greater structural similarity.
  3. Jaccard Index: Given the binary nature (center vs. leaf) features of star graph vectors, the Jaccard Index can serve as a valuable metric. J(A,B)=ABABJ(A, B) = \frac{|A \cap B|}{|A \cup B|}

Example Calculation

Consider two star graphs S5S_5 represented by vectors u=[0,1,1,1,1]\mathbf{u} = [0, 1, 1, 1, 1] and v=[0,1,1,0,1]\mathbf{v} = [0, 1, 1, 0, 1].

Cosine Similarity:

uv=00+11+11+10+11=3\mathbf{u} \cdot \mathbf{v} = 0 \cdot 0 + 1 \cdot 1 + 1 \cdot 1 + 1 \cdot 0 + 1 \cdot 1 = 3

u=02+12+12+12+12=4=2|\mathbf{u}| = \sqrt{0^2 + 1^2 + 1^2 + 1^2 + 1^2} = \sqrt{4} = 2

v=02+12+12+02+12=3|\mathbf{v}| = \sqrt{0^2 + 1^2 + 1^2 + 0^2 + 1^2} = \sqrt{3}

Sim_cos=32×3=32\text{Sim}\_{\cos} = \frac{3}{2 \times \sqrt{3}} = \frac{\sqrt{3}}{2}

Euclidean Distance:

d(u,v)=(00)2+(11)2+(11)2+(10)2+(11)2=1d(\mathbf{u}, \mathbf{v}) = \sqrt{(0 - 0)^2 + (1 - 1)^2 + (1 - 1)^2 + (1 - 0)^2 + (1 - 1)^2} = 1

Jaccard Index:

J(1,1,1,1,1,1,0,1)=34=0.75J({1, 1, 1, 1}, {1, 1, 0, 1}) = \frac{3}{4} = 0.75

Summary Table of Key Points

MetricFormulaPurposeExample Result
Cosine Similarity$\frac\{\mathbf\{a\} \cdot \mathbf\{b\}\}\{|\mathbf\{a\}| |\mathbf\{b\}|\}$Measures directional similarity$\frac\{\sqrt\{3\}\}\{2\}$
Euclidean Distancei=1n(aibi)2\sqrt{\sum_{i=1}^{n}(a_i - b_i)^2}Measures physical distance1
Jaccard IndexlvertABrvertlvertABrvert\frac{\\lvert A \cap B \\rvert}{\\lvert A \cup B \\rvert}Measures overlap in binary attributes0.75

Additional Considerations

Normalization: For meaningful analysis, vectors might require normalization, especially when graph sizes vary.

Dimensionality Reduction: Techniques like PCA can simplify high-dimensional vector data, noting significant patterns without loss of essential information.

Applications: Star graph vectors are pivotal in domains such as network topology, biological data analysis, and hierarchical data interpretation, where ease of node distinction and information flow paths are of interest.

Through understanding these metrics and representations, researchers can leverage the core structural similarities of star graphs, providing new insights into network theory, data science, and algorithm design.


Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

All Rights Reserved.