Operation: Data Structures and Algorithms
Operation: Data Structures and Algorithms
Operations: Java
1. add(T el): Insert element el in this priority.
NullPointerException if el is null
ClassCastException if the order used by this priority queue
cannot be applied to el.
2. clear(): Remove all the elements from this priority queue.
3. Comparator<? super T> comparator() : Return a comparator
to be used to order elements of this priority queue or null if
Priority Queue: elements are ordered with the method compareTo().
Can be assigned to anable a particular process without affecting 4. contains(Object el): Return true if element el is in this priority
ovarall system operation. queue.
5. offer(T el): Insert element el in this priority.
FIFO rule is broken in these situations. NullPointerException if el is null.
ClassCastException if the order used by this priority queue
In preority queues, elements are dequeued according to their cannot be applied to el.
priority and their current queue position
Operations:
1. clear(): Clear the queue.
Quick Sort 2. isEmpty(): Check to see if the queue is empty.
Best: O(n log(n)) 3. enqueue(el): Put the element el at the end of the queue.
Average: O(n log(n)) 4. dequeue(): Take the first element from the queue.
Worst: O(n2) 5. firstEl() / font() / peek(): Return the first element in the queue
Space worst: O(1) without removing it.
Operation:
Exception: EmptyQueueException 1. clear(): Clear the stack.
2. isEmpty(): Check to see if the stack is empty.
Queue: First in First out Structures. 3. push(el) / offer(el); Put the element el on the top of the stack.
Merge Sort
Can be accessed at both ends 4. pop(): Take the top most element from the stack.
Best: O(n log(n))
Hashing One for adding and one for removing 5. topEl() / peek: Return the topmost element in the stack without
Average: O(n log(n))
Worst: O(n2) removing it
Space worst: O(n)
Circular List Exception: EmptyStackException
Data compression
Insertion Sort
Best: O(n)
Average: O(n2)
Worst: O(n2)
Space worst: O(1)
Breadth-first traversal
Selection Sort A node is visited first, then all it's children, then all its
Best: O(n2) grandchildren,....
Avarage: O(n2)
Worst: O(n2) Pre-order traversal
Space worst: O(1) A node is visited before its descendants
Travel
Breadth First Post-order travelsal
Depth First A node is visited after its descendants
Tree traversal
DIijkstra's Algorithm Is the process of visiting each node in the tree exactly one
Complexity: O(|V|2) time. Ordered tree
Graph
Floy's Algorithm
Complexity: O(|V|3)
Tree
Tree is an abstract model of a hierarchical structure
A tree consists of nodes with a parent-child relation Traversal:
Applications: Organization charts, File systems, Breadth-first traversal is visiting
Programming environments each node starting from the
Internal node: Node with at least one child lowest(or highest) level and moving
External(leaf) node: Node without children down(or up) level by level, visiting
Sub tree: A node with its descendants nodes on each level from left to
Level(depth) max = height Binary Tree right(or from right to left)
A tree which each node has at most 2 children Pre order: Root -> left -> right
Proper/Full binary tree : Every node other than the leaves In order: Left -> root -> right
has 2 children Post order: Left -> right -> root
Complete binary tree: All non-terminal nodes have both their
children, and all leaves are at the same level
Implementing
Arrays (Can't predict the size of the array)
Linked List
Multiway Tree