CS PROGRAMMING & DATA STRUCTURES. UNIT I Part - A. 2. What is the difference between if and while statement?

Similar documents

CS PROGRAMMING & ATA STRUCTURES I. UNIT I Part - A

V.S.B ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY I IT-II Semester. Sl.No Subject Name Page No. 1 Programming & Data Structures-I 2


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

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1

Advanced C Programming and Introduction to Data Structures

CSCI 171 Chapter Outlines

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

Reg. No. : Question Paper Code : 27157

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Model Viva Questions for Programming in C lab

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

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

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

UNIT IV-2. The I/O library functions can be classified into two broad categories:

MODULE 5: Pointers, Preprocessor Directives and Data Structures

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

UNIT I : OVERVIEW OF COMPUTERS AND C-PROGRAMMING

Preprocessing directives are lines in your program that start with `#'. The `#' is followed by an identifier that is the directive name.

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT IV INTRODUCTION TO C

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

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

Computer Programming Unit v

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Programming and Data Structure Solved. MCQs- Part 2

Code No: R Set No. 1

SAURASHTRA UNIVERSITY

1 P age DS & OOPS / UNIT II

Guide for The C Programming Language Chapter 5

Linked List. April 2, 2007 Programming and Data Structure 1

Lists, Stacks, and Queues. (Lists, Stacks, and Queues ) Data Structures and Programming Spring / 50

Contents. A Review of C language. Visual C Visual C++ 6.0

I BCA[ ] SEMESTER I CORE: C PROGRAMMING - 106A Multiple Choice Questions.

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

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24

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

( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT V 2 MARKS

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

About this exam review

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

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DEEPIKA KAMBOJ UNIT 2. What is Stack?

CS301 - Data Structures Glossary By

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

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

17CS33:Data Structures Using C QUESTION BANK

PESIT Bangalore South Campus Department of MCA Course Information for

Introduction to C Final Review Chapters 1-6 & 13

UNIT-2 Stack & Queue

Introduction to Data Structures and Algorithms

a) State the need of data structure. Write the operations performed using data structures.


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

Short Notes of CS201

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

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

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

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS201 - Introduction to Programming Glossary By

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

Darshan Institute of Engineering & Technology for Diploma studies Unit 4

Department of Computer Science and Technology

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS

CP2 Revision. theme: dynamic datatypes & data structures

Advanced C Programming Topics

Question Bank Subject: Advanced Data Structures Class: SE Computer

Mode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.

Information Science 2

CS6202 PROGRAMING AND DATASTRUCTURE-I

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

Computer Systems Lecture 9

Model Viva Questions for Programming in C lab

INSTITUTE OF AERONAUTICAL ENGINEERING

Linear Data Structure

Programming Fundamentals

(i) Describe in detail about the classification of computers with their features and limitations(10)

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

DEPARTMENT OF MATHS, MJ COLLEGE

Problem Solving and 'C' Programming

Pace University. Fundamental Concepts of CS121 1

EL6483: Brief Overview of C Programming Language

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

12 Abstract Data Types

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Lectures 5-6: Introduction to C

Cpt S 122 Data Structures. Data Structures

CS8391-DATA STRUCTURES

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

Computers Programming Course 5. Iulian Năstac

Flow Control. CSC215 Lecture

Program Design (II): Quiz2 May 18, 2009 Part1. True/False Questions (30pts) Part2. Multiple Choice Questions (40pts)

Transcription:

CS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. What are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their intended purpose. Example: float, int,break, continue, goto, if, if- else, while, do-while,.. etc 2. What is the difference between if and while statement? if (i) It is a conditional statement (ii) If the condition is true, it executes some statements. (iii) If the condition is false then it stops the execution the statements. while (i) It is a loop control statement (ii) Executes the statements within the while block if the condition is true. (iii) If the condition is false the control is transferred to the next statement of the loop. 3. What is the difference between while loop and do while loop? In the while loop the condition is first executed. If the condition is true then it executes the body of the loop. When the condition is false it comes of the loop. In the do while loop first the statement is executed and then the condition is checked. The do while loop will execute at least one time even though the condition is false at the very first time. 4. What will happen when you access the array more than its dimension? When you access the array more than its dimensions some garbage value is stored in the array. 5. Write the limitations of getchar( ) and sacnf( ) functions for reading strings getchar( ) To read a single character from stdin, then getchar() is the appropriate. Scanf() scanf( ) allows to read more than just a single character at a time. Page 1

