Data Structures (CS 231)
Data Structures (CS 231)
1A) What are class templates? Write a template class for implementing Stack with push, pop
isEmpty and isFull member functions. Show the instantiation of Stack class for integer and
float types.Use dynamic memory allocation and de-allocation.
1B) What is space complexity of program? Explain briefly the components of space
complexity.
1C) What is Big oh notation?
(10+6+ 4=20)
2A) What is a recursive function? Give the properties of the same. Define arecursive
function to find factorial of a number.
2B) Write an algorithm for evaluation of prefix expression using stack.Also show the steps
for evaluating the following prefix expression using the above algorithm:
-*+4325
2C) Write a C++ function to convert an infix expression to postfix expression using Stack.
Also write the necessary functions. Assume that a template class Stack is defined.
(4+8+8=20)
3A) What are the advantages and disadvantages of linked lists over arrays.
3B) Write a member function to find the union of two sorted singly linked lists, with the
signature, voidlist :: getUnion ( list l1,list l2) { ...} . Write appropriate comments.
3C) Write a recursive function for binary search to search for an item in an array of integers.
Compare its time complexity with linear search in best and worst cases.
(6+8+6=20)
4A) Write an algorithm for DFS of a graph. Also write its time complexity.
4B) Write the iterative member function for level order traversal of a binary tree, with the
signature, voidBinaryTree::levelorder(){ } with node *root as the pointer to root of the
tree.
4C) Write an iterative member function for inorder traversal of a binary tree.
(8+4+8=20)
5A) Write an iterative function for removing largest element from maximum heap.
5B) Sort the following numbers using quick sort:
5, 3, 1, 9, 8, 2, 4, 7
(10+10=20)
CS 231 Page 1 of 2
6A) What is the drawback of linear queue? How is it solved using circular queue?Implement
a class circular queue with the following data members and member functions with
appropriate constructor and destructor functions:
Private Data Members: int rear, front;
Member Functions: isEmpty(), isFull(), cqInsert, cqDelete(), cqDisplay()
6B)Write the following member functions for the doubly linked list with a single private data
member ‘ first’ that points to the first node of the list:
void DLL :: Ins_rear(int x){ } – Insert an element at the rear end of the list.
void DLL ::inv_list(){ } - to reverse a list just by changing the links.
(10+10=20)
7A) What is an expression tree? Write a member function to create an expression tree for the
given postfix expression.
7B)Convert the following infix expression into prefix form and construct an Expression tree
(manually) for the prefix expression obtained.
A+B*C/D-F
7C) Write a recursive function to compare whether two binary trees are equal or not and
returning true or false. Use the following prototype.
inttree_compare( node *t1, node * t2);
(7+6+7=20)
CS 231 Page 2 of 2