Data Structure Time Complexity Question #15257
Single Choice Easy

QWhat is the time complexity of a depth-first search (DFS) algorithm on a tree with N nodes?

ID: #15257 Time Complexity 147 views
Question Info
#15257Q ID
EasyDifficulty
Time ComplexityTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A O(1)
  • B O(log N)
  • C O(N)
  • D O(N^2)
Correct Answer

Explanation

In a depth-first search (DFS) algorithm on a tree, each node is visited exactly once, and each edge is traversed once. As a tree has N-1 edges for N nodes, the time complexity of DFS on a tree is proportional to the number of nodes, denoted as O(N).

Share This Question

Challenge a friend or share with your study group.