6. What is the output of the programs given below? main() main() float a; float a; int x=6, y=4; int x=6, y=4; a=x\y; a=(float) x\y; printf( Value of a=%f, a); printf( Value of a=%f,a); } } Output: Output: 1. 1.500000 7. Distinguish between Call by value Call by reference. Call by value Call by reference. a) In call by value, the value of a) In call by reference, the address of actual actual argurment values is passed agreements is passed to the to formal argument values. formal arguments and the b) Formal arguments values are operation is done on formal pointers to the actual argument arguments. values. b) Formal arguments values c) Since Address is passed, the are photocopies of actual changes made in the both arguments values. arguments values are permanent. c) Changes made in formal arguments valued do not affect the actual arguments values. 8. What is the difference between while(a) and while(!a)? while(a) means while(a!=0) while(!a) means while(a==0) Page 2

9. Why we don t use the symbol & symbol, while reading a String through scanf()? The & is not used in scanf() while reading string, because the character variable itself specifies as a base address. Example: name, &name[0] both the declarations are same. 10. What is the difference between static and auto storage classes? Static Auto Storage Memory Memory Initial value Zero Garbage value Scope Local to the block in which Local to the block in which the variables is defined the variable is defined. Life Value of the variable persists The block in which the between different variable is defined. function calls. 11. What is the output of the program? main() increment() increment(); static int i=1; increment(); printf( %d\n,i) increment(); i=i+1; } } OUTPUT: 1 2 3 12. Define delimiters in C. Delimiters Use : Colon Useful for label ; Semicolon Terminates Statement ( ) Parenthesis Used in expression and functions [ ] Square Bracket Used for array declaration } Curly Brace Scope of statement # Hash Preprocessor directive, Comma Variable Separator Page 3

13. Differentiate break and continue statement. S No break continue 1 Exits from current block / loop Loop takes next iteration 2 Control passes to next statement Control passes to beginning of loop 3 Terminates the program Never terminates the program 14. List the types of operators. S No Operators Types Symbolic Representation 1 Arithmetic operators =, -, *, / and % 2 Relational operators >,<, ==, >=, <= and!= 3 Logical operators &&, and! 4 Increment and Decrement ++ and 5 operators =, + =, - =, * =, / =, ^ =, ; =, & = 6 Assignment &,, ^, >>, <<, and ~ 7 operators Bitwise, 8 operators Comma? : operator Conditional

15. Distinguish between while..do and do..while statement in C. While DO..while (i) Executes the statements within the (i) Executes the statements within the while block if only the condition is true. while block at least once. (ii) The condition is checked at the starting of the loop (ii) The condition is checked at the end of the loop 16. Compare switch( ) and nestedif statement. S No switch( ) case nested if 1 Test for equality ie., only constant It can equate relational (or) values are applicable. logical expressions. 2 No two case statements in Same conditions may be repeated 3 same switch. for a number of times. Character constants are Character constants are automatically converted to 4 automatically converted to integers. integers. In nested if statement switch case In switch( ) case statement can be used. nested if can be used. 17. Give the syntax for the for loop statement for (Initialize counter; Test condition; Increment / Decrement) statements; } Initialization counter sets the loop to an initial value. This statement isexecuted only once. The test condition is a relational expression that determines the number of iterations desired or it determines when to exit from the loop. The increment / decrement parameter decides how to make changes in the loop. Page 5

18. What is the use of sizeof( ) operator? The sizeof ( ) operator gives the bytes occupied by a variable. No of bytes occupied varies from variable to variable depending upon its data types. Example: intx,y; printf( %d,sizeof(x)); Output: 2 19. What is a loop control statement? Many tasks done with the help of a computer are repetitive in nature. Such tasks can be done with loop control statements. 20. What are global variable in C? This section declares some variables that are used in more than one function. such variable are called as global variables. It should be declared outside all functions. 21. Write a program to swap the values of two variables (without temporary variable). #include <stdio.h> #include <conio.h> void main( ) int a =5; b = 10; clrscr( ); prinf( Before swapping a = %d b = %d, a, b); a = a + b; b = a b; a = a b; prinf( After swapping a = %d b = %d, a,b); getch( ); } Output: Before swapping a = 5 b = 10 After swapping a = 10 b = 5 22. What is an array? Page 6

