You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notes/graphs/README.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,11 @@ A graph `( G = <V, E> )` data structure consists of a finite (and possibly mutab
6
6
7
7
**Note**: The number of edges `|E|` possible in an undirected graph with `|V|` vertices and no loops: `0 ≤ |E| ≤ |V|(|V| − 1)/2`. We have to divide product `|V|(|V| - 1)` by `2`, however, because it includes every edge twice.
8
8
9
-
####Representation
9
+
### Representation
10
10
11
11
Graph can be represented by using adjacency matrix, adjacency list or incidence matrix. Each implementations has their own pros and cons associated with it either it could be time complexity on operations or space complexity.
12
12
13
-
####Types
13
+
### Types
14
14
15
15
1. Simple graph
16
16
2. Undirected or Directed graphs
@@ -20,7 +20,7 @@ Graph can be represented by using adjacency matrix, adjacency list or incidence
20
20
6. Infinite graphs
21
21
7. Graph having Connected or Disconnected components
22
22
23
-
####Operations
23
+
### Operations
24
24
25
25
1.**Add node `(G, x)`** - adds a node to the graph
26
26
2.**Add edge `(G, x, y)`** - adds an edge from node x to y
@@ -33,7 +33,7 @@ Graph can be represented by using adjacency matrix, adjacency list or incidence
33
33
9.**Breadth First Traversal** - traverses the graph in bfs order
34
34
10.**Depth First Traversal** - traverses the graph in dfs order
35
35
36
-
####BFS Traversal Psuedo code
36
+
### BFS Traversal Psuedo code
37
37
38
38
1. Initialize a queue with starting node in it.
39
39
2. Initialize an empty visited set.
@@ -43,7 +43,7 @@ Graph can be represented by using adjacency matrix, adjacency list or incidence
43
43
- Mark the `currNode` as visited.
44
44
- Expand the `currNode`, add resulting nodes to the queue if they aren't already visited and aren't in the stack.
45
45
46
-
####DFS Traversal Psuedo code
46
+
### DFS Traversal Psuedo code
47
47
48
48
1. Initialize a stack with starting node in it.
49
49
2. Initialize an empty visited set.
@@ -55,7 +55,7 @@ Graph can be represented by using adjacency matrix, adjacency list or incidence
55
55
56
56
**Note**: The way you insert explored nodes into the queue or stack will result into different traversal paths.
57
57
58
-
####Applications
58
+
### Applications
59
59
60
60
1.**Shortest Path**: what is the best route between two cities? Google Maps.
61
61
@@ -65,7 +65,7 @@ Graph can be represented by using adjacency matrix, adjacency list or incidence
65
65
66
66
4.**Topological Sorting**: Dependencies of packages can be represented using graphs and those packages are compiled first which have no dependenies or have dependencies but these have already been compiled.
67
67
68
-
####Terminologies
68
+
### Terminologies
69
69
70
70
A graph with every pair of its vertices connected by an edge is called **complete**.
Heap is a tree based data structure where the tree is a complete binary tree. This binary tree satisfies the properties of heap:
4
+
5
+
1. For max heap, any given node C, if P is a parent node of C, then the key (the value) of P is greater than or equal to the key of C.
6
+
2. For min heap, any given node C, if P is a parent node of C, then the key (the value) of P is less than or equal to the key of C.
7
+
8
+
### Representation
9
+
10
+
Heap can be implemented using binary tree or array.
11
+
12
+
### Types
13
+
14
+
1. Min Binary Heap: Returns the least value node present in the heap.
15
+
2. Max Binary Heaps: Returns the max value node present in the heap.
16
+
17
+
### Operations
18
+
19
+
1.**Insert**: Inserts a node in the heap
20
+
2.**ExtractMin/ExtractMax**: Extracts the min or max value node depending on the type of the heap
21
+
3.**Delete**: Deletes a node from the heap
22
+
4.**Increase/Decrease Key**: Increases or decreases the key value of given node
23
+
24
+
Main functions of heap are:
25
+
26
+
1.**MaxHeapify/MinHeapify (aka Bubble Up)**: This is called after inserting an element, which is inserted in the end of the heap. This function traverses the heap in upward direction while making necessary shifts between nodes.
27
+
2.**Bubble down**: This is called after deleting an element, which is the root of the heap and the last node of the heap is placed there instead. This function traverses downward in direction while making necessary shifts between nodes.
28
+
29
+
### Applications
30
+
31
+
1. Heap Sort: Used to sort the elements in an array
32
+
2. Priority Queue: Used to select the highest priority job
33
+
3. Graph Algorithms: Used in graph algorithms like Dijkstra’s Shortest Path and Prim’s Minimum Spanning Tree
Copy file name to clipboardExpand all lines: notes/linked_lists/README.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,14 @@ In its most basic form, each node contains: data, and a reference (in other word
6
6
7
7
A drawback of linked lists is that access time is linear (and difficult to pipeline). Faster access, such as random access, is not feasible.
8
8
9
-
####Types
9
+
### Types
10
10
11
11
1. Singly Linked List
12
12
2. Circular Linked List
13
13
3. Doubly Linked List
14
14
4. Circular Doubly Linked List
15
15
16
-
####Applications
16
+
### Applications
17
17
18
18
1. Linked Lists can be used to implement Stacks , Queues.
19
19
2. Linked Lists can also be used to implement Graphs. (Adjacency list representation of Graph).
@@ -23,7 +23,7 @@ A drawback of linked lists is that access time is linear (and difficult to pipel
23
23
6. Previous and next page in web browser – We can access previous and next url searched in web browser by pressing back and next button since, they are linked as linked list.
24
24
7. Circular Doubly Linked Lists are used for implementation of advanced data structures like Fibonacci Heap.
25
25
26
-
####Time Complexities
26
+
### Time Complexities
27
27
28
28
- Indexing: Θ(n)
29
29
- Insert/Delete at beginning: Θ(1)
@@ -32,7 +32,7 @@ A drawback of linked lists is that access time is linear (and difficult to pipel
32
32
- Θ(n) when last element is unknown
33
33
- Insert/Delete in middle: search time + Θ(1)
34
34
35
-
####Operations
35
+
### Operations
36
36
37
37
Following operations can be performed on each type of linked lists:
Copy file name to clipboardExpand all lines: notes/queues/README.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,15 @@ A queue is an example of a linear data structure, or more abstractly a sequentia
8
8
9
9
Queue can be implemented using an Array, Stack or Linked List. The easiest way of implementing a queue is by using an Array.
10
10
11
-
####Types of Queues
11
+
### Types of Queues
12
12
13
13
1. Simple Queue
14
14
2. Circular Queue
15
15
3. Double Ended Queue
16
16
4. Circular Double Ended Queue
17
17
5. Priority Queue
18
18
19
-
####Applications
19
+
### Applications
20
20
21
21
1. Scheduling of resources and multiple processes running on same cpu.
22
22
2. When data is transferred asynchronously between two processes, Queue is used for synchronization.
@@ -28,7 +28,7 @@ Queue can be implemented using an Array, Stack or Linked List. The easiest way o
28
28
29
29
Simple Queue can be implemented using Array, Stack or Linked List. Easiest way to implement simple queue is using array.
30
30
31
-
####Operations
31
+
### Operations
32
32
33
33
1. Insert using tail(REAR) pointer.
34
34
2. Delete using head(FRONT) pointer.
@@ -37,7 +37,7 @@ Simple Queue can be implemented using Array, Stack or Linked List. Easiest way t
37
37
38
38
A circular buffer, circular queue, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams.
39
39
40
-
####Operations
40
+
### Operations
41
41
42
42
1. Insert using tail(REAR) pointer.
43
43
2. Delete using head(FRONT) pointer.
@@ -46,7 +46,7 @@ A circular buffer, circular queue, cyclic buffer or ring buffer is a data struct
46
46
47
47
In computer science, a double-ended queue (abbreviated to deque) is an abstract data type that generalizes a queue, for which elements can be added to or removed from either the front (head) or back (tail). It is also often called a head-tail linked list, though properly this refers to a specific data structure implementation of a deque.
48
48
49
-
####Operations
49
+
### Operations
50
50
51
51
1. Insert using tail(REAR) pointer.
52
52
2. Insert using head(FRONT) pointer.
@@ -57,7 +57,7 @@ In computer science, a double-ended queue (abbreviated to deque) is an abstract
57
57
58
58
Cicural Double Ended Queue is a generalized version of Queue data structure that allows insert and delete at both ends.
59
59
60
-
####Operations
60
+
### Operations
61
61
62
62
1. Insert using tail(REAR) pointer.
63
63
2. Insert using head(FRONT) pointer.
@@ -68,13 +68,13 @@ Cicural Double Ended Queue is a generalized version of Queue data structure that
68
68
69
69
In computer science, a priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. In some implementations, if two elements have the same priority, they are served according to the order in which they were enqueued, while in other implementations, ordering of elements with the same priority is undefined.
70
70
71
-
####Operations
71
+
### Operations
72
72
73
73
1. Insert - To insert a new element.
74
74
2. Remove - To remove an element depending upon it's priority. Returns the element which is removed.
75
75
3. Display - Display's the content of queue.
76
76
77
-
####Applications
77
+
### Applications
78
78
79
79
-**Dijkstra’s Shortest Path Algorithm**: When the graph is stored in the form of adjacency list or matrix, priority queue can be used to extract minimum efficiently when implementing Dijkstra’s algorithm.
80
80
@@ -88,7 +88,7 @@ In computer science, a priority queue is an abstract data type which is like a r
88
88
89
89
-**Operating systems**: It is also used in Operating System for load balancing (load balancing on server), interrupt handling.
90
90
91
-
####Time Complexities
91
+
### Time Complexities
92
92
93
93
Time complexities of priority queue depends on which sorting algorithm it uses internally to sort elements based on their priority. Here I have used heap sort algorithm, hence the time complexities will be:
Copy file name to clipboardExpand all lines: notes/stack/README.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
4
4
5
-
####Operations
5
+
### Operations
6
6
7
7
1.**PUSH** - Adds an item in the stack and increments the `top` pointer. If the stack is full, then it is said to be an Overflow condition.
8
8
2.**POP** - Removes an item from the stack and decrements the `top`. The items are popped in the reversed order in which they are pushed. If the stack is empty, then it is said to be an Underflow condition.
@@ -11,15 +11,15 @@ Stack is a linear data structure which follows a particular order in which the o
11
11
5.**DISPLAY** - Displays content of stack.
12
12
6.**getSize** - Returns the size of the stack irrespective of how many elements are in the stack.
13
13
14
-
####Implementation
14
+
### Implementation
15
15
16
16
Stack can be implemented using arrays, linked list or queues. Implementation using arrays is the simplest one.
17
17
18
-
####Time Complexities
18
+
### Time Complexities
19
19
20
20
- push(), pop(), isEmpty() and peek() all take O(1) time. We do not run any loop in any of these operations.
Copy file name to clipboardExpand all lines: notes/trees/README.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -2,24 +2,24 @@
2
2
3
3
**A tree is a type of graph**. A tree data structure can be defined recursively (locally) as a collection of nodes/vertices (starting at a root node), where each node is a data structure consisting of a value, together with a list of references (edges) to nodes (the "children"), with the constraints that no reference is duplicated, and none points to the root.
4
4
5
-
####Types of Trees
5
+
### Types of Trees
6
6
7
7
1.**Binary Tree** - It is a tree where a parent node has at most 2 children.
8
8
2.**Binary Search Tree** - It is a node-based binary tree data structure which has the following properties:
9
9
- The left subtree of a node contains only nodes with keys lesser than the node’s key.
10
10
- The right subtree of a node contains only nodes with keys greater than the node’s key.
11
11
- The left and right subtree each must also be a binary search tree.
12
-
3.**AVL Tree (aka Self Balancing Binary Search Tree)** - It is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than 1 for all nodes and less than -1.
12
+
3.**AVL Tree** - It is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than 1 for all nodes and less than -1.
13
13
4.**Red Black Tree** - A red–black tree is a kind of self-balancing binary search tree in computer science. Each node of the binary tree has an extra bit, and that bit is often interpreted as the color (red or black) of the node. These color bits are used to ensure the tree remains approximately balanced during insertions and deletions.
14
14
15
15
[**Refer here**](https://en.wikipedia.org/wiki/List_of_data_structures) for more information on other types of trees and terminologies used.
16
16
17
-
####Representation
17
+
### Representation
18
18
19
19
1. Linked List - Trees can be represented using linked list where each parent/root node points to its children.
20
20
2. Arrays - Sometimes trees can also be represented using arrays. However, some operations like deletion will take too many shifting of nodes in an array and hence it becomes impractical to implement such operations.
21
21
22
-
####Operations
22
+
### Operations
23
23
24
24
1. Insert - Inserts an element in a tree/create a tree.
25
25
2. Search - Searches an element in a tree.
@@ -31,7 +31,7 @@
31
31
32
32
These are the common operations that can be performed on a tree. Different types of trees has different operations which can be performed.
33
33
34
-
####Applications
34
+
### Applications
35
35
36
36
1. Heap is a tree data structure which is implemented using arrays and used to implement priority queues.
37
37
2. Syntax Tree: Used in Compilers.
@@ -42,7 +42,7 @@ These are the common operations that can be performed on a tree. Different types
42
42
7. Router algorithms
43
43
8. Many search algorithms in Aritificial Intelligence makes use of Trees and Graphs to maintain the search path and to backtrack if needed.
44
44
45
-
####Terminologies
45
+
### Terminologies
46
46
47
47
An **ordered tree** is a rooted tree in which all the children of each vertex are ordered. It is convenient to assume that in a tree's diagram, all the children are ordered left to right.
0 commit comments