recategorized by
2,891 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 votes
1 votes
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.

Related questions

0 votes
0 votes
0 answers
1
Anshul Shankar asked Sep 11, 2017
418 views
How to understand this: For a connected graph, V = O(E))SOURCE http://www.geeksforgeeks.org/greedy-algorithms-set-5-prims-mst-for-adjacency-list-representation/prims algo...
0 votes
0 votes
1 answer
3
Hardik Vagadia asked Jul 26, 2015
682 views
the number of bit strings of length 8 that will either start with 1 or end with 00 is?a) 32              b) 128              c) 160       ...