Vous êtes sur la page 1sur 15

C and Data Structures

Unit-Wise Important Questions

Unit I

Syllabus
Algorithm / pseudo code, flowchart, program development steps, structure of C program, A Simple C program, identifiers, basic data types and sizes, Constants, variables, arithmetic, relational and logical operators, increment and decrement operators, conditional operator, bit-wise operators, assignment operators, expressions, type conversions, conditional expressions, precedence and order of evaluation. Input-output statements, statements and blocks, if and switch statements, loops- while, do-while and for statements, break, continue, goto and labels, programming examples Algorithms,Flowcharts

1.

a. Draw a Flowchart for the following


The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional logic for generating reject letters for all candidates who do not get the required average & interview call letters for the others. [Answer Tip] b. Explain the basic structure of C program. [Answer Tip] [10+6]
Basics (I/O)

2.

a. Distinguish between getchar and scanf functions for reading strings.


[Answer Tip]

b. What is the difference between signed integer and unsigned integer in


terms of memory and range [Answer Tip] 3.

a. What are the general characteristics of C? [Answer Tip] b. Give and Explain the structure of a C program? [Answer Tip]

c. Write a C program to print the Pascals triangle. [Answer Tip] [4+4+8]


Constants, Data types and Variables

4. Write about space requirements for variables of different data types.[Answer


Tip]. [16] 5.

a. What is the difference between signed integer and unsigned integer in


terms of memory and range [Answer Tip]. types [Answer Tip]. [8+8]

b. List the entire data types in C. What is the size of each of these data

6.

7.

a. What is a string constant? How do string constants differ from character constants? Do string constants represent numerical Values? [Answer Tip] b. Summarize the standard escape sequences in C. Describe them. [Answer Tip] c. What is a variable? How can variables be characterized? Give the rules for variable declaration. [Answer Tip] d. What is the purpose of type declarations? What are the components of type declaration? [Answer Tip][4+4+4+4]

a. What are different types of integer constants? What are long integer
con- stants? How do these constants differ from ordinary integer constants? How can they be written and identified? [Answer Tip] b. Describe two different ways that floating-point constants can be written in C. What special rules apply in each case?[Answer Tip] c. What is a character constant? How do character constants differ from numeric type constants? Do character constants represent numerical values? [Answer Tip][6+4+6]
Operators

8.

a. What is meant by operator precedence? What are the relative


precedence of the arithmetic operators? [Answer Tip]

b. What is the associatively of the arithmetic operators?[Answer Tip] c. How can the value of an expression be converted to a different data
types? What is this called?[Answer Tip]

d. What are unary operators? Explain example for each. [Answer Tip]
[4+4+4+4] 9. a. Explain the following & illustrate it with an example each. i. Increment & Decrement operator.[Answer Tip] ii. Conditional operator. [Answer Tip] iii. Bitwise operator. [Answer Tip] iv. Assignment operator. [Answer Tip] b. State the rules that applied while evaluating expression in automatic type conversion. [Answer Tip][12+4]
Loops

10.

a. What is the purpose of break statement? [Answer Tip] b. Suppose a break statement is included within the innermost of several
nested control statements. What happens when break statement is executed? [Answer Tip] c. Write a program to print the multiplication table up to 20 with proper format. [Answer Tip][4+6+6]
Programs

11. harmonic series for a given value of n: 1+1/2+1/3+.....+1/n. [Answer Tip] b. What are the logical operators used in C and illustrate with examples. [Answer Tip][8+8] Write a C program to print the lower triangular of a given square matrix. [Answer Tip][16]

a. Write a program to determine and print the sum of the following

12.

Unit II

Syllabus
Designing structured programs, Functions, basics, parameter passing, storage classes- extern, auto, register, static, scope rules, block structure, user defined functions, standard library functions, recursive functions, header files, C preprocessor, example c programs. Functions basics

1.

a. What do you mean by functions? Give the structure of the functions b.


2. and explain about the arguments and their return values.[Answer Tip] Write a C program that uses a function to sort an array of integers. [Answer Tip] [8+8]

a. Distinguish between the following:[Answer Tip]

b.
3.

i. Actual and formal arguments. ii. Global and local variables. iii. Automatic and static variables. Explain in detail about pass by values and pass by reference. Explain with a sample program [Answer Tip][8+8]

4.

a. Distinguish between formal variable and actual variable. b. Distinguish between local and global variable. c. Distinguish between call by value and call by reference. [Answer Tip] [4+4+8]

a. What is a preprocessor directive. [Answer Tip] b. Distinguish between function and preprocessor directive. [Answer
Tip]

c. What is the significance of conditional compilation. [Answer Tip]

d. How does the undefining of a pre-defined macro done. [Answer Tip] [4+4+4+4]
Recursion

5.

a. What are the advantages and disadvantages of recursion.[Answer


Tip]

b. Write a C program to find the factorial of a given integer using a


function. [Answer Tip]. c. Write a recursive algorithm to compute the product of two non negative integers [3+7+6] 6. [Answer Tip]. b. Write a recursive definition of a + b , where a and b are nonnegative integers, in terms of the successor function succ , defined as succ(x) int x; { return (x++); } 7. Let a be an array of integers. Present recursive algorithms to compute a. Maximum element of the array b. The sum of elements of the array. [8+8]
Programming

a. Define recursion. What are the properties of recursive definition

8.

a. Write a program to demonstrate passing an array argument to a function. Consider the problem of finding largest of N numbers defined in an array. b. Write a recursive function power (base, exponent) that when invoked returns base exponent. [8+8] 9. Write a C program to find mean, standard deviation and variance of a set of elements [16] 10. The roots of a quadratic equation of the form ax2+bx+c = 0 are given by the following equations: x1=-b+(b2-4ac)/2a x2=-b-(b2-4ac)/2a Write a function to calculate the roots. The function must use two pointer Parameters, one to receive the coefficients a,b and c and the other to send the roots to the calling function. [16] 11. Write a program that calculates the value of money at the end of each year of investment assuming an interest rate of 12 percent and prints the year & corre- sponding amount in two columns for a period of 10 years with an intial investment of 5 years. Formula: Value at end of year = value at start of year (1+interest rate) [16] 12. Write a non-recursive simulation of Towers of Hanoi problem. [16]

Unit III

Syllabus
Arrays- concepts, declaration, definition, accessing elements, storing elements, arrays and functions, two-dimensional and multi-dimensional arrays, applications of arrays. pointersconcepts, initialization of pointer variables, pointers and function arguments, address arithmetic, Character pointers and functions, pointers to pointers, pointers and multidimensional arrays, dynamic memory managements functions, command line arguments, c program examples Arrays

1.

2.

a. In what way array is different from an ordinary variable? b. What conditions must be satisfied by the entire elements of any given array? c. What are subscripts? How are they written? What restrictions apply to the values that can be assigned to subscripts? d. What advantage is there in defining an array size in terms of a symbolic constant rather than a fixed integer quantity? e. Write a program to find the largest element in an array. [3+2+3+3+5] a. How are initial values written in a one-dimensional array definition? Is the entire array be initialized? What value is automatically assigned to those array elements not explicitly initialized? b. Write a program to calculate mean, variance and standard deviation of n numbers. S= variance, where Variance = 1/n (xi-m)2 M= mean of n numbers. [8+8]

3.

a. Write a C program to do Matrix Multiplications. b. Write in detail about one dimensional and multidimensional arrays. Also write about how initial values can be specified for each type of array 4. The annual examination is conducted for 50 students for three subjects. Write a program to read the data and determine the following: a. Total marks obtained by each student. b. The highest marks in each subject and the Roll No. of the student who secured it. c. The student who obtained the highest total marks. [5+6+5]
Pointers

5.

a. What is a pointer? How is a pointer initiated? Give an example. b. State whether each of the following statements is true or false. Give reasons. i. An integer can be added to a pointer. ii. A pointer can never be subtracted from another pointer. iii. When an array is passed as an argument to a function, a pointer is passed. iv. Pointers can not be used as formal parameters in headers to function definitions.

6.

c. If m and n have been declared as integers and p1 and p2 as pointers to integers, then find out the errors, if any, in the following statements. i. p1 = &m; ii. p2 = n; iii. m=p2-p1; iv. *p1 = &n; [4+6+6]

a. Explain the process of accessing a variable through its pointer. Give an Example. b. Write a C program using pointers to read in an array of integers and print its elements in reverse order. [8+8] 7. Write a C Program to compute the sum of all elements stored in an array using pointers. 8. a. Write a C program using pointer for string comparison. b. Write a C program to arrange the given numbers in ascending order using pointers. [8+8] 9. a. What is a pointer? List out the reasons for using pointers. b. Write a C Program to illustrate the use of indirection operator * to access the value pointed by a pointer. [8+8] 10. a. How to use pointer variables in expressions? Explain through examples. b. Write a C Program to illustrate the use of pointers in arithmetic operations. [8+8] 11. a. Explain the process of declaring and initializing pointers. Give an example. b. Write a C program that uses a pointer as a function argument. [8+8] 12. a. What is a pointer? List out the reasons for using pointers. b. Write a C Program to illustrate the use of indirection operator * to access the value pointed by a pointer. [8+8] 13. a. Explain the process of accessing a variable through its pointer. Give an Ex- ample. b. Write a C program using pointers to read in an array of integers and print its elements in reverse order. [8+8] 14. a. How to use pointer variables in expressions? Explain through examples. b. Write a C Program to illustrate the use of pointers in arithmetic operations. [8+8]
Strings

15. Write a C program using pointers to determine the length of a character string. [8+8] 16. Write a program to count the number of words, lines and characters in a text. [8] 17.

a. Distinguish between getchar and scanf functions for reading strings. b. Write a program to count the number of words, lines and characters in a text. [8+8] 18. Write a C program to replace a particular word by another word in a given line of text. [16]

Unit IV

Syllabus
Derived types- structures- declaration, definition and initialization of structures, accessing structures, nested structures, arrays of structures, structures and functions, pointers to structures, self referential structures, unions, typedef, bitfields, C program examples. Theory (6 Marks)

1.

a. How to compare structure variables? Give an example.[6] b. How does a structure differ from an array? [6] c. Distinguish between an array of structures and an array within a structure. Give an example each.[6] d. Differentiate between a structure and union with respective allocation of memory by the compiler. Given an example of each.[6] e. Describe nested structures. Draw diagrams to explain nested structure.[6] f. Distinguish between an array of structures and an array within a structure. Give an example each.[6] g. How are structure elements stored in memory. [6]
Theory (8 Marks)

2.

a. What is structure within structure? Give an example for it.[8] b. Write a C program to illustrate the comparison of structure variables. [8] c. Explain the different ways of passing structure as arguments in functions. d. What is the use of a structure? Given an example for a structure with initial- ized values. [8] e. Explain with an example how a structure can be organized in the C language? [8] f. What are Bit fields. What are its advantages. What is its syntax. [8]
Programming Examples (8 Marks)

3. a. Write a C program to illustrate the concept of structure within structure. [8]

b. Write a C program to print maximum marks in each subject along with the name of the student by using structures. Take 3 subjects and 3 students records. [8] c. Write a C program to illustrate the method of sending an entire structure as a parameter to a function. [8] d. Write a C program to illustrate the comparison of structure variables. e. What is the use of a structure? Given an example for a structure with initialized values. [8] f. Write a C program to store the information of vehicles. Use bit fields to store the status information. Assume the vehicle object consists of type, fuel and model member fields. Assume appropriate number of bits for each field.[8]
Programming Examples (10 Marks)

4.

a. Write a program to declare pointer as members of structure and display the contents of the structure. Define a structure object, boy with three fields: name, age and height. [10] b. Write a C program using structure to create a library catalogue with the following fields; Access number, authors name. Title of the book, year of publication, publishers name, price. [10] c. Write a program to create an array of student structure objects and to find the highest marks scorer. The fields in the student structure are: name, age and marks.[10] d. Write a C program using structure to read and print the students records of a class with the following members. Field Name Data Type name string reg no integer major string result string [10] e. Write a C program using structure to create a library catalogue with the following fields; Access number, authors name. Title of the book, year of publication, publishers name, price. [10] f. Define a structure type struct ABS, that contains name, age, designation, and salary. Using this structure, write a C program to read this information for one person from the keyboard and print the same on the screen. [10] g. Write a program to read n records of students and find out how many of them have passed. The fields are students roll no, name, mark and result. Evaluate the result as follows if markes > 35 then Result = Pass else Fail [10]
Programming Examples (16 Marks)

5. Write a C program to compute the monthly pay of 100 employees using each employee s name, basic-pay. The DA is computed as 52% of the basic pay. Gross-salary (Basic pay +DA). Print the employees name and gross salary. [16]

6. Write a C program to read the information from the keyboard in which the Employee structure consists of employee name, code, designation and salary. Construct an array of structures that stores n employees information and write a program to carry out operations like inserting a new entry, deleting entry. [16] 7. The annual examination is conducted for 50 students for three subjects. Write a program to read the data and determine the following: a. Total marks obtained by each student. b. The highest marks in each subject and the Roll No. of the student who secured it. c. The student who obtained the highest total marks. [5+6+5]

Unit V

Syllabus
Input and output concept of a file, text files and binary files, streams, standard I/o, Formatted I/o, file I/o operations, error handling, C program examples. Theory Questions

1.

a. What are the file I/O functions in C. Give a brief note about the task performed by each function.[8] b. Distinguish between text mode and binary mode operation of a file.[4] c. What is the task performed by fseek( ) function. What is its syntax. Explain each parameter in it.[8] d. Explain the command line arguments. What are the syntactic constructs followed in C.[8] e. Explain the way of defining, opening and closing a file. Also explain the different modes of operation. f. How does an append mode differs from a write mode.[4] g. Compare between printf and fprint f functions.[4]
Programming Questions

2.

a. Write a program to read an input file and count the number of characters in the input file.[ 8] b. Write a program to open a pre-existing file and add information at the end of file. Display the contents of the file before and after appending. [12] c. Write a C program to read the text file containing some paragraph. Use fseek() and read the text after skipping n characters form beginning of the file. [8] d. Write a C program to read the input file from command prompt, using command line arguments. [8]

e. Write a program to copy upto 100 characters from a file to an output array. [8]
Programming Examples (16 Marks)

3. Write a C program to read a text file and to count a. number of characters, b. number of words and c. number of sentences and write in an output file. [16] 4. Write a C program to replace every 5th character of the data file, using fseek( ) command. [16] 5. Write a C program to read information about the student record containing stu- dents name, students age and students total marks. Write the marks of each student in an output file. [16] 6. Write a C program to read data from the keyboard, write it to a file called INPUT, again read the same data from the INPUT file, and display it on the screen. [8+8] 7. Write a program to read a C program file and count the following in the complete C program a. Total number of statements b. Total number of opening brackets. [8+8]

Unit VI

Syllabus
Searching Linear and binary search methods, sorting Bubble sort, selection sort, Insertion sort, Quick sort, merge sort. Searchings

1.

a. Write a C program to search for a given element in the integer array using binary search. b. Derive the time complexity of binary search. [8+8] a. Using linear search delete the number 17 from the list of numbers and give the steps. 42,12,10,91,17,59. b. Write a C program to implement the same. [8+8]

2.

3.

a. Using linear search delete the number 26 from the list of numbers and give the steps. 10,7,17,26,32,92 b. Write a C program to implement the same. [8+8] 4. Write a C program to search for a given element in the integer array using binary search.

5. Write a C program that searches a value in a stored array using binary search. What is the time complexity of binary search? [16] 6. a. Distinguish between linear and binary search methods. b. Write an algorithm for non-recursive binary search method. [8+8]
Sortings

7. a. Write a C program to sort the elements of an array using Quick sort with suitable example b. What is the worst case and best case time complexity of the above program? 8. a. Explain Quick sort with algorithm. b. Analyse the worst case performance of Quick sort and compare with Selection sort. [8+8] 9. Write a C program to sort the elements of an array using Quick sort method with suitable example. [8+8] 10. Write an algorithm for two-way merge sort. Analyse its time complexity . [8+8] 11. a. Write a C program to merge two sorted arrays of integers. b. Derive the time complexity of merge sort. [8+8] 12. a. compare quick sort and heap sort methods. b. Explain quick sort method for the elements. 11,51,71,21,61,41,91,31, [8+8] 13. Write an algorithm for performing selection sort when the input elements are represented as a linked list. [16] 14. Write an algorithm for two way merge sort. Analyse its time complexity. [8+8] 15. Write an algorithm for quick sort. What is its time complexity. [16]
Others

16. Write a function in C to form a list containing the intersection of the elements of two lists. [16]
Out of Scope

17. 18.

a. Write a C program to sort given integers using partition exchange sort. b. Derive the time complexity of partition exchange sort. [8+8] a. Explain the algorithm for exchange sort with a suitable example. b. Compare sort and exchange sort [8+8]

Unit VII

Syllabus
Introduction to data structures, singly linked lists, doubly linked lists, circular list, representing stacks and queues in C using arrays and linked lists, infix to post fix conversion, postfix expression evaluation. Basics

1. Define a data structure. What are the different types of data structures? Explain each of them with suitable example. [4+6+6]
Linked Lists

2. How can a polynomial in three variables (x,y and z) be represented by a singly linked list? Each node should represent a term and should contain the powers of x, y, and z as well as coefficient of that term. Write a routine evaluate this polynomial for given values of x,y, and z. [4+6+6] 3. Write a routine to reverse elements of a doubly linked list by traversing the list only once. [16] 4. Write a C program to insert and delete the elements from circular doubly linked list. [16] 5. Write a routine SPLIT() to split a singly linked list into two lists so that all elements in odd position are in one list and those in even position are in another list. [16] 6. Define linked list. Explain various operations performed on linked lists with suitable algorithms. [16] 7. Write a C Program to exchange two nodes of a singly linked list. [16] 8. a. Compare and contrast singly linked list with an array. b. Write a C program to count the number of nodes in a linked 9. Define input-restricted deque as deque in which insertion is restricted to one end and deletion can be made at either end. Write routines to implement operations on this deque. [16 10. Write a C program to create a singly linked list and split it at the middle and make the second half as the first and vice-versa. Display the final list. [16] 11. a. What are the advantages and disadvantages of linear linked lists. b. Write the applications of singly linked list, double linked list and circular linked lists. [5+11] 12. a. Define a doubly linked list. Write an algorithm to insert and delete a node in a doubly linked list. b. List the applications of doubly linked lists. [12+4]
Stacks

13. Write a C program using pointers to implement a stack with all the operations.[16] 14. Declare two stacks of varying length in a single array. Write C routines push1, push2, pop1 and pop2 to manipulate the two stacks. [4x4=16] 15. a. Given a sequence of push and pop operations and an integer representing the size of an array in which a stack is to be implemented. Design an algorithm to determine whether or not overflow occurs. The algorithm should not use a stack. b. Explain what test is required for exceptional conditions in pop operations. [8+8]
Queues

16. Declare a circular queue of integers such that F points to the front and R points to the rear. Write functions a. To insert an element into queue b. To delete an element from queue. [8+8] 17. Write a C program for implementation of various operations on circular queue. [16] 18. Circular linked lists are usually set up with so-called list header. What is the reason for introducing such a header? Write fucntions to insert and delete elements for this implementation. [4+12] 19. Write a C program using pointers to implement Queue with all operation. [16] 20. Write a C program for implementation of various operations on circular queue. [16] a. Write an algorithm for performing insertion of an element into an input- restricted Dequeue. b. Write an algorithm for performing deletion of an element from an output- restricted Dequeue. [8+8] 21. a. Mention and explain various types of queues and give an example for each b. Compare various types of queues. [8+8]
Others

22. Write a program to convert a given prefix expression to postfix expression using stacks. [16] 23. Write in detail about the following: a. Recursion b. Applications of Stacks and Queues [8+8] 24. Write a program to convert a postfix expression to a fully parenthesized infix expression. For example, AB+ would be transformed in to (A+B) and AB+C- would be transformed into ((A+B)-C). [16] 25. a. Derive a method to convert a postfix expression into its prefix form b. Consider the following arithmetic expression in postfix notation: 752+*415-/i. Find the equivalent prefix form of the above .

ii.

Obtain the computed value of the expression from its postfix notation

Unit VIII

Syllabus
Trees- Binary tress, terminology, representation, traversals, graphs- terminology, representation, graph traversals (dfs & bfs) Trees

26. a. Write a C program to implement binary tree traversals. b. Write an algorithm to count the number of leaf nodes in a binary tree. What is its computing time? [8+8] 27. Write a C program to copy one binary tree to another binary tree. 28. a. What is preorder traversal method? b. Explain a procedure for preorder traversal of a binary tree with an example in detail. Analyze the time complexity of your procedure. [8+8] 29. Write a C program to sort a given list of elements using tree sort and discuss its time complexity. [16] 30. a. Construct a binary tree for the following preorder and inorder traversals. a. Pre order : ABCDEFGHIJKLMNOPQ b. In order : DECFBHGAKMLJIORNQP b. Prove that a binary tree with n leaves contains 2n-1 nodes. [8+8] 2. Write an algorithm, given the address of an input binary tree, prints the equivalent infix expression with minimum number of paranthesis 3. Write an algorithm for determining whether two binary trees A and B are similar based on the traversal method. [16] 4. a. Describe different types of trees b. Write a C program to implement Binary tree. [6+10] 5. Write a C program for creating, inserting and deletion in a Binary tree. [16] 6. Write a C program to create a tree and traversing the same in preorder and post order [16]
Graphs

7.

a. List and explain about the basic operations on a graph. b. Write a C program for depth first search of a graph. [7+9] 8. A digraph is strongly connected if it contains a directed path from i to j and from j to i for every pair of distinct vertices i and j. a. Show that for every n, n<2 , there exists a strongly connected digraph that contains exactly n edges. b. Show that every n vertex strongly connected digraph contains at least n edges where n>2 [8+8] 9. a. What are the advantages of adjacency matrix representation of graphs b. Define spanning tree of an undirected graph. [8+8]

Vous aimerez peut-être aussi