TRENDING NOW

no image
Linear Search, Binary Search, Linked List, Stack, Queue, General Tree, Binary Tree, Binary Search Tree, Graph
Introduction to Graph Data Structure:

A graph consists of a set of vertices and a set of edges. The two main ways of representing graphs are adjacency matrix representation and adjacency list representation.

In adjacency matrix representation of a Graph with n vertices and e edges, a two dimensional nxn array , say a , is used , with the property that a[i,j] equals 1 if there is an edge from i to j and a[i,j] equals 0 if there is no edge from i to j.

In adjacency list representation of a graph with n vertices and e edges, there are n linked lists, one list for each vertex in the graph.

The usual operations on the graph are:

1. Indegree(i) – returns the indegree (the number of edges ending on) of the ith vertex
2. Outdegree(i) – returns the outdegree(the number of edges moving out) of the ith vertex)
3. displayAdjMatrix – displays the adjacency matrix for the graph 


Thanks
Mukesh Rajput
no image
Linear Search, Binary Search, Linked List, Stack, Queue, General Tree, Binary Tree, Binary Search Tree, Graph
Introduction to Tree Data Structure:

The Tree is a recursive data structure. A Binary tree consists of a root and two disjoint binary trees called left and right trees. In Binary search tree, every element is distinct and elements in the left subtree are smaller than the root and root is smaller than elements in the right subtree.

The operations on binary search tree are:
1. init (T) – creates an empty Binary search tree by initializing T to NULL
2. insert (T, x) – inserts the value x in the proper position in the Binary search tree
3. search (T, x) – searches if the value x is present in the search tree
4. inOrder (T) – displays the node using inorder traversal of the binary search tree
5. postOrder (T) – displays the node using postorder traversal of the binary search tree
6. preOrder (T) – displays the node using preorder traversal of the binary search tree 


Thanks
Mukesh Rajput
no image
Linear Search, Binary Search, Linked List, Stack, Queue, General Tree, Binary Tree, Binary Search Tree, Graph
Introduction to Queue Data Structure

The Queue is an ordered set of elements in which insertions are from the rear and deletions are from the front. It is a First in First Out structure.

1. Static Implementation:
A Queue is implemented statically by using an array of size MAX to hold stack elements and two integers – front and rear. The ‘front’ stores the position of the current front element and ‘rear’ stores the position of the current rear element of the queue. A queue is a single entity that is a structure made up of the array, rear, and front. The Queue elements can be integers, characters, strings or user-defined types.
The operations to be performed on a Queue are:
1. init (Q) – Create an empty queue by initializing both front and rear to -1 indicating the queue is empty
2. add (Q, x) – adding an element x to the rear end of the queue Q
3. delete (Q) – deletes the element from the front of the queue Q
4. peek (Q) - returns the front element from the queue without deleting the element from the Queue
5. isEmpty (Q) – check if the queue is empty, that is, when rear equals front
6. isFull (Q) – check if the Queue is full which happens when rear equals MAX -1

2. Dynamic Implementation:
A Queue is implemented dynamically by using a Linked list where each node in the linked list has two parts, the data element and the pointer to the next element of the queue. Since Queue should be a single entity, we need to use only one external pointer while here we need two one for the rear and one to the front. To avoid this we use a circular linked list and
Queue pointer is pointing to the rear of the queue. The front can be easily accessed as it is next to rear. The Queue elements can be integers, characters, strings or user-defined types. There is no restriction on how big the Queue can grow.
The operations to be performed on a Queue:
1. init (Q) – Create an empty queue as a circular linked list by initializing S to NULL indicating that the queue is empty.
2. add (Q, x) – Adding an element x to the queue Q requires the creation of node containing x and putting it next to the rear and rear points to the newly added element. This changes the rear pointer Q and the function should return the changed value of Q. The function call will be as follows
Q=add(Q, x);
3. delete (Q) – deletes the front node from the queue Q which is actually next element to the rear pointer Q. However if the queue contains only one element, (Q->next == Q) then deleting this single element can be achieved by making empty Q (Q =NULL). Since the rear pointer Q is changed in this case, the function should return the changed value of Q. The function call will be as follows
Q=delete(Q);
4. peek (Q) - returns the data element in the front (Q->next) node of the Queue Q.
5. isEmpty (Q) – Check if the Queue is empty which is equivalent to checking if Q==NULL


Thanks
Mukesh Rajput
no image
Linear Search, Binary Search, Linked List, Stack, Queue, General Tree, Binary Tree, Binary Search Tree, Graph
Introduction to Stack Data Structure

The stack is an ordered set of elements in which insertion and deletion are from one end of the stack called the top of the stack. It is a Last in First Out structure.

A. Static Implementation:
A stack is implemented statically by using an array of size MAX to hold stack elements and an integer top storing the position of the top of the stack. A stack is a single entity that is a structure made up of both the array and the top. The stack elements can be integers, characters, strings or user-defined types.

The operations to be performed on a stack are:
1. init(S) – Create an empty stack by initializing top to -1 indicating the stack is empty
2. push(S, x) – adding an element x to the stack S
3. pop (S) – deletes and returns the top element from the stack S
4. Peek(S) - returns the top element from the stack S without deleting the element from the stack
5. isEmpty(S) – Check if the stack is empty
6. isFull(S) – check if the stack is full which happens when top equals MAX -1

B. Dynamic Implementation:
A stack is implemented dynamically by using a Linked list where each node in the linked list has two parts, the data element and the pointer to the next element of the stack. The stack is a single entity i.e. a pointer pointing to the top node in the linked list. The stack elements can be integers, characters, strings or user-defined types. There is no restriction on how big the stack can grow.
The operations to be performed on a stack are:
1. init(S) – Create an empty stack S using the linked list and by initializing S to NULL indicating the stack is empty.
2. push(S, x) – Adding an element x to the stack S requires creation of node containing x and putting it in front of the top node pointed by S. This changes the top node S and the function should return the changed value of S. The function call will be as follows
S=push(S,x);
3. pop (S) – deletes the top node from the stack S so that next element becomes the top. Since the top node S is changed function should return the changed value of S. The function call will be as follows
S=pop(S);
4. peek(S) - returns the data element in the top node of the stack S.  
5. isEmpty(S) – Check if the stack is empty which is equivalent to checking if S==NULL


Thanks
Mukesh Rajput
no image
Linear Search, Binary Search, Linked List, Stack, Queue, General Tree, Binary Tree, Binary Search Tree, Graph
What is the difference between Stack and Queue in java?

What is Stack?
A Stack is a first-in, last-out data structure that pops elements in the opposite order than they were pushed. By default, a Stack uses an Array for its internal storage, although this can easily be changed.

What is the queue?
A Queue is a first-in, first-out data structure that pops elements in the same order that they were pushed. By default, a Queue uses an SList for its internal storage, although this can easily be changed.

What is the difference between Stack and Queue in java?
1. A Stack represents a Collection of objects that are in LIFO (Last In First Out Order). A Queue is also a Collection of Objects
similar to a Stack.
2. The Stack class provides operations that allow testing for zero elements, inspection of its topmost element, removal of its topmost element, and the addition of elements. Queues typically order the elements contained within in FIFO order but this is not always the case.


Thanks
Mukesh Rajput