Stack, Queue, Recursion and Bit Manipulation PDF
Stack, Queue, Recursion and Bit Manipulation PDF
Stack, Queue, Recursion and Bit Manipulation PDF
Introduction -
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).
Uses -
1) Check balanced parentheses -
https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/`
2) Evaluation of prefix expression -
https://www.geeksforgeeks.org/evaluation-prefix-expressions/
3) Evaluation of postfix expression -
https://www.geeksforgeeks.org/stack-set-4-evaluation-postfix-expression/
http://www.spoj.com/problems/HISTOGRA/
The above question can be solved by [ RMQ(Range minimum query)+Conquer And Divide ]
with c omplexity O(N logN) while it can be easily solved by stack with c omplexity O(N)
Questions -
Easy :
1) https://www.codechef.com/problems/COMPILER and
http://www.spoj.com/problems/ANARC09A/
2) http://www.spoj.com/problems/STPAR/
3) http://codeforces.com/contest/343/problem/B
4) http://www.spoj.com/problems/ONP/
Hard :
1) http://www.spoj.com/problems/MMASS/
2) http://codeforces.com/contest/5/problem/C
3) http://codeforces.com/contest/797/problem/C
4)https://www.hackerearth.com/practice/data-structures/stacks/basics-of-stacks/practice
-problems/algorithm/monk-celebrating-checkpoint/
Introduction -
Like Stack, Queue is a linear structure which follows a particular order in which the
operations are performed. The order is First In First Out (FIFO).The difference between
stacks and queues is in removing. In a stack we remove the item the most recently
added; in a queue, we remove the item the least recently added.
Quiz -
https://www.geeksforgeeks.org/dataa-structure-gq/queue-gq/
Questions -
Refer following links for question based on simple queues
1) HackerEarth -
https://www.hackerearth.com/practice/data-structures/queues/basics-of-queues/practice
-problems/
2) HackerRank -
https://www.hackerrank.com/domains/data-structures?filters%5Bsubdomains%5D%5B
%5D=queues
Priority Queue
Introduction -
Priority Queue is an extension of queue with following properties.
1) Every item has a priority associated with it.
2) An element with high priority is dequeued before an element with low priority.
3) If two elements have the same priority, they are served according to their order in the
queue.
Time Complexity -
Priority queue is implemented using heaps so we get front, rear, size and isEmpty
operation are performed in O(1) while Enqueue and Dequeue operation are performed
in O(log N) Read following article for further details about time compexity of operation in
priority queue and heap
https://www.hackerearth.com/practice/notes/heaps-and-priority-queues/
Questions -
Easy :
1) http://www.spoj.com/problems/PQUEUE/
2)https://www.hackerearth.com/practice/data-structures/trees/heapspriority-queues/prac
tice-problems/algorithm/roy-and-trending-topics-1/
3) http://codeforces.com/problemset/problem/982/B`
4) http://www.spoj.com/problems/PRO/
Hard :
1) www.spoj.com/problems/LAZYPROG/
2) https://www.codechef.com/JULY15/problems/MCHEF
3) http://codeforces.com/problemset/problem/20/C
4) http://codeforces.com/contest/377/problem/B
Introduction :-
1. And ( & )
2. Or ( | )
3. Xor ( ^ )
4. Not ( ~ )
5. Bit shifts
a. Left shift ( << )
b. Right shift ( >> )
Tutorial :-
1. Easy :-
a. https://www.hackerearth.com/practice/algorithms/dynamic-progr
amming/bit-masking/practice-problems/algorithm/when-the-inte
gers-got-upset/
b. https://www.hackerearth.com/practice/basic-programming/bit-m
anipulation/basics-of-bit-manipulation/practice-problems/algorith
m/monk-and-his-friend/
c. https://www.hackerearth.com/practice/basic-programming/bit-m
anipulation/basics-of-bit-manipulation/practice-problems/algorith
m/monks-choice-of-numbers-1/
a. https://www.hackerrank.com/challenges/counter-game/problem
b. https://www.hackerrank.com/challenges/the-great-xor/problem
c. https://www.hackerrank.com/challenges/xor-se/problem
HINT : You can find a pattern in this problem
Introduction :-
Binary search, DFS ( Graph theory ), Merge sort, Quick sort are some
examples of Recursion.
Tutorial :-
1. Hackerearth
2. Geeksforgeeks
Questions :-
1. Easy :-
a. https://www.hackerearth.com/practice/basic-programming/recur
sion/recursion-and-backtracking/practice-problems/algorithm/a-t
ryst-with-chess/
b. https://www.hackerearth.com/practice/basic-programming/recur
sion/recursion-and-backtracking/practice-problems/algorithm/n-
queensrecursion-tutorial/
c. https://www.hackerrank.com/challenges/the-power-sum/proble
m
2. Not that easy :-
a. https://www.hackerearth.com/practice/basic-programming/recur
sion/recursion-and-backtracking/practice-problems/algorithm/ju
mpingjack-488ce744/
b. https://www.hackerrank.com/challenges/repeat-k-sums/problem
c. https://www.hackerrank.com/challenges/arithmetic-expressions/
problem