### Data Structures and Applications – 17CS33 Question Bank 1

### Module 1 & 2 Introduction, Strings, Stacks & Queues

1. Write C program to find max & min of N numbers using pointers?

2. Write a recursive function to implement binary search and trace for 10 numbers.

3. Explain how two-dimensional arrays are represented in memory with an example.

4. Write C structure to represent planets in the solar system. Each planet has fields for the planet’s name its distance from the sun in miles and number of moons it has. Write a program to read the data for each planet that has the highest no of moons.

5. What is Static and Dynamic memory allocation? How is DMA done in C? Explain with examples.

6. Write an algorithm/program to convert infix to postfix expression and apply the same to convert the following expression.

(i) ( ( (a / b + c) + ( d * e ) ) – ( a * c ) )

(ii) ( 15 / 6 ) + 8 * 2 ^ 2 { evaluate its postfix expression}

7. Write C function for inserting & deleting an element in sequential QUEUE.

8. What are the advantages of Circular queue over a linear queue? Write C routines for insert, delete and Display of circular queue.

9. Demonstrate a program to access the elements in 1D and 2D arrays using Dynamic memory allocation.

10. What is a structure in C. Give its syntax? Differentiate it from an array. Give examples.

11. Differentiate structure and union with appropriate examples. What is the advantage of using a union over a structure?

12. What are the ways in which a structure can be passed to a function? Explain with examples.

13. What is a pointer to a structure? Explain with an example how structure members can be accessed with pointers.

14. Write a C structure which represents the details of the inventory of items in a store. The program accepts the value of item name, item code, price, and quantity & manufacture date. The date field is to have three fields, date, month and year. The program displays all fields for N items and also calculates the total quantity of the items available. A separate function may be used for the display.

15. Define a pointer? Explain with examples.

a) NULL pointer (b) Pointer initialization. (c) Pointer De-referencing.

16. (a) Explain how a stack can be implemented using local variables.

(b) Explain the implementation of queue operations using local variables.

(c) Implement the above (a) & (b) using DMA.

(d) Implement stack and queue using structures

17. (a)An array A contains 25 positive integers. Write C routine to do the following operations on the array (i)insert an element (ii)delete an element (iii) display the contents

(b) Find the number of elements which are even and the number of elements which are odd.

18. (a)Write an algorithm for evaluating a postfix expression

(b)Evaluate the following postfix expression using the algorithm.

(i) ab/c-de*+ac*- , given a=2,b=2,c=3,d=4,e=1 (ii) 231*+9-

19. What is pointer arithmetic? What are the operations possible on pointers? Illustrate with examples.

20. (a)Write a program in C using pointers to implement linear search on a list of N numbers using pointers.

(b) Rewrite the program using pointers to implement a binary search.

21. Let A be an n*n dimensional square array. Write a module which finds thenumber of non zero elements in A

sum of elements above the diagonal (i.e) elements A [i,j] where I<J

product of the diagonal elements

22. Suppose A is a linear array with N numeric values. Write a Procedure MEAN (A, N, AVE) which find the average of the values in A.

23. Each student in a class of 30 students takes 3 tests in which scores range between 0 and 50. Suppose the test scores are stored in a 30 * 3 array TEST.W rite a module which Finds the average grade of each test. Finds the average grade of each student where the average grade is the average of the student’s best two scores.

24. Explain the array representation of stack. Write procedures for PUSH and POP of an element from the stack.

25. What is a priority queue? Explain the two-dimensional array representation of the priority queue with an example.

26. Consider each of the following reverse polish notations of arithmetic expressions.

P1: 5, 3, +, 2, *, 6, 9, 7, -, /, –

P2: 3, 5, +, 6, 4, -, *, 4, 1, -, 2, $, +

P3: 3, 1, +, 2, ^, 7, 4, -, 2, *, +, 5, –

Translate into infix expression and evaluate.

27. Suppose a priority queue is maintained as a two-dimensional array.

(a) Write a procedure INSPQ(Q, FRONT, REAR, ITEM, M ) which adds an item with priority number M into the queue.

(b) Write a procedure DELPQ(Q, FRONT, REAR, ITEM) which removes an element from the queue and assigns it to the variable ITEM.

28. Convert the following expressions to Reverse Polish Notation.

(i)(A-B)/((D+E)*F) (ii) ((A+B)/D)^((E-F)*G)

29. Explain Multiple stacks with neat diagram and write algorithm for push(), pop() & Disp().

30. Write short notes on priority queues. Also, explain the 1D and 2D array representation of the priority

queues.

31. Write a C program to perform string processing for the following operations

(i) Insert a string in the middle of the text

(ii) Replace a string by another in the text

(iii) Delete a string from the text

(iv) Find the length of the text

*For regular updates please like the facebook page*