Data Structures
Overview
different ways of storing data
Array:
Collection of similar items in continuos memory location
Linked list:
- single
- Double
- Circular
Stack:
linear data structure which follows a particular order LIFO or FILO.
Operations:
- push
- pop
- peek
- isempty
Note: we can implement using array and linkedlist
Queue:
linear data structure which follows a particular order LIFO or FILO.
Operations:
- enqueue
- dequeue
- front
- rear
priotity queue: uses max heap, comparator arguement
Operations:
- insert
- getHighestPriority
- deleteHighestPriority
Tree:
non linear datastruture, undirected graph.
Teminologies: root, node, leaf, level, width, depth, height, degree
Types of Representation :
- Sequential
- Array
left child position - 2i+1,right child position - 2i+2, parent position - (i-1)/1, max number of nodes in height = (2^h+1)-1
Types of Travesals:
- Inorder(L/Ro/R)
- Preorder(Ro/L/R)
- Postorder(L/R/Ro)
Types of deletion:
- inorder predecessor(replace root with largest element in left side)
- inorder successor(replace root with lowest element in right side)
Tree Types:
- Full/proper/strict Btree - should have two/zero children
- Complete Btree - last level as left as possible
- Perfect Btree all the leaf at same level
- Degenerate Btree - all nodes having only one child
Types of Binary trees:
- Binary tree: Each node can have maximum two children.
- Binary search tree : Binary tree in which left node should less, right node should high
- AVL tree : self balanced tree. maintain Balance factor = {-1,0,1}
-
Red Black tree : not aggressive self balancing
root should be black, no adjacent continuos red node, new node always red
if we face adjacent red nodes then check parent sibling,
a)if it is black, then realign, exchange color for resligned nodes
b)if it is red, then recolor parent&sibling to black, recheck againt it parent’s parent, if it is (black && not a root) change to red.
if u will face adjacent red nodes means again continue adjacent conditions.
- Splay tree : self balanced tree with recently accessed elements are as root.
- B tree : this try to reduce the height of tree, thus multiple key in root node, called m value.
a) must have m/2 children, b)minimum two parent key 3)all leaf at same level
- B+ tree : each parent key has duplicate at leaf node
Heap:
specialized tree structure with heap property
- MinHeap
- MaxHeap
Hash:
searching technique, key field value is converted to address location
Types of Hashing
- Open hashing (closed addressing)
a) Chaning method - uses Linked list
- Closed hashing (opern addressing)
a) Linear probing - insert next free location (u+i)%10), save formula count as probe
b) quadratic probing - insert free location of (u+i^2)%10), save formula count as probe
c) double hashing - do another hashing(v), then insert free location (u+v* i)%10), save formula count as probe
- Division method(i % m)
Graph:
collection of nodes(vertices) which connected between edges
complete graph: all nodes conneced together(formula = n(n-1)/2)
Terminoloy:
- length = no of edges
- cost = sum of weight at each node
- cyclic = path start and ends in same node
- acyclic = contains no cycle
Advance Data structures:
XOR Linked list:
###