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

  • SEARCH
  • Home
  • 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 6910137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:46:33+00:00 2026-05-27T08:46:33+00:00

For a homework problem I was asked the question of given a set of

  • 0

For a homework problem I was asked the question of given a set of n nodes and m edges where the graph was represented by an adjacency list, why insertVertex would take O(1) and deleteVertex would take O(m).

I’m not entirely sure of my answer, but I put that insertVertex is O(1) because when you first insert, all you add to the array is one node and a set of adjacent vertices (meaning vertices that your new node points to). Thus this time complexity is constant. However, when you remove a node, not only do you have to remove the node and the adjacent edges that come with the node, you also have to go through the rest of the m edges to make sure that you remove the ones that point to the node that you are trying to remove (since you can’t have an edge that points to nothing.

I’m new to graph theory so I don’t know if my way of thinking is correct.

  • 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-05-27T08:46:33+00:00Added an answer on May 27, 2026 at 8:46 am

    The O(m) explanation is right.

    Your explanation would be better if you explained the actions in terms of linked list manipulations. It takes O(1) time to append a node to a linked list. And it takes O(n) time to delete an item.

    a) Why insertVertex is O(1)?

    Inserting a vertex is just appending a node to a linked list (O(1)) or 2 if the graph is undirected.

    b) Why deleteVertex is O(m)?

    Deleting a vertex means:

    1) Delete a linked list (O(1))

    2) In the worst case you will have to remove the vertex from all the linked lists: O(m). It’s O(m) cause the number of nodes in all the linked lists is m, or 2*m if the graph is undirected.

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

Sidebar

Related Questions

Okay, so I have another question on a prolog homework problem I am struggling
I'm trying to solve this problem, its not a homework question, its just code
Okay one of my homework problems is to take a list of lists and
I needed some help/pointers on a homework problem. I would really appreciate it if
This is a question for a homework problem that I cant figure out: Question
This is a homework problem - so I would appreciate if you could tell
Does anyone know an algorithm for the following problem: Given a undirected connected graph
I have a question about my homework problem. Here is the problem: Write a
I was taught HMM and given this homework problem. I understood a part of
This is not a homework problem. This questions was asked to one of my

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.