The explanation of O (m) is correct.
Your explanation would be better if you explained the actions in terms of related list manipulations. It takes O (1) time to add a node to the linked list. And to remove an item, O (n) time is required.
a) Why is insertVertex O (1)?
Inserting a vertex is simply adding a node to the linked list (O (1)) or 2 if the graph is not directed.
b) Why is deleteVertex O (m)?
Removing a vertex means:
1) Delete the linked list (O (1))
2) In the worst case, you will have to remove the vertex from all linked lists: O (m). This O (m) leads to the fact that the number of nodes in all linked lists is m or 2 * m if the graph is not directional.
source share