Properties of Various Adts

Total Page:16

File Type:pdf, Size:1020Kb

Properties of Various Adts

Properties of various ADTs

1. LIST

a. can be accessed from front, middle, and end

b. to search for an item:

i. if not sorted:

 it has to be a sequential search. O(n)

 for items not in the list: you have to search until the end

ii. if sorted:

 and if it is implemented as an array or vector it can be searched using binary search. O(log n)

 if searched sequentially and item not in the list you can stop once you passed the place where the item should be, you do not have to search until the end.

c. adding to a sorted list requires finding appropriate location

2. STACK

a. additions and removals are done at one end … the TOP

b. you access the last (newest) item added first (LIFO)

c. you can not add in the middle of a stack

3. QUEUE

a. additions are done at the END of the queue

b. removals are done at the FRONT of the queue

c. you access the first (oldest) item added first (FIFO) d. you can not add in the middle of a queue

4. PRIORITY QUEUE (PQ)

a. it is a variation of a queue that is sorted by priority

b. additions are done in specific positions according to priority

(not controlled by user, it is controlled by the ADT)

c. removals are done at the FRONT of the PQ, just like a regular queue

d. you can access the most important item first, that is the item with the highest priority.

e. Do NOT confuse with sorted list. Here you can only remove from front!!

5. DEQUE

a. it is a combination of stack and a queue

b. you can add and remove from both ends

c. but you can not add or remove from the middle

6. BINARY SEARCH TREE (BST)

a. if traversed inorder produces sorted output

b. additions are easy, only need to find appropriate location by deciding left or right repeatedly (or recursively)

c. removals have different cases depending on whether the node to be removed is a leaf, has one child, or two children, so it is a little bit complicated.

d. search is of O(h) and h=height is at best O(log n) where n=number of nodes. This means the shorter the tree the faster the search. e. it is suitable for applications that require fast searching.

7. AVL TREE

a. a special kind of BST :

it is balanced, which means it is always shortest possible  faster search

b. additions are complicated, because need to keep tree balanced

c. removals are also complicated

d. not suitable if there are a lot of additions and removals all the time

8. B-TREE

a. another kind of balanced trees, but not a binary tree

b. used for huge amount of data

9. HEAP

a. a special kind of Binary Trees, but not a binary search tree

b. it is a complete binary tree

c. can be used to implement priority queues

d. can be used to sort data

e. additions are controlled by the ADT

f. removals always from root

g. Two kinds i. MAX heaps:

largest value in root and its subtrees are also max heaps ii. MIN heaps:

smallest value in root and its subtrees are also min heaps

Recommended publications