in DS recategorized by
2,848 views
0 votes
0 votes

Select a data structure that you have seen previously, and discuss its strengths and limitations.

in DS recategorized by
2.8k views

2 Answers

3 votes
3 votes
AVL Tree

Strength:

1.Balanced bst so searching of any element will give O(logn) in worst case.
2.Finding Minimum and Maximum can  be done in O(logn) time.

3.Insertion and Deletion of element can also be done in O(logn) time.
On Insertion at most 1 place problem(imbalance)  can occur so max 2 rotations required.On deletion height may change so max logn problems can occur.
4.Creation of AVL tree takes O(nlogn) ,also it can be used to create normal binary search trees which otherwise take O(n^2) time.

Limitations:

1.Maintaining pointers in case of link list representation (extra space req)
2.After every insertion/deletion,Balance property need to be checked and in case it violate ,rotations are required which increases its complexity compared to some other data structures for ex Arrays,
edited by
1 vote
1 vote
Well this a pretty subjective question. As one can take any data structure he likes and say the pros and cons of it.

I would give the answer for the data structure Array.

Strengths:
1. Random accesses : We can access any element of an array using the index value and the base address of the array. Every element can be accessed in O(1) time (assuming whole array is in the main memory)
2. Serial allocation : Usually, the arrays occupy consecutive memory locations for its elements. So, we can delete the array in one step by deallocating the whole memory area at once. Another advantage of serial allocation is, if the array is too big, accessing consecutive elements takes fewer disk seeks than say in linked lists(where elements could be scattered across the memory).
3. Faster Search : Algorithms like binary search and interpolated search can only be applied on SORTED arrays.

 Limitations:
1. Deleting/Inserting random elements : When we delete a random element in an array we may need to shift all elements ahead of it left by one place - worst case O(n). Same is the case when we are maintaining a sorted array and want to insert a random element.
2. Unsorted Array is not good for searching when we have very large number of elements - as we need to perform Linear search - O(n) time.
3. Static nature :- In most languages, array are statically allocated. So, we may end of reserving extra space then needed or we may not be able to add more elements as needed.

2 Comments

yes purpose is at the end we'll have many answers with diff  data structures and their properties. Kind of Practice for interviews :)
1
1
So, why not you too start with your favourite data structure :)
1
1

Related questions