Friday, November 24, 2023

The runtime for traversing all the nodes of a binary search tree with n nodes and printing them in an order is...


 

Answer: O(n)

Top of Form

Printing the elements in an order means the elements should be printed in sorted order.

Inorder traversal of BST gives the sorted order and takes O(n) time.

When a tree is traversed, every node of tree has to be traversed. So, if a tree has n nodes, the time complexity is O(n).

0 comments:

Post a Comment

Data Structures with C++



NET/SET/CS PG



Operating Systems



Computer Networks



JAVA



Design and Analysis of Algorithms



Programming in C++

Top