Vous êtes sur la page 1sur 2

All the queries have been implemented and are working properly on all the sample

test cases.

In this assignment I have made a graph structure to store the triangle as well as
vertices as nodes with their inteconnecting edges.
I have implemented a separate chaining hashtable for storing vertices, a vhashtable
for storing verices using separate chaining(linked list), and a BST for edges.

m - number of edges
n- number of vertices
t - number of triangles

Queries -
ADD_TRIANGLE
In this query I checked if the points form a triangle and if so, added it to all
the data structures.
Time complexity for adding to hashtable = O(t^2) (please check internal
implementation for further idea as to how i have implemented)Time complexity for
adding to vhashtable = O(log n) n - number of vertices(points) in our graph.
(please check internal implementation for further idea as to how i have
implemented).
Time complexity for adding to BST = O(log m) m - number of edges (assuming a decent
BST is formed) (please check internal implementation for further idea as to how i
have implemented).

TYPE_MESH
I have maintained a count for each edge, the number of triangles it is a part of,
so Time complexity = O(1).

BOUNDARY_EDGES -
Recursively traverse the BST so time complexity = O((log m) + p). p -number of
boundary edges.

COUNT_CONNECTED_COMPONENTS
I have maintained a count, time complexiy is = O(1)

IS_CONNECTED
Check if triangle exist = search in hashtable = O(1).
Overall query = O(1)

NEIGHBORS_OF_TRIANGLE -
Check if triangle exist = search in hashtable = O(1).
Overall query time complexity = O(1 + degree) degree = number of neighbours of
queried triangle.

EDGE_NEIGHBOR_TRIANGLE
Check if triangle exist = search in hashtable = O(1).
If so just return its edges, Overall query time complexity = O(1).

VERTEX_NEIGHBOR_TRIANGLE
Check if triangle exist = search in hashtable = O(1).
If so just return its vertices, Overall query time complexity = O(1).

EXTENDED_NEIGHBOR_TRIANGLE
Check if triangle exist = search in hashtable = O(1).
Find the connected triangles list of each vertex of this triangle, merge it and
return.
O(1) - for searching vertices in hashtable
Overall query time complexity = O(number of extended neighbours + 1).
INCIDENT_TRIANGLES
Just search for the vertex in the hashtable
Overall query time complexity = O(1).

NEIGHBORS_OF_POINT
Find triangles connected to the point = O(1)
Contstruct an arraylist of points belonging to these triangles = O((number of
vertices)^2)
convert to array and return this list.
Overall complexity = O((number of vertices)^2 + 1)

EDGE_NEIGHBORS_OF_POINT
Similar to above just repeat for edges
Overall complexity = O((number of edges)^2 + 1)

FACE_NEIGHBORS_OF_POINT
Overall complexity = O(1)

TRIANGLE_NEIGHBOR_OF_EDGE
find arraylist of triangle for both endpoints of edges and take set
intersection(implemented)
p1, p2 - end points of edge
Overall time complexity = O(min(arraylist.size(p1), arraylist.size(p2))

CENTROID
I have maintained an arraylist of arraylist structure to store the components in
the graphs(here I have stored only triangles)
merge sort to sort the lists
so overall complexity = O(s * log s) s - number of components.

CENTROID_OF_COMPONENT
find the component to which the point belong - O(s*l) s - number of components
l - number of verices in that component.
Overall complexity = O(s*l + l)

CLOSEST_COMPONENTS
Iterate over arraylist of arraylists of components and in that iterate over all the
vertices in the list.
The complexity is indeed very high about the order of = O(l^2 * s^2)
l,s as defined in above query.

Vous aimerez peut-être aussi