I have an algorithm that takes a DAG graph that has n nodes and for every node, it does a binary search on its adjacency nodes. To the best of my knowledge, this would be a O(n log n) algorithm however since the n inside the log corresponds only to the adjacency of a node I was wondering if this would become rather O(n log m). By m I mean the m nodes adjacent to each node (which would intuitively and often be much less than n).
Why not O(n log m)? I would say O(n log m) doesn’t make sense because m is not technically a size of the input, n is. Besides, worst-case scenario the m can be n since a node could easily be connected to all others. Correct?
There are two cases here:
m, the number of adjacent nodes is bounded by a constantC, andm, the number of adjacent nodes is bounded only byn, the number of nodesIn the first case the complexity is
O(n), becauseLog(C)is a constant. In the second case, it’sO(n*log(n))because of the reason that you explained in your question (i.e. “mcan ben)).