An array is a group of similar data types grouped under a common name. int a[10]; Here a[10] is an array with 10 values. 23. What is a Pointer? How a variable is declared to the pointer? Pointer is a variable which holds the address of another variable. Pointer Declaration: datatype *variable-name; Example: int *x, c=5; x=&a; 24. What are the uses of Pointers? Pointers are used to return more than one value to the function Pointers are more efficient in handling the data in arrays Pointers reduce the length and complexity of the program They increase the execution speed The pointers saves data storage space in memory 25. What is the output of the program? main() junk(int i, int j) int i=5;j=2; i=i*j; junk(i,j); j=i*j; printf( \n %d %d,i,j); } } Output: 1. 2 2. 26. What are * and & operators means? * operator means value at the address & operator means address of 27. What is meant by Preprocessor? Preprocessor is the program, that process our source program before the compilation. Page 7

28. How can you return more than one value from a function? value. A Function returns only one value. By using pointer we can return more than one 29. What are the main elements of an array declaration? Array name - Datatype - Size 30. List the header files in C language. <stdio.h>contains standard I/O functions<ctype.h>contains character handling functions<stdlib.h>contains general utility functions<string.h>contains string manipulation functions<math.h>contains mathematical functions<time.h>contains time manipulation functions 31. What are the pre-processor directives? Macro Inclusion Conditional Inclusion File Inclusion. 32. What is the difference between an array and pointer? Difference between arrays and pointers are as follows. Array Pointer 1.Array allocates space 1.Pointer is explicitly assigned to point to automatically. an allocated space. 2.It cannot be resized. 2.It can be resized using realloc (). 3.It cannot be reassigned. 3.Pointers can be reassigned. 4.Size of(array name) gives the 4.Sezeof(pointer name) returns the number of bytes occupied by number of bytes used to store the pointer the array. variable. Page 8

33.Is it better to use a macro or a function? Macros are more efficient (and faster) than function, because their corresponding code is inserted directly at the point where the macro is called. There is no overhead involved in using a macro like there is in placing a call to a function. However, macros are generally small and cannot handle large, complex coding constructs. In cases where large, complex constructs are to handled, functions are more suited, additionally; macros are expanded inline, which means that the code is replicated for each occurrence of a macro. 34. List the characteristics of Arrays. ƒ All elements of an array share the same name, and they are distinguished form one another with help of an element number. ƒ Any particular element of an array can be modified separately without disturbing other elements. 35.What are the types of Arrays? 1.One-Dimensional Array 2. Two-Dimensional Array 3. Multi-Dimensional Array 36. What is the use of \0 character? When declaring character arrays (strings), \0 (NULL) character is automatically added at end. The \0 character acts as an end of character array. 37. What is C functions? Why they are used? A function is a self-contained block (or) a sub-program of one or more statements that performs a special task when called. To perform a task repetitively then it is not necessary to re-write the particular block of the program again and again. The function defined can be used for any number of times to perform the task. 38. Differentiate library functions and User-defined functions. Library Functions User-defined Functions Page 9

a) Library functions are predefined set of functions that are defined in C libraries. b) User can only use the function but cannot change a) The User-defined functions are the functions defined by the user according to his/her requirement. b) User can use this type of function. User can also modify this function. 39. What are the steps in writing a function in a program. a) Function Declaration (Prototype declaration): Every user-defined functions has to be declared before the main b) Function Callings: The user-defined functions can be called inside any functions like main(), user-defined function, etc. c) Function Definition: The function definition block is used to define the user-defined functions with statements. 40. Give the syntax for using user-defined functions in a program. Syntax for using user-defined functions in a program Syntax: function declaration; function main() definition; ====== ====== function calling; (or) function calling; ====== ====== } } function definition; 41. Classify the functions based on arguments and return values. Depending on the arguments and return values, functions are classified into four types. a) Function without arguments and return values. b) Function with arguments but without return values. c) Function without arguments but with return values. d) Function with arguments and return values. Page 10

42. Define pre-processor in C. The C Preprocessor is not part of the compiler, but is a separate step in the compilation process. In simplistic terms, a C Preprocessor is just a text substitution tool. We'll refer to the C Preprocessor as the CPP. Example: #define Substitutes a preprocessor macro #include Inserts a particular header from another file 43. Define Macro in C. A macro definition is independent of block structure, and is in effect from the #define directive that defines it until either a corresponding #undef directive or the end of the compilation unit is encountered. Its format is: #define identifier replacement Example: #define TABLE_SIZE 100 inttable1[table_size]; int table2[table_size]; 44. What are conditional Inclusions in Preprocessor Directive? Conditional inclusions (#ifdef, #ifndef, #if, #endif, #else and #elif) These directives allow including or discarding part of the code of a program if a certain condition is met. #ifdef allows a section of a program to be compiled only if the macro that is specified as the parameter has been defined, no matter which its value is. For example: #ifdef TABLE_SIZE int table[table_size]; #endif 45. What you meant by Source file Inclusion in Preprocessor directive? Source file inclusion (#include) Page 11

This directive has also been used assiduously in other sections of this tutorial. When the preprocessor finds an #include directive it replaces it by the entire content of the specified file. There are two ways to specify a file to be included: 1 #include "file" 2 #include <file> PART B 1. Explain about the various decision making statements in C language. 2. Explain the control statements in c. 3. What are functions? Explain the types of functions in detail with an example program for each type. 4. Define arrays. Explain the array types with an example program for each type 5. What are pointers? When and why they are used? Explain in detail with sample programs. 6. Describe in detail about the Preprocessors in C. 7. Explain function pointers with example. 8. Detailly explain about function with variable number of arguments.? Page 12

1. Define structure. CS6202 - PROGRAMMING & DATA STRUCTURES I UNIT II Part A A structure is a user defined data type that groups logically related data items of different data types into a single unit. All the elements of a structure are stored at contiguous memory locations. 2. What is meant by structure template? A structure template contains definition of a structure name and a list of members along with data types. 3. Write the syntax for structure declaration and definition Structure definition: structstructure_name Datatype member1; Datatype member2; }; Structure declaration: structstructure_name v1,v2, ; 4. Define union. A union is a user defined data type similar to structure. The union groups logically related data items of different data types into a single unit. But the memory allocation for union is different from structure. 5. Write the syntax for union declaration and definition. Union definition: unionunion_name Datatype member1; Datatype member2; }; Union declaration: unionunion _name v1,v2, ; 6. How structures are initialized? Give example. Page 1

o A structure can be initialized in two ways. struct student intrno; int age; char name[20]; }; x Structure variable initialization o struct student s1=223,17, john }; x Structure member by member initialization o s1.rno=223; o s1.age=17; o s1.name= john ; 7. What are nested structures? A structure built within another structure is called nested structures or structure within a structure. Example: struct dob int day; int month; int year; }; struct student intrno; char name[20]; }; struct dob date; 8. What is meant by array of structures? An array of structure contains data elements of every structure variable stored into an array. Example: struct student intrno; int age; Page 2

char name[20]; }s[15]; 9. What is structure assignment? The value of one structure variable is assigned to another variable of same type using assignment statement. If the e1 and e2 are structure variables of type employee then the structure assignment can be performed as e1=e2; This assigns value of structure variable e2 to e1. 10. How do you reference a structure member? The structure members cannot be accessed directly. They can be accessed by using the name of the structure variable followed by a dot(.) and then the name of the member variable. struct student intrno; int age; char name[20]; }s1; s1.rno=223; s1.age=17; s1.name= john ; 11. Differentiate structure and union. S.No. Structure Union 1. A structure is defined with struct A union is defined with union keyword keyword 2. All members of a structure can be The members of a union can be utilized utilized simultaneously. only one at a time. 3. The size of a structure variable is equal The size of the union variable is equal to the sum of the size of the members to the size of the largest member. 4. Structure members are allocated Union members share common distinct memory locations memory space. 5. Structures are not memory efficient Unions are memory efficient. when compared to unions. 12. Differentiate structure and arrays. S.No. Structure Array 1. Definition and declaration of program Definition and declaration of program in structures are different. in arrays are same.

