+1 vote
in Data Structures & Algorithms I by (88.2k points)
What is a time complexity for checking a string of length n is substring or not?

(a) O (log n!)

(b) O (n!)

(c) O (n^2)

(d) O (n)

My question is taken from Suffix Tree in chapter Trie of Data Structures & Algorithms I

I have been asked this question by my college professor while I was bunking the class.

1 Answer

+1 vote
by (672k points)
selected by
Best answer
Correct option is (d) O (n)

Explanation: Suffix tree is also known as PAT tree or position tree. It allows fast string operation. Total time taken for construction of suffix tree is linear to the length of the tree. To check if a substring is present in a string of a length of n, the time complexity for such operation is found to be O (n).

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.