Linkedin Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
3
of 3 vote

1. TreeSet guarantees arrangement of elements according to their natural ordering always, HashSet doesn't guarantee.
2. TreeSet implements Red-Black Trees(spl Binary Tree, no arrays), while HashSet uses arrays and hashing mechanism.
3. For put, get, contains(), remove: HashSet - O(c), TreeSet - O(log n).

- taojfew August 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess TreeSet needs an ordering between elements, while a HashSet needs a mapping to some key.

- Anonymous August 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

EDIT: TreeSet uses TreeMap that implements RB Trees using Entry object with left, right nodes). HashSet implements HashMap...

- taojfew August 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

TreeSet
- store set in a tree, sorted order of elements (increasing/decreasing) is preserved.
- insertion/removal/searching are O(log n)

HashSet
- store set in a hashmap, order of elements (whether sorted or insertion order) is lost
- insertion/removal/searching are O(1)

LinkedHashSet
- stores set in hashmap, plus a linked list to keep track of order of insertion
- insertion/removal/searching are O(1) , though extra space needed for the linked list
- order of insertion is preserved (due to linked list storing elements in order they are inerted)

- venkat325 November 24, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More