RajasekharwhY / Build-your-muscle

Learning concepts and sample practice code - C#, MVC, SQL etc..
2 stars 0 forks source link

Hashset,Dictionary,List difference between them #8

Open RajasekharwhY opened 5 years ago

RajasekharwhY commented 5 years ago

Hashset is a un ordered collection set. retrial is easy and fast : O(1) meaning even though the set grows bigger the time required to find the element is constant O(1). Irrespective of size of the set. it is similar to Dictionary except Dictionary has key,value pair. but in has you have both key and values are same.

1 .A HashSet is a List with no duplicate members.

  1. Because a HashSet is constrained to contain only unique entries, the internal structure is optimised for searching (compared with a list) - it is considerably faster. 3.Adding to a HashSet returns a boolean - false if addition fails due to already existing in Set .) Can perform mathematical set operations against a Set: Union/Intersection/IsSubsetOf etc
  2. HashSet doesn't implement IList only ICollection
  3. You cannot use indices with a HashSet, only enumerators.
  4. You can perform set operations.

List is a index based ..you can access the list by index. A List is a class designed to give you a collection with O(1) random access than can grow dynamically (think dynamic array). You can test containment in O(n) time (unless the list is sorted, then you can do a binary search in O(log n) time).