What is the time complexity of accessing a column by its name in an instance of DataRow?
object Foo(DataRow row, string columnName)
{
// What is the time complexity of the below line O(1) / O(n) / ?
return row[columnName];
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I took a peek with Reflector and can confirm that the code in question has a time complexity of O(1). The actual data is stored in DataColumn instances using a plain old array indexed by record number…one array per column. The DataColumn is obtained from the name via a Hashtable and the record number is obtained directly from the DataRow instance. So you have a hash table lookup and an array lookup both of which are O(1).