# Data Structures Programs in C, C++, Java and Python | Data Structures questions and solutions

Data Structures and Algorithms consists of some of the most important topics asked by Product companies (* Microsoft, Amazon, D.E Shaw, Directi, Intel, Nutanix, KPIT, etc*) for placement tests. A list of programs based on these topics, ranging from easy to advanced difficulty level is given below with solutions.

**Data structures and Algorithms topics covered:**

*Programs on arrays**Programs on stacks, queues and linked list**Problems on trees and graphs**Dynamic programming problems*

**Get More Updates From Us on WhatsApp**

For aptitude and programming preparation resources, recruitment drive updates, interview tips & tricks, come join the largest learners’ community on Telegram and WhatsApp and take your placement preparation to the next level.

Telegram: https://t.me/placements2020

WhatsApp: http://bit.ly/2MgoYMR/bit.ly/2MgoYMR

**Join here:**Telegram: https://t.me/placements2020

WhatsApp: http://bit.ly/2MgoYMR/bit.ly/2MgoYMR

*Arrays*

*1-D Arrays*

- Basic array operations (Insert, delete and search an element)
- Smallest and largest element in an array
- Sum of elements in an array
- Check if two arrays are the same or not
- Finding the array type
- Sum of positive square elements in an array
- Second smallest element in an array
- Sorting the elements of an array
- Reversing an array
- Longest palindrome in an array
- Count distinct elements of an array
- Print all distinct elements in an array
- Non-repeating elements of an array
- Repeating elements in an array
- Remove duplicate elements in an array
- Minimum scalar product of two vectors
- Maximum scalar product of two vectors
- Can the numbers of an array be made equal?
- Missing elements of a range
- Triplets with a given sum
- Frequency of each element of an array
- Symmetric pairs in an array
- Maximum product subarray in a given array
- Arrays are disjoint or not
- Array is a subset of another array or not
- Can all numbers of an array be made equal
- Minimum sum of absolute difference of given array
- Sorting elements of an array by frequency
- Sort an array according to the order defined by another array
- Replace each element of the array by its rank in the array
- Equilibrium index of an array
- Array rotation – Left and right
- Block swap algorithm for array rotation
- Juggling algorithm for array rotation
- Circular rotation of an array by K positions
- Convert an array into a zig-zag fashion
- Merge two sorted arrays
- Longest subarray having an average greater than or equal to k
- Rearrange positive and negative numbers in an array
- Sum of all odd frequency elements in an array
- Median of two sorted arrays
- 0-1 Knapsack problem
- K’th smallest element in an unsorted array

*2-D Arrays*

- Matrix operations (Addition and subtraction)
- Transpose of a matrix
- Upper triangular matrix or not
- Lower triangular matrix or not
- The maximum element in a row
- The maximum element in a column
- Sum of each row and column of a matrix
- Saddle point coordinates of a given matrix
- Sum of elements in the zig-zag sequence of a matrix
- Sum of boundary elements of a matrix
- Matrix printing in a spiral form
- Rotate the matrix by K times
- Matrix rotation by 90 degrees clockwise and anticlockwise
- Maximum size of square submatrix with all 1’s in a binary matrix

*Stacks, Queues and Lists*

- Stack implementation using arrays
- Stack implementation using a Linked list
- Balanced parenthesis checker
- Redundant braces
- Sorting a stack using a temporary stack
- Infix to postfix using a stack
- Infix to prefix using a stack
- Queue using arrays
- Queue using a linked list
- Circular queue using arrays and Linked list
- Implement stack using a queue
- Implement queue using a stack
- Reversing a queue
- Reverse first k elements of a queue
- Program to return the nth node from the end in a linked list
- Remove duplicates from a linked list
- Reverse a linked list
- Detect a loop in a linked list

*Trees and Graphs*

- Height of a binary tree
- Product of all leaf nodes of binary tree
- Find kth maximum value in a binary search tree
- Graph is a tree or not
- Nodes at “k” distance from the root
- Ancestors of a given node in a binary tree
- The vertical sum of a tree
- Implement Depth First Search (DFS)
- Implement Breadth First Search (BFS)
- Number of edges in an undirected graph
- Shortest path between two vertices
- Trace all paths of a directed graph

*Miscellaneous problems*

- Open and closed gates problem
- Number of Islands
- N digit numbers with digits in non-decreasing order
- Maximum number of A’s using four keys
- Minimum number of jumps to reach the end of an array
- Subset sum problem
- Rat in a maze problem
- Minimum and maximum values of a given expression
- Minimum sum partition problem
- Number of ways to reach the n’th stair
- Word break problem
- Two player coin game
- Sudoku problem
- Maximum sum in a array such that no two elements are adjacent
- Treasure and cities problem