Programming Questions
Programming Questions
QUESTIONS
FOR
PLACEMENTS
DATA STRUCTURES
AND
ALGORITHMS
SL.No TOPIC PAGE NO
.
1 ARRAYS 1,2
2 LINKED LIST 3
3 QUEUE 4
4 TREES 5,6
5 HEAP 7
6 STRING 8
8 BACK TRACKING 10
9 PATTERN SEARCHING 11
11 GREEDY ALGORITHMS 14
1
ARRAYS
1. Find a pair in an array of size 'n', whose sum is X
3. Find the number occuring odd number of times in a given array of size 'n'
7. Find the maximum difference between two elements such that larger element
appears after the smaller element
8. Algorithm to merge an array of size 'n' into another array of size 'm+n'.
10. Algorithm to find duplicate elements in O(n) time and O(1) extra space, for a given
array of size 'n'
11. Find the index in an array such that the sum of elements at lower indices is equal to
the sum of elements at higher indices.
12. Algorithm to find the maximum difference of j - i such that a[j] > a[i], for a given an
array of 'n' elements.
15. Algorithm to find the largest sub array with equal number of 0's and 1's
16. Algorithm to find the number of triangles that can be formed with three different
array elements as three sides of triangles, for a given unsorted array of n elements
17. Algorithm to find the smallest integer value that can't be represented as sum of any
subset of a given array.
18. Algorithm to find the common element in given three sorted arrays
19. Algorithm to find the contiguous sub-array with maximum sum, for a given array of
postive and negative numbers.
20. Given an array of integers, sort the array into a wave like array and return it.
(arrange the element into a sequence such that a1>=a2<=a3>=a4<=a5----etc.
21. Algorithm to find the next greater number formed after permuting the digits of given
number
22. Algorithm to find the sum of bit difference in all pairs that can be formed from array
of n elements.
24. Algorithm to find the minimum number of platforms required for the railway station
so that no train waits according to arrival and departure time
2
ARRAYS
25. Rotate 2-Dimentional array
27. Rearrange an array so that a[i] becomes a[a[i]] with O(1) extra space
29. Given an array consisting 0's, 1's and 2's, write a algorithm to sort it
30. Given a positive number X, print all jumping numbers(all adjacent digits in it differ
by 1) smaller than or equal to X
31. Given an array and an integer 'k', find the maximum, for each and every contiguous
subarray of size 'k'
33. Find the maximum value of a[j]-a[i]+a[l]-a[k], for every four indices i, j, k, l such that
i< j < k < l.
3
LINKED LIST
1. Algorithm to find the nth node from end of the linked list
2. Algorithm to find the middle node in a linked list
3. Algorithm to find the intersection point of two linked lists
4. Reversal of linked list
5. Algorithm to detect loop in linked list
6. Algorithm to find starting node of a loop in a linked list
7. Algorithm to check given linked list is palindrome (or) not
8. Algorithm to reverse alternative K nodes in a single linked list
9. Algorithm to clone a linked list with next and random pointer are given...many more
10. Stack
11. Reversal of a stack
12. Algorithm to find next greater element on the right side of an array.
13. Implemention of the following operations in stack in O(1) time. Push(), pop(),
isEmpty(), isFull() and getMin().
14. Algorithm to find the celebrity in minimum number of questions in a party.
15. Algorithm to the stock span problem is a financial problem where we have a series of
'n' daily price for a stock and we need to calculate span of stock’s price for all n days
16. Algorithm to merge overlapping intervals
17. Find the largest rectangular area possible in a given histogram.
18. Given an integer array of size 'n', find the maximum of the minimum’s of every
window size in the array.
19. Calculate minimum number of bracket reversals needed to make an expression
balenced.
20. Design a stack, to find getmin() in O(1) time and O(1) space complexity.
21. Find if an expression has duplicate or not....many more
4
QUEUE
1. Given an array and an integer k, find the maximum for each and every contiguous
subarray of size k.
3. Find the first circular tour that visits all petrol pumps