2. A structure is a group of dissimilar data An array is a group of similar data 3. Nested structures is possible No nested arrays 4. Structure members are accessed with Index is used to access data in arrays. dot (.) operator. 5. In structures, reserved word struct is In arrays, no reserved word is used. used. 13. What are the advantages of union over structure? x Union save memory space compared to structures since the size of union is equal to its largest sized member. x Unions are useful in situations where there is a need to use only one of its member elements at a time 14. Write the syntax for pointers to structure. structstructure_name Datatype member1; Datatype member2; }s1; structstructure_name *ptr; ptr=&s1; 15. What is a file? A file is a collection of data that is available in permanent storage. 16. Write the syntax for file declaration. Syntax: FILE *filepointer; Example: FILE *fp; 17. What are file modes? Modes tell about the type of operation to be performed on a file that is being opened. There are three basic file modes: a. Read b. Write c. Append 18. Write the syntax to open a file. Syntax: Page 4

FILE *filepointer; filepointer = fopen( filename, mode ); Example: FILE *fp; fp=fopen( hai.txt, r ); 19. What is the significance of fclose() function? This function closes a file that has been opened for an operation. Syntax: fclose(filepointer); 20. What are the steps for using a file? The basic steps for using a file in C are as follows: a. Create a variable of type FILE * ; b. Open the file using fopen function and assign the file to the variable. c. Check to make sure that the file was successfully opened by checking to see if the variable is equal to NULL. d. Perform file operations like read,write, 21. What are the functions of text files in stdio library? a. fopen() opens a file. b. fclose() closes a file. c. feof() - detects end-of-file marker in a file. d. fscanf() reads formatted input from a file. e. fprintf() writes formatted output to a file. f. fgets() reads a string from a file g. fputs() writes a string to a file h. fgets() reads a character from a file i. fputs() writes a character to a file 22. What are the file pointers of stdlib.h? There are three special file pointers. 1. stdin (Standard input) 2. stdout (Standard output) 3. stderr (Standard error) 23. What are the types of files? There are two types a. Text file b. Binary file Page 5

If a large amount of numerical data is to be stored, text files will be insufficient. In such cases, binary files can be used. 24. What are the features of binary files? x Any structure can be used in the file. x Contents can be changed anywhere in the file. 25. What are the functions to access files randomly? There are three functions to perform random access. x ftell() tells the current position of a file x fseek() moves to a desired location from the current position x rewind() resets the file position to the beginning of a file. Part B 1. Explain the different modes in which a file can be opened. 2. Explain the functions fscanf, fprintf, fgets, fputs, getw, putw, getc, putc, fread, fwrite, feof, ferror,fseek,ftell,rewind with example. 3. Explain structures with an example 4. Explain union with an example 5. Discuss about the file handling concepts in C 6. Explain different ways to read data from a file. 7. Explain different ways to write data to a file 8. Design a c program to create the employee database and to perform the manipulations such as adding a record, deleting a record, updating a record. 9. Explain about structure within structure with example. Page 6

CS6202 - PROGRAMMING & DATA STRUCTURES - I 1. What is a data structure? Unit III Part A A data structure is a method for organizing and storing data which would allow efficient data retrieval and usage. A data structure is a way of organizing data that considers not only the items stored, but also their relationships to each other. 2. Why do we need data structures? x Data structures allow us to achieve an important goal: component reuse. x Once data structure has been implemented, it can be used again and again in various applications. 3. List some common data structures. x Stacks x Queues x Lists x Trees x Graphs x Tables 4. How data structures are classified? Data structures are classified into two categories based on how the data items are operated: i. Primitive data structure ii. Non-Primitive data structure a. Linear data structure b. Non-linear data structure 5. Differentiate linear and non-linear data structure. S.No Linear data structure Non-linear data structure 1 Data are arranged in linear or Data are not arranged in linear manner. sequential manner 2 Every items is related to its previous Every item is attached with many other and next item items 3 Data items can be traversed in a Data items cannot be traversed in a single run. single run. 4 Implementation is easy Implementation is difficult. Page 1

