arrays - Complexity of getting all neighbors of all nodes in adjacency list/matrix -


if want neighbors of 1 node in graph, time complexity o(|v|) if graph stored in adjacency matrix , o(|v|) if it's saved in adjacency list. thinking, how change if did not want neighbors of 1 node instead nodes. (note: adjacency list contains array , linked lists. 1 linked list stored @ each array entry, each array entry represents 1 node. each node in linked list represents adjacent node.)

my though process following:

in adjacency matrix need have @ every single entry. therefore time complexity o(|v|^2). in adjacency list need @ each array entry , go through respective linked list. thinking, should done in o(|e|) because @ edges.

is thinking correct?

the time complexity o(n + m) n = number of vertex in graph & m = number of edges in graph. need apply bfs or dfs algorithm.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -