I think your professor is looking for an API that uses only one character, not an array. Not an array of characters. I mean, if your separator string is "abcd", you will not split into all instances of "a", "b", "c", "d". If you find the whole line, you will split only.
Your current algorithm is not O (n), because for each element of the input array you are comparing it with each element of the delimiter array. This results in runtime O (n * m).
I do not think that this can be converted to O (n), because each element in the input needs to be compared with each element of the delimiter array. I think that most likely your professor is asking another question regarding an array of delimiters.
public static String[] Split(String input, String delimiter) { List<String> parts = new List<String>(); StringBuilder buff = new StringBuilder(); if (delimiter.Length > 1)
C # String.Split()
takes in an array of delimiters, but I don't think it performs splitting in O (n) time.
If you are looking for String search algorithms, this might be useful. http://en.wikipedia.org/wiki/String_searching_algorithm
edit: I incorrectly referenced the fact that the C # String.Split()
API did not accept an array of delimiters.
source share