5 Example: array, stack, queue, linked Example: tree, graph list 6. Define ADT(Abstract Data Type) An abstract data type (ADT) is a set of operations and mathematical abstractions, which can be viewed as how the set of operations is implemented. Objects like lists, sets and graphs, along with their operation, can be viewed as abstract data types, just as integers, real numbers and Booleans. 7. Mention the features of ADT. a. Modularity i. Divide program into small functions ii. Easy to debug and maintain iii. Easy to modify b. Reuse i. Define some operations only once and reuse them in future c. Easy to change the implementation 8. Define List ADT A list is a sequence of zero or more elements of a given type. The list is represented as sequence of elements separated by comma. A1,A2,A3..AN Where N>0 and A is of type element. 9. What are the ways of implementing linked list? The list can be implemented in the following ways: i. Array implementation ii. Linked-list implementation iii. Cursor implementation 10. What are the types of linked lists? There are three types i. Singly linked list ii. Doubly linked list iii. Circularly linked list

11. How the singly linked lists can be represented? 0Head Node Null

Each node has two elements i. Data ii. Next 12. How the doubly linked list can be represented? Head Doubly linked list is a collection of nodes where nodes are connected by forwarded and backward link. Each node has three fields: 1. Address of previous node 2. Data 3. Address of next node. 13. What are benefits of ADT? a. Code is easier to understand b. Implementation of ADT can be changed without requiring changes to the program that uses the ADT 14. When singly linked list can be represented as circular linked list? In a singly linked list, all the nodes are connected with forward links to the next nodes in the list. The last node has a next field, NULL. In order to implement the circularly linked lists from singly linked lists, the last node s next field is connected to the first node 15. When doubly linked list can be represented as circular linked list? In a doubly linked list, all nodes are connected with forward and backward links to the next and previous nodes respectively. In order to implement circular linked lists from doubly linked lists, the first node s previous field is connected to the last node and the last node s next field is connected to the first node. Page 3

16. Where cursor implementation can be used? The cursor implementation of lists is used by many languages such as BASIC and FORTRAN that do not support pointers. The two important features of the cursor implementation of linked are as follows: x The data are stored in a collection of structures. Each structure contains data and a index to the next structure. x A new structure can be obtained from the system s global memory by a call to cursorspace array. 17. List down the applications of List. a. Representation of polynomial ADT b. Used in radix and bubble sorting c. In a FAT file system, the metadata of a large file is organized as a linked list of FAT entries. d. Simple memory allocators use a free list of unused memory regions, basically a linked list with the list pointer inside the free memory itself. 18. What are the advantages of linked list? a. Save memory space and easy to maintain b. It is possible to retrieve the element at a particular index c. It is possible to traverse the list in the order of increasing index. d. It is possible to change the element at a particular index to a different value, without affecting any other elements. 19. Mention the demerits of linked list a. It is not possible to go backwards through the list b. Unable to jump to the beginning of list from the end. 20. How the polynomial is represented using linked lists? The polynomial equation can be represented with linked list as follows: Coefficient Exponent Next node link struct polynomial int coefficient; int exponent; struct polynomial *next; }; Page 4

21. What are the operations performed in list? The following operations can be performed on a list i. Insertion a. Insert at beginning b. Insert at end c. Insert after specific node d. Insert before specific node ii. Deletion a. Delete at beginning b. Delete at end c. Delete after specific node d. Delete before specific node iii. Merging iv. Traversal 22. What are the merits and demerits of array implementation of lists? Merits x Fast, random access of elements x Memory efficient very less amount of memory is required Demerits x Insertion and deletion operations are very slow since the elements should be moved. x Redundant memory space difficult to estimate the size of array. 23. What is a circular linked list? A circular linked list is a special type of linked list that supports traversing from the end of the list to the beginning by making the last node point back to the head of the list. Part B 1. Explain the various operations of the list ADT with examples 2. Write the program for array implementation of lists 3. Write a C program for linked list implementation of list. 4. Explain the operations of singly linked lists 5. Explain the operations of doubly linked lists 6. Explain the operations of circularly linked lists 7. How polynomial manipulations are performed with lists? Explain the operations 8. Explain the steps involved in insertion and deletion into an singly and doubly linked list. Page 5

1. Define Stack. CS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type and based on the principle of LIFO (Last In First Out). 2. What are the operations of the stack? a. CreateStack/ InitStack(Stack) creates an empty stack b. Push(Item) pushes an item on the top of the stack c. Pop(Item) removes the top most element from the stack d. Top(Stack) returns the first element from the stack e. IsEmpty(Stack) returns true if the stack is empty 3. Write the routine to push a element into a stack. Push(Element X, Stack S) if(isfull(s) Error( Full Stack ); } else S Array[++S TopOfStack]=X; } 4. How the operations performed on linked list implementation of stack? a. Push and pop operations at the head of the list b. New nodes should be inserted at the front of the list, so that they become the top of the stack c. Nodes are removed from the front(top) of the stack 5. What are the applications of stack? The following are the applications of stacks Evaluating arithmetic expressions Balancing the parenthesis Towers of Hanoi Function calls Tree traversal Page 1

6. What are the methods to implement stack in C? The methods to implement stacks are : x Array based x Linked list based 7. How the stack is implemented by linked list? It involves dynamically allocating memory space at run time while performing stack operations. Since it consumes only that much amount of space is required for holding its data elements, it prevents wastage of memory space. struct stack int element; struct }*top; stack *next; 8. Write the routine to pop a element from a stack. int pop() if(top==null) printf( \n Stack is empty.\n ); getch(); exit(1); } else int temp; temp=top element; /* retreiving the top element*/ top=top next; /* Updating the stack pointer */ return temp; /* returning the popped value */ } } 9. Define queue. It is a linear data structure that maintains a list of elements such that insertion happens at rear end and deletion happens at front end. FIFO First In First Out principle Page 2

10. What are the operations of a queue? The operations of a queue are x isempty() x isfull() x insert() x delete() x display() 11. Write the routine to insert a element onto a queue. void insert(int element) } if(front==-1 ) front = rear = front +1; queue[front] = element; return; } if(rear==99) printf( Queue is full ); getch(); return; } rear = rear +1; queue[rear]=element; 12. What are the types of queue? The following are the types of queue: x Double ended queue x Circular queue x Priority queue Page 3

13. Define double ended queue x It is a special type of queue that allows insertion and deletion of elements at both ends x It is also termed as DEQUE. 14. What are the methods to implement queue in C? The methods to implement queues are : x Array based x Linked list based 15. How the queue is implemented by linked list? It is based on the dynamic memory management techniques which allow allocation and de-allocation of memory space at runtime. Insert operation It involves the following subtasks: x Reserving memory space of the size of a queue element in memory x Storing the added value at the new location x Linking the new element with existing queue x Updating the rear pointer Delete operation It involves the following subtasks: 1. Checking whether queue is empty 2. Retrieving the front most element of the queue 3. Updating the front pointer 4. Returning the retrieved value 16. Write the routine to delete a element from a queue intdel() int i; if(front == NULL) /*checking whether the queue is empty*/ return(-9999); } else Page 4

} } i = front element; front = front next; return i; 17. What are the applications of queue? The following are the areas in which queues are applicable a. Simulation b. Batch processing in an operating systems c. Multiprogramming platform systems d. Queuing theory e. Printer server routines f. Scheduling algorithms like disk scheduling, CPU scheduling g. I/O buffer requests 18. Define circular queue A Circular queue is a queue whose start and end locations are logically connected with each other. That means the start location comes after the end location. 19. What are push and pop operations? Push adding an element to the top of stack Pop removing or deleting an element from the top of stack 20. What are enqueue and dequeue operations? Enqueue - adding an element to the queue at the rear end Dequeue removing or deleting an element from the queue at the front end Page 5

Part B 1. Explain Stack ADT and its operations 2. Explain array based implementation of stacks 3. Explain linked list implementation of stacks 4. Explain the applications of Stacks 5. Explain how to evaluate arithmetic expressions using stacks 6. Explain queue ADT 7. Explain array based implementation of queues 8. Explain linked list implementation of queues 9. Explain the applications of queues 10. Explain circular queue and its implementation 11. Explain double ended queue and its operations Page 6

CS6202 - PROGRAMMING & DATA STRUCTURES I Unit V Part A 1. Define sorting Sorting arranges the numerical and alphabetical data present in a list in a specific order orsequence. There are a number of sorting techniques available. The algorithms can be chosen based on the following factors Size of the data structure Algorithm efficiency Programmer s knowledge of the technique. 2. Mention the types of sorting x Internal sorting x External sorting 3. What do you mean by internal and external sorting? An internal sort is any data sorting process that takes place entirely within the main memory of a computer. This is possible whenever the data to be sorted is small enough to all be held in the main memory. External sorting is a term for a class of sorting algorithms that can handle massiveamounts of data. External sorting is required when the data being sorted do not fit into the main memory of a computing device (usually RAM) and instead they must reside in the slower external memory (usually a hard drive) 4. Define bubble sort Bubble sort is a simplesorting algorithmthat works by repeatedly stepping through thelist to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. 5. How the insertion sort is done with the array? It sorts a list of elements by inserting each successive element in the previously sorted sublist. Consider an array to be sorted A[1],A[2],.A[n] a. Pass 1 : A[2] is compared with A[1] and placed them in sorted order. b. Pass 2 : A[3] is compared with both A[1] and A[2] and inserted at an appropriate place. This makes A[1], A[2],A[3] as a sorted sub array. c. Pass n-1 : A[n] is compared with each element in the sub array A[1],A[2], A[n-1] and inserted at an appropriate position. Page 1

6. What are the steps for selection sort? x The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. x Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. x The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right. 7. What is meant by shell sort? Shell sort, also known as Shell sort or Shell's method, is an in-place comparison sort. Itcan either be seen as a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort). [1] The method starts by sorting elements far apart from each other and progressively reducing the gap between them. Starting with far apart elements can move some out-of-place elements into position faster than a simple nearest neighbor exchange. Donald Shell published the first version of this sort in 1959. The running time of Shell sort is heavily dependent on the gap sequence it uses 8. What are the steps in quick sort? The steps are: a. Pick an element, called a pivot, from the list. b. Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation. c. Recursively apply the above steps to the sub-list of elements with smaller valuesand separately to the sub-list of elements with greater values. 9. Define radix sort Radix Sort is a clever and intuitive little sorting algorithm. Radix sort is a noncomparative integer sorting algorithm that sorts data with integer keys by grouping keysby the individual digits which share the same significant position and value. Radix Sort puts the elements in order by comparing the digits of the numbers. 10. What are the advantages of insertion sort Advantages a. Simplest sorting technique and easy to implement b. It performs well in the case of smaller lists. c. It leverages the presence of any existing sort pattern in the list Page 2

Disadvantages x Efficiency of O(n ) is not well suited for large sized lists x It requires large number of elements to be shifted 11. Define searching Searching refers to determining whether an element is present in a given list of elements or not. If the element is present, the search is considered as successful, otherwise it is considered as an unsuccessful search. The choice of a searching technique is based on the following factors a. Order of elements in the list i.e., random or sorted b. Size of the list 12. Mention the types of searching The types are x Linear search x Binary search 13. What is meant by linear search? Linear search or sequential search is a method for finding a particular value in alistthat consists of checking every one of its elements, one at a time and in sequence, until the desired one is found. 14. What is binary search? For binary search, the array should be arranged in ascending or descending order. In each step, the algorithm compares the search key value with the middle element of the array. If the key match, then a matching element has been found and its index, or position, is returned. Otherwise, if the search key is less than the middle element, then the algorithm repeats its action on the sub-array to the left of the middle element or, if the search key is greater, on the sub-array to the right. 15. Define hashing function A hashing function is a key-to-transformation, which acts upon a given key to compute the relative position of the key in an array. A simple hash function HASH(KEY_Value)= (KEY_Value)mod(Table-size) 16. What is open addressing? Open addressing is also called closed hashing, which is an alternative to resolve the collisions with linked lists. In this hashing system, if a collision occurs, alternative cells are tired until an empty cell is found. Page 3

There are three strategies in open addressing: x Linear probing x Quadratic probing x Double hashing 17. What are the collision resolution methods? The following are the collision resolution methods x Separate chaining x Open addressing x Multiple hashing 18. Define separate chaining It is an open hashing technique. A pointer field is added to each record location, when an overflow occurs, this pointer is set to point to overflow blocks making a linked list. In this method, the table can never overflow, since the linked lists are only extended upon the arrival of new keys. Part B 1. Explain the sorting algorithms 2. Explain the searching algorithms 3. Explain hashing 4. Explain open addressing 5. Write a C program to sort the elements using bubble sort. 6. Write a C program to perform searching operations using linear and binary search. 7. Explain in detail about separate chaining. Page 4