Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CSI 218, Practice Problem

Recursion problems:
1. Sum of n numbers using recursion in c
2. Matrix multiplication using recursion in c
3. Using recursion in c find the largest element in an array
4. Prime number program in c using recursion
5. Decimal to binary conversion in c using recursion
6. C program for fibonacci series using recursion
7. Reverse a number using recursion in c program
8. Reverse a string using recursion
9. C Program to Check whether a given String is Palindrome or not using
Recursion
10. Find factorial of a number using recursion in c program
11. Find sum of digits of a number using recursion using cprogram
12. Find power of a number using recursion using c program
13. C Program to find Product of 2 Numbers using Recursion
14. C Program to Perform Binary Search using Recursion

Write a program to reverse a stack using recursion. You are not allowed to use loop constructs like
while, for..etc.
Write a program to sort a Stack using recursion. Use of any loop constructs like while, for..etc is
not allowed.
Write a program to implement a Stack (both Array and Linked List) which will support following
operations
- push() which adds an element to the top of stack.
- pop() which removes an element from top of stack.
- findMiddle() which will return middle element of the stack.
- deleteMiddle() which will delete the middle
element. Push and Pop are standard stack operations.
Write a program to traverse a tree in Inorder sequence without recursion.
Algorithm:
1) Create an empty stack S.
2) Initialize current node as root
3) Push the current node to S and set current = current->left until current is NULL
4) If current is NULL and stack is not empty then
a) Pop the top item from stack.
b) Print the popped item, set current = popped_item->right
c) Go to step 3.
5) If current is NULL and stack is empty then we are done.

5. Write a program to traverse a tree in Inorder sequence without recursion and without STACK.
1. Initialize current as root
2. While current is not NULL
If current does not have left child
a) Print currents data
b) Go to the right, i.e., current = current->right
Else
a) Make current as right child of the rightmost node in current's left subtree
b) Go to this left child, i.e., current = current->left

Write a program to Detect Cycle in a Directed Graph. Suppose, you have a directed graph, check
whether the graph contains a cycle or not. Your function should return true if the given graph
contains at least one cycle, else return false.
Write a Program to Find the Maximum Height of a Tree.
WAP that will check for brackets in a mathematical expression whether it is balanced or not.

Sample Inputs

Sample Outputs

{({})([])}}

Closing bracket overflow

[{{({})([])}}]

Balanced

[{{({})([])})]

Unmatched

(()){{{[]}{[][]}}

Opening bracket overflow

WAP that will evaluate postfix notations using a stack. (Take inputs from a file upto EOF)

Sample Inputs

Sample Outputs

56+82/*3+

Result: 47

23+6*

Result: 30

A system has a 16 byte memory. Therefore it can hold only 8 integers. Initially the memory
is empty. It can perform four operations. They are
1.
2.
3.
4.

Push
Pop
Enqueue and
Dequeue

Here Push, Pop operations maintain the rules of a simple stack and Enqueue, Dequeue
operations maintains the rules of a simple queue. If the memory is full then the system
discards any push or enqueue operation and if the memory is empty then it discards pop

and dequeue operations. Now write a program using the concept of stack and queue to
simulate the system.
Input: Test case will start with an input n that contains the numbers of operations. Next n
line will have the operations. Specifications of operations are given below:
Ex
: Enqueue x // here x is an interger number
D
: Dequeue
Px
: Push x
O
: Pop
Output: Output the final memory status of the system. If the memory is empty print a
message Memory is Empty.

Sample input
12
D
P7
P9
E 13
P 17
D
E 19
D
P 23
O
O
E 18

Sample output
13 17 18

Implement a BST-Binary Search Tree (for integer numbers) that consists of following
operations:
(1)
Insert
(2)
Tree minimum
(3)
Search
(4)
In-order traversal
(5)
Tree successor
(6)
Delete
[Make it Menu driven: 1 means insert, 2 means tree minimum and so on.]

You might also like