i need a datastructure in dotnet where i can search an item in constant time.it means that datastructure should implement indexing internally.is dictionary usefull for this purpose or some other one?
Share
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.
Yes, use Dictionary<> (or Hashtable if you are on an older version of .NET). Be sure the objects you are stuffing in the dictionary have a good hash value (look into overriding GetHashCode() and Equals() for your objects you are using as keys in the Dictionary). If your data objects have poor hash codes performance will start to degrade. And yes, to answer your question, looks ups in a hashtable/dictionary should be relatively constant time (books generally say it is O(1), but that’s arguable). The lookup performance will be determined by many factors: