AE52/AC52/AT52 C & Data Structures JUNE 2014

Similar documents
DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

DC54 DATA STRUCTURES DEC 2014

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

FUNCTIONS OMPAL SINGH

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

INSTITUTE OF AERONAUTICAL ENGINEERING

Subject: Fundamental of Computer Programming 2068

Code No: R Set No. 1

CSL 201 Data Structures Mid-Semester Exam minutes

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

About this exam review

DC54 DATA STRUCTURES JUNE 2013

Data Structures. Chapter 04. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

Computer System and programming in C

These are reserved words of the C language. For example int, float, if, else, for, while etc.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C

NCS 301 DATA STRUCTURE USING C

CS301 - Data Structures Glossary By

Heaps / Priority Queues

Computer Science E-22 Practice Final Exam

Linear Data Structure

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Programming and Data Structure Solved. MCQs- Part 2

What is recursion. WAP to find sum of n natural numbers using recursion (5)

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Chapter 4: Trees. 4.2 For node B :

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

Data Structure. IBPS SO (IT- Officer) Exam 2017

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra

CS 241 Data Organization Binary Trees

Data structures and libraries

Computer Science Foundation Exam

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Functions. Arash Rafiey. September 26, 2017

CSCE 2014 Final Exam Spring Version A

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Q 1. Attempt any TEN of the following:

COMPUTER SCIENCE PAPER 1

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

Unit 3 Decision making, Looping and Arrays

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

CS171 Final Practice Exam

Computer Science Foundation Exam

CP2 Revision. theme: dynamic datatypes & data structures

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Introduction. two of the most fundamental concepts in computer science are, given an array of values:

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

Reg. No. : Question Paper Code : 27157

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Final Examination CSE 100 UCSD (Practice)

Computers Programming Course 5. Iulian Năstac

Introduction to C Language (M3-R )

Pointers. Mr. Ovass Shafi (Assistant Professor) Department of Computer Applications

CS171 Final Practice Exam

Department of Computer Applications


Department of Computer Science and Technology

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

Operators and Expressions:

Dynamic Memory Allocation

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

Procedural programming with C

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

INF2220: algorithms and data structures Series 1

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

ITI Introduction to Computing II

DATA STRUCTURES AND ALGORITHMS

Darshan Institute of Engineering & Technology for Diploma studies Unit 4

COMP 250 Fall recurrences 2 Oct. 13, 2017

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.

Graphs & Digraphs Tuesday, November 06, 2007

ITI Introduction to Computing II

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character

Summer Final Exam Review Session August 5, 2009

8. Binary Search Tree

COMPUTER APPLICATION

Trees. (Trees) Data Structures and Programming Spring / 28

CSE 2123 Recursion. Jeremy Morris

Computer Algorithms. Introduction to Algorithm

Computer Organization & Systems Exam I Example Questions

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

Transcription:

Q.2 a. Write a program to add two numbers using a temporary variable. #include<stdio.h> #include<conio.h> int main () int num1, num2; clrscr (); printf( \n Enter the first number : ); scanf ( %d, &num1); printf ( \n Enter the second number : ); scanf ( %d, &num2); num1 = num1 + num2; num2 =num1 num2; num1 = num1 num2; printf ( \n The first number is %d, num1); printf ( \n The second number is %d, num2); return 0; b. Explain the basic data types that the C language supports. C language provides very few basic data types. Table 1.2 lists the data type, their size, range, and usage for a C programmer. Table 1.2 Basic data types in C Data Type Size in Bytes Range Use char 1-128 to 127 To store characters int 2-32768 to 32767 To store integer numbers float 4 3.4E-38 to 3.4E+38 To store floating point numbers double 8 1.7E-308 to 1.7E+308 To store big floating point numbers Bitwise AND c. Explain Bitwise AND operator and Bitwise OR operator in C. IETE 1

The bitwise AND operator (&) is a small version of boolean AND (&&) as it performs operation on bits instead of bytes, chars, integers, etc. When we use the bitwise AND operator, the bit in the first operand is ANDed with the corresponding bit in the second operand. The truth table is the same as we had seen in logical AND operation. That is, the bitwise AND operator compares each bit of its first operand with the corresponding bit of its second operand. If both bits are 1, the corresponding bit in the result is 1 and 0 otherwise. For example, 10101010 & 01010101 = 00000000 In a C program, the & operator is used as follows : int a = 10, b = 20, c = 0; c=a&b; Bitwise OR The bitwise OR operator ( ) is a small version of the boolean OR ( ) as it performs operation on bits instead of bytes, chars, integers, etc. When we use the bitwise OR operator, the bit in the first operand is ORed with the corresponding bit in the second operand. The truth table is the same as we had seen in logical OR operation. That is, the bitwise OR operator compares each bit of its first operand with the corresponding bit of its second operand. If one or both bits are 1, the corresponding bit in the result is 1 and 0 otherwise. For example, 10101010 & 01010101 =11111111 In a C program, the operator is used as follows : int a= 10, b = 20, c = 0; c = a b Q.3 a. Differentiate between while loop and do-while loop. Also give the syntax of both the loops. The while loop provides a mechanism to repeat one or more statements while a particular condition is true. Syntax of While Loop Statement x; While (condition) Statement block; Statement y; The do-while loop is similar to the while loop. The only difference is that in a do-while loop, the test condition is tested at the end of the loop. Now that the test condition is tested at the end, this clearly means that the body of the loop gets executed at least one time (even if the condition is false). Syntax of do-while Loop Statement x; do IETE 2

statement block; while (condition); statement y; b. What is the difference between signed and unsigned variables? The difference between signed and unsigned numeric variables is that signed variables can be either negative or positive but unsigned variables can only be positive. By default, C makes a signed variable. c. Write a program to sum the series 1/2 + 2/3 + ---- + n/n +1) #include<stdio.h> #include<conio.h> main () int n; float sum = 0.0, a, i; clrscr (); printf( \n Enter the value of n: ); scanf ( %d, &n); for (i = 1.0; i<=n;i++) a = (float) i/(i +1); sum = sum +a; printf ( \n The sum of series 1/2 + 2/3 +.+%d/%d = %f, n, n+1, sum); return 0; Q.4 b. Explain briefly different pros and cons of recursion. Advantages The advantages of using a recursive program include: Recursive solutions often tend to be shorter and simpler than non-recursive ones. Code is clearer and easier to use. Recursion represents the original formula to solve a problem. Follows a divide-and-conquer technique to solve problems. In some (limited) instances, recursion may be more efficient. Disadvantages The drawbacks of using a recursive program include: For some programmers and readers, recursion is a difficult concept. Recursion is implemented using system stack. If the stack space on the system is limited, recursion to a deeper level will be difficult to implement. IETE 3

Aborting a recursive process in midstream is slow and sometimes nasty. Using a recursive function takes more memory and time to execute as compared to its non-recursive counterpart. It is difficult to find bugs, particularly when using global variables. c. Consider the linear arrays AAA (5:50), BBB (-5:10) and CCC (18) (i) Find the number of elements in each array. (ii) Suppose Base (AAA) = 300 and W=4 words per memory cell for AAA. Find the address of AAA [15] and AAA[35]. The number of elements is equal to the length; hence use the formula Length = UB-LB +1 Accordingly, Length (AAA) = 50-5+1 =46 Length (BBB) = 10-(-5) +1 Length (CCC) = 18-1 +1 = 18 Note that Length (CCC) = UB, since LB = 1. ii. Use the formula LOC (AAA[K]) = Base (AAA) + w(k-lb) Hence: (LOC(AAA[15] = 300 +4(15-5) = 340 LOC (AAA[35]) = 300 + 4(35-5) = 420 Q.5 a. Write a program to extract the first N characters of a string. #include<stdio.h> #include<conio.h> int main () char str[100], substr[100]; int i = 0, n; clrscr (); printf ( \n Enter the string : ); gets (str); printf ( \n Enter the number of characters to be copied : ); scanf ( %d, &n); i = 0; while (str [i]!= \0 && I <n) substr[i] = str [i]; I++; substr [i] = \0 ; printf ( \n The substring is : ) ; IETE 4

puts (substr); getch (); return 0; b. What are structures? Illustrate a complex structure with an example. Self-referential structures:- Structures that contain a reference to data of its same type. That is, a self-referential structure, in addition to other data, contains a pointer to a data that is of the same type as that of the structure. Q.6 a. Write a program to read and display the values of an integer array. Allocate space dynamically for the array. #include<stdio.h> #include<conio.h> main() int i, n; int *arr; clrscr (); printf ( \n Enter the number of elements in the array : ); scanf ( %d, &n); arr = (int *) malloc (n*sizeof(int) ); if (arr == NULL) printf ( \n Memory Allocation Failed ); exit (0); for (i=0; i<n;i++) printf ( \n Enter the %dth value of the array :, i); scanf ( %d, &arr[i]); printf ( \n The array contains the following values - \n ); for (i=0; i<n; i++) printf ( %d, arr[i]); // another way is to write * (arr +i) return 0; b. Write the basic steps of a merge sort algorithm. What is the complexity of merge sort? IETE 5

The basic steps of a merge sort algorithm are as follows: If the array is of length 0 or 1, then it is already sorted. Otherwise, divide the unsorted array into two sub-arrays of about half the size. Use merge sort algorithm recursively to sort each sub-array. Merge the two sub-arrays to form a single sorted list. Time complexity is 0(nlog 2 (n)) for both average case and worst case. Q.7 a. How can the polynomial 6x 3 +9x 2 +7x +1 be represented in the memory using a linked list? Every individual term in a polynomial consists of two parts, a coefficient and a power. Here, 6, 9, 7 and 1 are the coefficients of the terms that have 3, 2, 1, and 0 as their powers respectively. Every term of a polynomial can be represented as a node of the linked list. Figure 8.32 shows the linked representation of the terms of the above polynomial. 6 3 9 2 7 1 1 0 X Figure 8.32 Linked representation of a polynomial b. Write an algorithm to insert an element in a queue. Every individual term in a polynomial consists of two parts, a coefficient and a power. Here, 6, 9, 7 and 1 are the coefficients of the terms that have 3, 2, 1, and 0 as their powers respectively. Every term of a polynomial can be represented as a node of the linked list. Figure 8.32 shows the linked representation of the terms of the above polynomial. 6 3 9 2 7 1 1 0 X Figure 8.32 Linked representation of a polynomial c. List few applications of stack. Step 1: IF REAR = MAX-1, then; Write OVERFLOW [END OF IF] Step 2: IF FRONT == -1 and REAR = -1, then; SET FRONT = REAR = 0 ELSE SET REAR = REAR + 1 IETE 6

[END OF IF] Step 3: SET QUEUE [REAR] = NUM Step 4: Exit Q.8 a. Define the following terms with respect to a binary tree: (i) (i) (ii) (iv) Degree of a node In- order traversal Depth of the tree Full binary tree. i. Degree The degree of a node is equal to the number of children that a node has. The degree of a leaf node is zero. ii. The traversal technique in which all the nodes of a tree are processed by recursively processing the left sub-tree first, then processing the root, and finally the right sub-tree. iii.the depth of a node N is given as the length of the path from the root R to the node N. The depth of the root node is zero. The height/depth of a tree is defined as the length of the path from the root node to the deepest node in the tree. iv. Full binary tree- A binary tree in which every node has exactly zero or two children. b. Given the expression, Exp = a+b/c*d-e, construct the corresponding binary tree. Expression Tree e + a * l d b c IETE 7

c. Write a C routine to find the height of a binary tree. int height (node*r) int LH, RH; if (R = = NULL) return 0; else LH=height (R->left); RH = height (R->right); if (LH>RH) return ++LH; else return ++RH; Q.9 b. Define the following terms with respect of a graph: (i) Incident edge (ii) Degree of vertex (iii) Directed edge (iv) Undirected edge (v) Path Page Number 388 of Text Book c. What is a spanning tree? A minimum weight tree in a weighted graph which contains all of the graph`s vertices. Text book C & Data Structures, P.S. Deshpande & O.G. Kakde, Dream tech Press, 2005 IETE 8