Learn with a sip of Latte

A Queue is a data structure for storing data similar to Linked List and Stack. In Queue, the order in which data arrives is important. In general, a queue is a line of people or things waiting to be served in sequential order stating at the beginning of the line.

A queue is an ordered list in which insertions are done at one end (rear) and deletion done at other end (front). The first element to be inserted is the first one to be deleted. Hence, it is called as First in First Out(FIFO) or Last in Last Out (LILO).

This is some what similar to Stack. When an element is inserted in a queue, the concept is called EnQueue and when an element is removed from the queue, the concept is called DeQueue.Trying to DeQueue an empty Queue is called as underflow and trying to EnQueue an full queue is called overflow. Generally, we treat them as exceptions.

While implementingstack using array we took one index which first initially point to -1, In this case of 2 stacks we take two index one point to -1 and other point to the end of the array i.e, size of the array.

Algorithms :

Start with two indexes one at the left and other at the right end of the array.

Left index simulate the first stack and second index simulate the right stack.

If we want to put the element in the first stack then put the element at the left index. Similarly, if we want to put the element in the second stackthen put the element at the right index.

A stack is a simple data structure for storing data. In stack, the order in which the data arrives is important. A pile of books is a good example of stack. Astack is an ordered list in which insertion and deletion are done at one end, where end is called top. The last element inserted is the first one to be deleted. Hence, it is called Last in First Out (LIFO) or First in Last Out (FILO) list

In this post, we’ll see the other way of implementing Stack is by Linked List. This is continuation of the previous post about Array implementation of Stack.
In this implementation, push operation is implemented by inserting element at the beginning of the list. Pop operation is implemented by deleting the node from the beginning.
Even you can throw exception instead of printing message in case of pop operation when stack is empty.

A stack is a simple data structure for storing data. In stack, the order in which the data arrives is important. A pile of books is a good example of stack.
A stack is an ordered list in which insertion and deletion are done at one end, where end is called top. The last element inserted is the first one to be deleted. Hence, it is called Last in First Out (LIFO) or First in Last Out (FILO) list

In computer science, a stack is a particular kind of abstract data type or collection in which the principal (or only) operations on the collection are the addition of an entity to the collection, known as push and removal of an entity, known as pop. Often a peek or top operation is also implemented, returning the value ofthe top element without removing it.

Stack Operations
Main operations

void push(int data) : Insert data onto stack.

int pop() : Removes and returned last inserted element from the stack

Auxiliary operations

int top() or peek() : Returns the last inserted elements without removing it.

This is one of the basicinterview question about algorithm about finding the two numbers from array such that there sum is equal to K.In this post, we’ll look into different approaches for finding all the pair of integer such that there sum is equal to K.

Approach 1 Brute-ForceIn this approach, for each input elementcheck whether there is any element exist whose sum is K. This can be solved with just two loops.

This is one of basic searching algorithm question.
In this post, we’ll look into different approaches of checking whether array has duplicate elements or not. In addition to this, we’ll also see how to findall duplicate elements from array in one pass.

Approach 1 Brute-Force approach
In this method, for each input elements check whether there is any element with the same value. This we can solve with two loops.