Vous êtes sur la page 1sur 24

M.A.M.SCHOOL OF ENGINEERING SIRUGANUR, TIRUCHIRAPPALLI 621 105.

Department of Computer Science and Engineering QUESTION BANK AIM EC2202 - DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++

To provide an in-depth knowledge in problem solving techniques and data structures. OBJECTIVES To learn the systematic way of solving problems To understand the different methods of organizing large amounts of data To learn to program in C++ To efficiently implement the different data structures To efficiently implement solutions for specific problems UNIT - I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 9 Introduction- Tokens-Expressions-contour Structures -Functions in C++, classes and objects, constructors and destructors ,operators overloading and type conversions . UNIT - II ADVANCED OBJECT ORIENTED PROGRAMMING 9 Inheritance, Extending classes, Pointers, Virtual functions and polymorphism, File Handling Templates, Exception handling, Manipulating strings. UNIT - III DATA STRUCTURES & ALGORITHMS 9 Algorithm, Analysis, Lists, Stacks and queues, Priority queues-Binary Heap-Application, Heaps-hashing-hash tables without linked lists UNIT - IV NONLINEAR DATA STRUCTURES 9 Trees-Binary trees, search tree ADT, AVL trees, Graph Algorithms-Topological sort, shortest path algorithm network flow problems-minimum spanning tree - Introduction to NP - completeness. UNIT - V SORTING AND SEARCHING 9 Sorting - Insertion sort, Shell sort, Heap sort, Merge sort, Quick sort, Indirect sorting, Bucket sort, Introduction to Algorithm Design Techniques -Greedy algorithm (Minimum Spanning Tree), Divide and Conquer (Merge Sort), Dynamic Programming (All pairs Shortest Path Problem). Total hours = 45 TEXT BOOKS: 1. Mark Allen Weiss, "Data Structures and Algorithm Analysis in C", 3rd ed, Pearson Education Asia,2007. 2. E. Balagurusamy, " Object Oriented Programming with C++", McGraw Hill Company Ltd., 2007. REFERENCES: 1. Michael T. Goodrich, "Data Structures and Algorithm Analysis in C++", Wiley student edition, 2007. 2. Sahni, "Data Structures Using C++", The McGraw-Hill, 2006. 3. Seymour, "Data Structures", The McGraw-Hill, 2007. 4. Jean - Paul Tremblay & Paul G.Sorenson, An Introduction to data structures with applications, Tata McGraw Hill edition, II Edition, 2002. 5. John R.Hubbard, Schaums outline of theory and problem of data structure with C++, McGraw-Hill, New Delhi, 2000. 6. Bjarne Stroustrup, The C++ Programming Language, Addison Wesley, 2000 7. Robert Lafore, Object oriented programming in C++, Galgotia Publication

do w

ECE III SEM

nl o

ad ed

fro m

re j

in

pa ul .c
DS & OOPS QB

om

TWO MARKS QUESTIONS AND ANSWERS UNIT 1 & 2

1. List out the characteristics of FOP.

1. Large programs are divided into smaller programs known as functions. 2. Most of the functions share global data 3. Functions transform data from one form to another. 4. It 2. List out the characteristics of OOP. 1. Programs are divided into objects. 2. Data is hidden. responses. 4. It follows bottom-up approach. 3. List down the basic concepts of OOP. 1. Objects Classes 2. Data abstraction and encapsulation 3. Inheritance 4. Polymorphism 5. Dynamic binding Message passing 4. Define an object. 3. Objects communicate with each other, by sending messages and receiving employs top-down approach.

Objects are the basic run time entities in an object oriented system. They may represent a person, a place or any item that a program has to handle. 5. Define Object Oriented Programming. OOP is a method of implementation in which programs are organized as co-operative collection of objects, each of which represents an instance of some class and whose classes are all members of a hierarchy of classes united through the property called Inheritance. 6. Define a class. A class is a collection of objects with similar attributes and operations. Eg. Class - Account It will create an object savings_account belonging to the class Account. The wrapping up of data and functions into a single unit is known as encapsulation. The data

do w

7. Define Encapsulation. is kept safe from external interference and misuse. 8. Define Data hiding? The isolation of data from direct access by the program is called as data hiding or information hiding.

9. Define Abstraction.

ECE III SEM

nl o

ad ed

fro m

re j
DS & OOPS QB

in

pa ul .c

om

It refers to the act of representing essential features without including the background details. 10. Define ADT? The classes which are using the concept of data abstraction is known as abstract data types (ADT). 11. Define data member and member function? that operate on data member are sometimes called as member function. 12. Define Inheritance? The attributes which are holding the information is known as data members. The functions

another class. The new derived class inherits the members of the base class and also adds its own. 13. Define Polymorphism? It allows a single name/operator to be associated with different operations depending on the type of data passed to it. An operation may exhibit different behaviors in different instances. 14. Define dynamic binding? until the time of call at runtime. 15. What is message passing? Dynamic binding means that the code associated with the given procedure call is not known

It is the process of invoking an operation on an object. In response to a message, the corresponding function is executed in the object. 16. List down the benefits of OOP?

1. The principle of data hiding helps to build secure programs. 2. Through inheritance, redundant code is eliminated. 17. List down the applications of OOP. 1. Real time system 2. Simulation and modeling 3. AI and expert system 3. Software complexity can be easily managed.

18. What is Implicit Type Conversion?

do w

conversions automatically. This is referred as Implicit Type Conversion. 19. What are the differences between break and continue statement.

20. Distinguish while and do - while statements.

ECE III SEM

nl o

4. Neural network programming. 5. CAD/CAM systems. When an expression consists of data items of different types, the compiler performs type

ad ed

fro m

re j

in

pa ul .c
DS & OOPS QB

Inheritance is the process by which objects of one class acquire the properties of objects of

om

21. Give the syntax of Array Initialization with an example. Data-type array-name[size] = {list of values separated by comma}; (eg.) int mark[5] = {96,45,66,74,82}; strlen( ) - finds the length of string strcpy( ) - copies the contents of one string to another strcat( ) - concatenates two strings into one single string strupr( ) - converts a lower case string to upper case (i) Pass by value (ii) Pass by Address (iii) Pass by Reference 24. What is Dynamic memory allocation? execution is called as Dynamic memory allocation. 22. Give four examples for String Manipulation functions.

23. List the different types of parameter passing techniques.

Allocation of memory space for any data structure during the course of the program 25. How memory management is performed dynamically in C++? Two operators are available for dynamic memory management. (i) new - for dynamic memory allocation 26. Define class? hidden if necessary. (ii) delete - for dynamic memory deallocation

27. What are the parts of class specification? The class specification has two parts 1. Class declaration - To describe the type and scope of its members 28. Write the syntax of class declaration.

do w

29. Where will you define a member function?

ECE III SEM

nl o

2. Class function definition - To describe how the class functions are implemented. class classname { Private: Variable declaration; Function declaration; Public: Variable declaration; Function declaration; };

ad ed

A class is a way to bind data and its associated functions together. It allows the data to be

fro m

re j

in
DS & OOPS QB

pa ul .c

om

Member functions can be defined in two places. 1. Outside the class definition. 2. Inside the class definition. 30. Give the syntax for member function definition outside the class. Return type class name:: function name (argument name declaration) { } 31. List the characteristics of member function. 1. Member function can access the private data of class. 32. Define nesting of member function. class. This is known as nesting of member functions. 33. List the properties of static members. function body

2. A member function can call another member function directly without using the dot operator. A member function can be called by using its name inside another member function of the same

A data member of a class can be qualified as static properties. 2. It is visible only within the class.

34. Write the properties of static member function. class.

1. A static function can have access to only other static members declared in the same 2. A static member function can be called using the class name (Instead of objects) as follows: class name:: function name; 35. Define constructor?

A constructor is a special member function whose task is to initialize the object of its class. It is called constructor because it constructs the value of data members of the class. 36. What are the characteristics of constructor? Constructors should be declared in public section. They are involved automatically when the objects are created. They do not have return types. They cannot be inherited.

do w

37. Define parameterized constructor. Arguments can be passed to the constructor function when the objects are created.The constructors that can take arguments are called as parameterized constructor. 38. What is an implicit constructor? C++ compiler has an implicit constructor which creates objects even though it was not defined in the class. 39. What is the use of copy constructor? Copy constructor is used to declare and initialize an object from another object.

ECE III SEM

nl o

ad ed

fro m

re j

1. It is always initialized to zero when the first object of its class is created.

in

pa ul .c
DS & OOPS QB

om

E.g. Class name object2 (object1); Will define the object2 and at the same time initialize it the values of object1. 40. What do you mean by dynamic construction? Allocation of memory to objects at the time of their contraction Is known as dynamic contraction of objects. 41. What is the use of destructor? memory space for future use. 42. What are the characteristics of destructor? preceded by a tilde. 2. It neither takes any argument nor returns any value. 43. Define operator overloading? is known as operator overloading. 44. Define function overloading? overloading. 45. Define Virtual function. to as virtual function. 46 .What are C++ Streams? It is used to destroy the objects that have been created by a constructor. It releases the

3. It will be invoked implicitly by the compiler to clean up the storage.

The process of making an operator to exhibit different behaviors in different instances

Performing different types of task using single function name is referred as function

When the form of a member function is changed at run time, that member function is referred

consistent input-output system in the form of streams library. It is a collection of classes and objects which can be used to build a powerful system or it can be modified and extended to handle user defined data types . 47. List the predefined console streams.

do w

48. Give the usage of ios class. The ios class provides operations common to both input and output. It contains a pointer to a buffer object. It has constants and member functions that are useful in handling formatted a) b) c) istream - input stream ostream - output stream iostream - input-output stream

I/O operations. Following are the derived classes of ios class,

ECE III SEM

nl o

a) c)

cin - standard input cout - standard output clog - fully buffered version of cerr

b) d)

cerr - standard error output

ad ed

The C++ language offers a mechanism, which permits the creation of an extensible and

fro m

re j

in
DS & OOPS QB

pa ul .c

1. A destructor is a member function whose name is the same as the class name but it is

om

49. What are the types of formatted console i/o operations? a) b) c) ios stream class member functions and class standard manipulators userdefined manipulators Flag value (a) Left justified output ios::left (b) Decimal conversion ios::dec Bit field ios::basefield

50. Give the flag value and bit field for (a) Left justified output and (b) Decimal conversion. ios::adjustfield

51. What are the types of manipulators? Give example. Two types of manipulators are available in C++. a) Parameterized manipulators Eg: setw(int width) - sets the field width b) Non-parameterized manipulator Eg: dec - sets the conversion base to 10 52. What is a custom manipulator? Give its syntax. as custom manipulator. Syntax: { // manipulator code return output; }

setprecision(int prec) - sets the floating point precision

Endl - outputs a new line and flushes stream

Designing of customized manipulators to control the appearance of the output is referred

ostream & manipulator(ostream & output, arguments_if_any)

53. Write a note on File.

A file is a collection of related information normally representing programs, both source and object forms and data. Data may be numeric, alphabetic or alphanumeric. A file can also be defined as a sequence of bits, bytes, lines or records whose meaning is defined by the programmer. Operations such as create, open, read, write and close are performed on files. 54. Define ifstream & fstream. ifstream: It is used for handling input files. It contains open() with default input mode and inherits

do w

get(), getline(), read(), seekg(), tellg() functions from istream. fstream: Used for handling files on which both i/o operations can be performed. It supports simultaneous i/o operations. It contains open() with default input mode and inherits all the functions from istream and ostream classes through iostream.

ECE III SEM

nl o

ad ed

fro m

re j

in
DS & OOPS QB

pa ul .c

om

55. Give the prototypes of file stream class constructors. a) ifstream class constructor ifstream(const char *path, int mode=ios::in, int prot=filebuf::openprot); b) ofstream class constructor ofstream(const char *path, int mode=ios::out int prot=filebuf::openprot); c) fstream class constructor 56. List any four file modes and their purpose ios::in - open for reading ios::ate - seek to the end of file at opening time ios::nocreate - open fails if file does not exist ios::binary - opens a binary file 57. List the file pointer control functions. seekg() - moves get file pointer to a specific location seekp() - moves put file pointer to a specific location tellg() - returns the current position of the get pointer 58. What are the types of file accessing? Sequential access tellp() - returns the current position of the put pointer fstream(const char *path, int mode=ios::in/ios::out, int prot=filebuf::openprot);

This type of file is to be accessed sequentially that is to access a particular data all the preceding data items have to be read and discarded. Random access items This type of file allows access to the specific data directly without accessing its preceding data 59. Give any two error handling functions and their purpose a) eof() - TRUE(nonzero) if eof encountered while reading; otherwise FALSE(zero) b) rdstate() - returns the status state data member of the class ios 60. Define fault avoidance and fault tolerance

do w

techniques to be applied during system development that ensures the system satisfies all reliability criteria Fault tolerance: This deals with the method of providing services complying with the specification in spite of

false occurring by redundancy. The error handling mechanism of C++ is referred to as exception handling. Exception

61. What is exception handling? How it is classified? refers to some unexpected condition in a program. It is classified as synchronous and asynchronous exception.

ECE III SEM

nl o

Fault avoidance:

It deals with the prevention of fault occurrence by construction. It emphasizes on

ad ed

fro m

re j
DS & OOPS QB

in

pa ul .c

om

Synchronous exception: The exceptions, which occur during the program execution, due to some fault in input data, within the program, is known as Synchronous exception. Asynchronous exception: The exceptions caused by events or a fault unrelated to the program and beyond the control of the program is known as asynchronous exception. a) try which an exception may occur must be prefixed by this keyword. b) throw 62. Define the exception handling constructs.

This keyword defines a boundary within which an exception can occur. A block of code in

Throw is used to raise an exception when an error is generated in the computation. It initializes a temporary object to be used in throw. c) catch

This keyword represents exception handler. It must be compulsorily used immediately after the statements marked by try keyword. It can also occur immediately after the type specified in the argument list a) b) c) d) catch keyword. Each handler will only evaluate an exception that matches or can be converted to 63. What are the tasks to be performed by error handling code? Hit the exception - detect the problem causing exception Throw the exception - inform that an error has occurred Catch the exception - receive the error information Handle the exceptions - take corrective actions

terminate() - it is invoked when an exception is raised and the handler is not found. set_terminate() - allows the user to install a function that defines the programs actions to be taken to terminate the program when a handler for the exception cannot be found unexpected() - this function is called when a function throws an exception not listed in its exception

set_unexpected() - it allows the user to install a function that defines the programs actions to

do w

65. How fault tolerant s/w design techniques are classified? N-version programming - in this technique, N-programmers develop N algorithms for

the same problem with out interacting with each other. All these algorithms are executed simultaneously on a multiprocessor system and the majority solution is taken as the correct answer. Recovery block - this structure represents the dynamic redundancy approach to s/w fault

ECE III SEM

nl o

ad ed

64. List the functions for handling uncaught exceptions.

specification

be taken when a function throws an exception not listed in its exception specification

fro m

re j

in

pa ul .c
DS & OOPS QB

om

tolerance. It consists of (i) Primary routine - executes critical s/w function, (ii) acceptance test - tests the output of primary routine after each execution and (iii) alternate routine - performs the same function as primary routine but is invoked by an acceptance test after reduction of a fault. 1. What is an Algorithm? UNIT 3, 4 & 5

An algorithm is clearly specified set of simple instructions to be followed to solve a problem. The algorithm forms a base for program. 2. What are the properties of an Algorithm? Takes zero or more inputs Results in one or more outputs All operations are carried out in a finite time Efficient and flexible 3. Define Program? algorithm. 4. What is Complexity analysis? completion. There are two types of Complexity

Should be concise and compact to facilitate verification of their correctness.

It is an instruction and it is written according to the instructions, which is given in the

It is the analysis of the amount of memory and time an algorithm requires to Space Complexity and Time Complexity 5. Explain the performance analysis of the algorithm? The analysis of the performance of an algorithm based on specification is called performance analysis. It is loosely divided into a. Priori estimates b. Posterior Testing

6. Explain Space complexity? completion.

Space complexity of an algorithm is the amount of memory it needs to run to 7. Explain Time complexity? completion.

do w

8. List out the components that are used for space complexity? a. Instruction Space b. Environment Stack c. Data Space. Asymptotic notations are terminology that is introduced to enable us to make meaningful statements about the time and space complexity of an algorithm. The different notations are

9. What do asymptotic notation means?

ECE III SEM

nl o

Time complexity is the amount of computer time an algorithm requires to run to

ad ed

fro m

re j

in
DS & OOPS QB

pa ul .c

om

Big - Oh notation Omega notation Theta notation. 10. Define Efficiency of an algorithm? It denotes the rate at which an algorithm solves a problem of size n. It is measured by the amount of resources it uses, the time and the space. 11. Define Worst case of an algorithm? It is the longest time that an algorithm will use over all instances of size n for a given problem to produce the result. 12. Define Best case of an algorithm? given problem to produce the result. 13. Define average case an algorithm? given problem to produce the result. 14. Define Divide and Conquer algorithm?

It is the shortest time that an algorithm will use over all instances of size n for a

It is the average time that an algorithm will use over all instances of size n for a

several, smaller sub instances, solving them independently and then combining the sub instances solutions so as to yield a solution for the original instance. a. Quick Sort b. Merge Sort c. Binary search 15. Mention some application of Divide and Conquer algorithm?

16. Define dynamic programming algorithm?

Dynamic programming algorithm is a general class of algorithms which solve problems by solving smaller versions of the problem, saving the solutions to the small problems and then combining them to solve the larger problems. 17. Mention application of dynamic programming algorithm? Efficient Fibonacci number computation Chained matrix multiplication. Longest common subsequence problem Devising the algorithm Validating the algorithm Expressing the algorithm Determination of complexity of the algorithm

18. State the various steps in algorithm?

do w

19. Define algorithm paradigms space of an algorithm? Algorithmic paradigms are defined as the general approach to design and construct efficient solutions to problems.

20. Mention the various spaces utilized by a program? a. A fixed amount of memory occupied by the space for the program code and space

ECE III SEM

nl o

ad ed

fro m

re j

Divide and Conquer algorithm is based on dividing the problem to be solved into

in

pa ul .c
DS & OOPS QB

om

occupied by the variables used in the program. b. A variable amount of memory occupied by the variable whose size is dependent on the problem being solved. This space increases or decreases depending upon whether the program uses iterative or recursive procedures. 21. Define ADT (Abstract Data Type)? An ADT is a mathematical model with a collection of operations defined on that model. 22. Define linear data structure? adjacent elements. Eg: Linked List. 23. Define Non Linear data structure? Linear data structures are data structures having a linear relationship between its

Non Linear data structures are data structures dont have a linear relationship between its adjacent elements, but had the hierarchical relationship. Eg: Graph, Tree. 24. What are different types of Linked List? 25. What are different types of Circular Linked List? Single linked list Double linked list Circular linked list Circular Single linked list Circular double linked list

26. List the basic operations carried out in a linked list? Traversal of List 27. Define a stack?

a. Creation of list b. Insertion of list c. Deletion of list d. Modification of list e.

Stack is an ordered collection of elements in which insertions and deletions are restricted to one end. The end from which elements are added and /or removed is referred to as top of the stack. Stacks are also referred as piles and push-down lists. 28. Define a queue? Queue is an ordered collection of elements in which insertions and deletions are restricted to one end. The end from which elements are added and / or removed is referred to as the rear end and the end from which deletions are made is referred to as front end. 29. Difference between Arrays and Linked List?

nl o

Arrays

ad ed

fro m

Size of any array is fixed.

do w

It

is

necessary

to

specify

the

number

of

elements during declaration Insertion and deletions are difficult and costly. It occupies less memory than a linked List. Coding is easy.

30. What is single linked list? It is a linear data structure which contains a pointer field that points to the address

ECE III SEM

re j
Linked List during declaration errors.

Size of list is variable. It is not necessary to specify the elements Insertions and deletions are done in less time. It occupies more memory. Careful coding is needed to avoid memory

in
DS & OOPS QB

pa ul .c

om

of its next node (successor) and the data item. 31. Define HEAD pointer and NULL pointer? HEAD - It contains the address of the first node in that list. NULL - It indicates the end of the list structure. 32 What is meant by dummy header? It is ahead node in the linked list before the actual data nodes. 33. Define Circular linked list? 34. Write operations that can be done on stack? PUSH and POP 35. Mention applications of stack? Hanoi e. Reversing a string 36. Define Infix, prefix and postfix notations? It is a list structure in which last node points to the first node there is no null value.

a. Expression Parsing b. Evaluation of Postfix c. Balancing parenthesis d. Tower of

Infix operators are placed in between the operands Prefix operators are placed 37. What are the conditions that followed in the array implementation of queue? Condition Situation REAR<FRONT EMPTY QUEUE

FRONT==REAR ONE ENTRY QUEUE REAR==ARRAY SIZE FULL QUEUE

Condition Situation

REAR==HEAD EMPTY QUEUE

REAR==LINK (HEAD) ONE ENTRY QUEUE NO FREE SPACE TO INSERT FULL QUEUE

do w

39. What are the conditions that could be followed in a linked list implementations of queue? Condition Situation (REAR MOD ARRAY SIZE +1)==FRONT EMPTY QUEUE (REAR MOD ARRAY SIZE +2)==FRONT FULL QUEUE FRONT==REAR ONE ENTRY QUEUE 40. Define Circular queue?

ECE III SEM

nl o

ad ed

38. What are the conditions that could be followed in a linked list implementations of queue?

fro m

re j

before the operands Postfix Operators are placed after the operands.

in

pa ul .c
DS & OOPS QB

om

A circular queue allows the queue to wrap around upon reaching the end of the array. 41. Define tree. Trees are non-liner data structure, which is used to store data items in a shorted sequence. It represents any hierarchical relationship between any data Item. It is a collection of nodes, which has a distinguish node called the root and zero or more nonempty sub trees T1, T2,.Tk. each of which are connected by a directed edge from the root. 42. Define Height of tree.

43. Define Depth of tree.

For any node n, the depth of n is the length of the unique path from the root to node n. Thus for a root the depth is always zero. 44. Define Degree of a node.

It is the number of sub trees of a node in a given tree. 45. Define Degree of a tree.

It is the maximum degree of a node in a given tree.

Nodes with no children are known as leaves. A leaf will always have degree zero and is also called as terminal node. 47. Define Non-terminal node?

48. Define sibling?

49. Define binary tree?

do w

A Binary tree is a finite set of data items which is either empty or consists of a single item called root and two disjoin binary trees called left sub tree max degree of any node is two. 50. Define expression tree? Expression tree is also a binary tree in which the leafs terminal nodes or operands and non-terminal intermediate nodes are operators used for traversal. 51. Define Construction of expression trees 1. Convert the given infix expression into postfix notation

ECE III SEM

nl o

Nodes with the same parent are called siblings.

ad ed

Any node except the root node whose degree is a non-zero value is called as a non-terminal node. Non-terminal nodes are the intermediate nodes in traversing the given tree from its root node to the terminal node.

fro m

46. Define Terminal node or leaf?

re j
DS & OOPS QB

in

pa ul .c

The height of n is the length of the longest path from root to a leaf. Thus all leaves have height zero. The height of a tree is equal to a height of a root.

om

2. Create a stack and read each character of the expression and push into the stack, if operands are encountered. 3. When an operator is encountered pop 2 values from the stack. 52. Define lazy deletion? When an element is to be deleted it is left in the tree itself and marked as being deleted. This is called as lazy deletion and is an efficient procedure if duplicate keys are present in the binary search tree, because the field that keeps count of the frequency of appearance of the element can be decremented of the element can be decremented. 53. Define AVL tree?

AVL tree also called as height balanced tree .It is a height balanced tree in which every node will have a balancing factor of 1,0,1. sub tree and the height of the right sub tree.

Balancing factor of a node is given by the difference between the height of the left 54. What are the various operation performed in the binary search tree? 1. insertion 2. deletion 3. find 4. find min 5. find max

55. What are the various transformation performed in AVL tree?

- Single L rotation

- Single R rotation 2. Double rotation

do w

56. General idea of hashing and what is the use of hashing function?

A hash table similar to an array of some fixes size-containing keys. The keys specified here might be either integer or strings, the size of the table is taken as table size or the keys are mapped on to some number on the hash table from a range of 0 to table size 57. What is priority queue?

ECE III SEM

nl o

-LR rotation -RL rotation

ad ed

1. Single rotation

fro m

re j
DS & OOPS QB

in

pa ul .c

om

A priority queue is a data structure that allows at least the following two operations: insert which does the obvious thing; and Deletemin, which finds, returns, and removes the minimum element in the priority queue. The Insert operation is the equivalent to enqueue. 58. Application of priority queues? 1. for scheduling purpose in operating system 2. used for external sorting

by repeatedly finding a minimum. 59. What are the main properties of a binary heap? 1. Structure property 2. Heap order property

60. Define tree traversal and mention the type of traversals?

1. inorder traversal 2. preoder traversal 3. postorder traversal.

sorted?

One of the simplest sorting algorithms is the insertion sort. Insertion sort consist of N-1 passes. For pass P=1 through N-1 , insertion sort ensures that the elements in positions 0 through P-1 are in sorted order .It makes use of the fact that elements in position 0 62. Write the function in C for insertion sort ? Void insertionsort(elementtype A[ ] , int N) { int j, p; through P-1 are already known to be in sorted order .

do w

63. Who invented shell sort? Define it?

ECE III SEM

nl o

elementtype tmp; for(p=1 ; p <N ;p++ ) { tmp = a[ p] ; for ( j=p ; j>0 && a [ j -1 ] >tmp ;j--) a [ j ]=a [j-1 ] ; a [ j ] = tmp ; } }

ad ed

fro m

61. What is insertion sort? How many passes are required for the elements to be

re j

Three types of tree traversal

in

Visiting of each and every node in the tree exactly is called as tree traversal

pa ul .c
DS & OOPS QB

om

3. important for the implementation of greedy algorithm, which operates

Shell sort was invented by Donald Shell. It works by comparing element that are distant. The distance between the comparisons decreases as the algorithm runs until the last phase in which adjacent elements are compared. Hence it is referred as diminishing increment sort. 64. Write the function in c for shell sort? Void Shellsort(Elementtype A[ ],int N) { int i , j , increment ; elementtype tmp ; for(elementtype=N / 2;increment > 0;increment / = 2) For( i= increment ; i <N ; i ++) { tmp=A[ ]; for( j=I; j>=increment; j - =increment) if(tmp< A[ ]=A[j increment]; A[ j ]=A[ j increment]; Else Break; A[ j ]=tmp; } } 65. What is maxheap?

If we want the elements in the more typical increasing sorted order, we can change heap.

66. What are the two stages for heap sort? Stage 1: Construction of heap 67. What is divide and conquer strategy? In divide and conquer strategy the given problem is divided into smaller problems and solved recursively. The conquering phase consists of patching together the answers. Divide and conquer is a very powerful use of recursion that we will see many times. 68. Differentiate between merge sort and quick sort? Mergesort Quicksort Divide and conquer strategy Partition by value Stage 2: Root deletion N-1 times

do w

1. Divide and conquer strategy 2. Partition by position 1. Choosing first element

69. Mention some methods for choosing the pivot element in quicksort?

ECE III SEM

nl o

ad ed

the ordering property so that the parent has a larger key than the child. it is called max

fro m

re j
DS & OOPS QB

in

pa ul .c

om

2. Generate random number 3. Median of three 70. What are the three cases that arise during the left to right scan in quicksort? 1. I and j cross each other 2. I and j do not cross each other 3. I and j points the same position 71. What is the need of external sorting? External sorting is required where the input is too large to fit into memory. So external sorting is necessary where the program is too large. 72. Define two way merge? 73. Define multi way merge?

It is a basic external sorting in which there are two inputs and two outputs tapes. If we have extra tapes then we can expect to reduce the number of passes required to sort our input. We do this by extending two way merge to a k-way merge. 74. Define polyphase merge?

The k-way merging strategy requires the use of 2 k tapes. This could be prohibitive 75. What is replacement selection?

We read as many records as possible and sort them. Writing the result to some record is written to a output tape the memory it used becomes available for another record. If the next record on the input tape is larger than the record we have just output then it can be included in the item. Using this we can give algorithm. This is called replacement selection. 76. What is sorting?

Sorting is the process of arranging the given items in a logical order. Sorting is an example where the analysis can be precisely performed. 77. What is mergesort?

divided into two arrays and merged into single array

do w

78. What are the properties involved in heapsort? 1. Structure property 2. Heap order property

79. Define articulation points. If a graph is not biconnected, the vertices whose removal would disconnect the graph are known as articulation points. 80. Give some example of NP complete problems. i. Hamiltonian circuit.

ECE III SEM

nl o

The mergesort algorithm is a classic divide and conquer strategy. The problem is

ad ed

fro m

tapes. This seems like the best approach possible until one realizes that as soon as the first

re j

for some applications. It is possible to get by with only k+1 tapes.

in

pa ul .c
DS & OOPS QB

om

ii. Travelling salesmen problems iii. Longest path problems iv. Bin packing v. Knapsack problem vi. Graph coloring problem 81. What is a graph? A graph consists of a set of vertices V and set of edges E which is mathematically represented as G=(V,E).Each edge in a pair(V,W) where V,W, belongs to E ,edges are sometimes referred to as arcs. 82. What are Directed graphs? directed graph. 83. Define Path.

If a pair of vertices for any edge is ordered, then that graph is called as Digraph or

A path in a graph is a sequence of vertices w1,w2w,3,wN such that Wi,Wi+1 belongs to E for a value 1<=I<=N. The length of such a path is the number of edges on the path, which is equal to n-1. 84. Define Cycle. 85. Define Acyclic graph.

A cycle is a path in which the first and last vertices are the same. A graph with no cycles is called Acyclic graph. A directed graph with no Edges is called as a directed Acyclic graph (or) DAG. DAGS are used for Compiler Optimization process. 86. Define Connected graph.

An undirected graph is connected if there is a path from every vertex to every other vertex. A directed graph with this property is called as strongly connected graph. If a directed graph is not strongly connected but the underline graph. Without direction is connected it is called as a weakly connected graph. 87. What are the conditions for a graph to become a tree? A graph is a tree if it has two properties. i. If it is a connected graph. ii. There should not be any cycles in the graph. A graph is said to be a weighted graph if every edge in the graph is assigned some

do w

88. Define a Weighted Graph. weight or value. The weight of the edge is a positive value that represents the cost of moving the edge or the distance between two vertices. 89. Give the types of representation of graphs. 1. Adjacency matrix 2. Adjacency linked list 90. What is a minimum spanning tree?

ECE III SEM

nl o

ad ed

fro m

re j

in
DS & OOPS QB

pa ul .c

om

A minimum spanning tree of an undirected graph G is a tree formed from graph edges that connect all the vertices of G at lowest total cost. 91. Explain about Adjacency Matrix Adjacency matrix consists of a n*n matrix where n is the no. of vertices present. In the graph, which consists of values either 0 or 1. 92. Explain about Adjacency linked list. It consists of a table with the no. of entries for each vertex for each entry a Linked List is initiated for the vertices adjacent to the corresponding table entry. 93. What is a single source shortest path problem?

as the source vertex. Single source shortest path problem finds the shortest weighted path from s to every other vertex in G. 94. Explain about Unweighted shortest path.

Single source shortest path finds the shortest path from the source to each and every vertex present in a unweighted graph. Here no cost is associated with the edges connecting the vertices. Always unit cost is associated with each edge. 95. Explain about Weighted shortest path

Single source shortest path finds the shortest path from the source to each and every vertex present in a weighted graph. In a weighted graph some cost is always 96. What are the methods to solve minimum spanning tree? a) Prims algorithm associated with the edges connecting the vertices.

b) Kruskals algorithm

Prims algorithm creates the spanning tree in various stages. At each stage, a node is picked as the root and an edge is added and thus the associated vertex along with it. 98. Define a depth first spanning tree. The tree that is formulated by depth first search on a graph is called as depth first spanning tree. The depth first spanning tree consists of tree edges and back edges. 99. What is a tree edge? Traversal from one vertex to the next vertex in a graph is called as a tree edge. The possibility of reaching an already marked vertex is indicated by a dashed line, in

do w

100. What is a back edge? a graph is called as back edge. 101. Define double linked list? It is linear data structure which consists of two links or pointer fields Next pointer points to the address of the next (successor) node. Previous pointer points to the address of the previous (predecessor) node.

ECE III SEM

nl o

ad ed

97. Explain briefly about Prims algorithm

fro m

re j

in

pa ul .c
DS & OOPS QB

Given as an input, a weighted graph, G=<V,E> and a distinguished vertex S

om

16 MARK QUESTIONS UNIT 1&2 1. Explain in detail about the features of Object Oriented paradigm with diagram. 2. a)What are the elements of Object Oriented Programming? b) Explain object and classes with examples. 3. Explain in detail about File stream classes with an example. 4. What are the various categories of operators supported by C++? List any two types and give examples. 5. Explain the following with appropriate sample programs. (i) for loop (ii) dowhile 6. Write programs for the following statements. (i) Nested ifelse (ii) Switch statement

7. Write an interactive program to perform matrix multiplication.

8. Explain about the three types of Parameter passing with suitable examples. 10. a) What is a Pointer? Explain its need and advantages. expressions.

b) List the various pointer arithmetic operations and explain them with sample 11. Illustrate with a program class declaration, definition and accessing class members. 12. Explain the client-server model of object communication. 13. a) What is a constructor? Give its syntax. b) Define Constructor overloading and illustrate its use with a suitable program. 14. a) Write a program to demonstrate the use of Copy constructor. b) What is a destructor? Explain it with an example. 15. What is operator function? Describe operator function with syntax and examples. 16. Write a program to perform addition of complex numbers using stream loading. 17. a) List the different forms of Inheritance and explain. 18. Write a program to demonstrate the overloading of functions in base and derived

do w

19. Explain the difference between a normal Virtual function and Pure Virtual function With example. UNIT 3, 4&5 21.Explain the types of analysis that can performed on an algorithm? _ Correctness analysis _ Rate of growth 20. What is an Abstract class? Write a program for testing the debuggable class.

ECE III SEM

nl o

b) Explain the Multiple Inheritance model with syntax and example. classes.

ad ed

fro m

re j

9. What is Function overloading? Explain it with a suitable program.

in

pa ul .c
DS & OOPS QB

om

_ Time analysis _ Order analysis _ Space analysis _ Example 22.i)Design an algorithm to reverse the linked list. Trace it with an example? ii) Define an efficient representation of two stacks in a given area of memory with n words and explain. i) algorithm _ Define a stack and queue _ Delete elements from queue and add it to stack _ Pop elements from stack _ Example and trace 23. Explain the process of problem solving? _ Problem definition phase _ Getting started with problem _ The use of examples _ Simulation among problems _ Working backwards from solution _ Problem solving techniques _ Input and output assertion _ Implications _ Proof of termination 24. Explain program verification in detail?

ii) _ figure ,_ push operation pop operation advantages

_ Computer model for program execution _ Verification of program segments 25. Explain top down design?

_ Breaking a problem into sub problem

do w

26.What is a Stack?Explain with example? _ Definition of Stack _ Operations of Stack:PUSH and POP _ Example 27.Write the algorithm for converting infix expression to postfix expression? _ Definition of Expression

ECE III SEM

nl o

_ Choice of suitable data structure _ Construction of loops _ Initial conditions for loops _ Iterative construct _ Termination of loops

ad ed

fro m

re j
DS & OOPS QB

in

pa ul .c

om

_ Types of expression _ Algorithm for infix to postfix expression _ Example 28.What is a Queue?Explain its operation with example? _ Definition of Queue _ Operations of Queue:insert and remove _ Example 29.Explain the applications of stack? _ Evaluating arithmetic expression _ Balancing the symbols _ Function calls linear linked implementation of Stack and Queue? _ Introduction to Doubly linked list _ Linked list implementation of Stack _ Linked list implementation of Queue Definition of Binary tree Traversals Inorder traversal Preorder traversal Postorder traversal deleting an element?

30. Write an algorithm for inserting and deleting an element from Doubly linked list? Explain

_ Operations: insertion and deletion with algorithm

31.What is a Binary tree?Explain Binary tree traversals in C?

32.Explain Representing lists as Binary tree?Write algorithm for finding Kth element and Representing list as Binary tree Finding Kth element Deleting an element

do w

34.What is a Priority Queue?What are its types?Explain? Definition of Priority queue Types:Ascending and Descending priority queue Implementation of priority queue 35.Explain AVL tree in detail Definition Creation

ECE III SEM

nl o

33.Explain Binary search tree representation? Node representation of Binary search tree Implicit array representation of Binary tree Implementation of various operations

ad ed

fro m

re j
DS & OOPS QB

in

pa ul .c

om

Types of rotation Deletion 36.Explain Heap sort? Heap sort _ Heap as a priority queue _ Sorting using a heap _ Heap sort procedure 37.Explain Insertion sort with example? _ definition _ algorithm and example _ implementation 38.Explain merge sort with example? _ definition _ algorithm and example _ implementation _ basic merge algorithm with eg 39.Explain shell sort with example? _ definition _ algorithm and example _ implementation _ definition _ implementation 40.Explain quick sort with example? _ algorithm and example

41.Explain Shortest path algorithm with example? _ Shortest path algorithm _ Example

42.Explain Depth first and breadth first traversal?

do w

43.Explain spanning and minimum spanning tree? _ Spanning tree _ Minimum spanning tree

44.Explain Kruskals and prims algorithm? _ Kruskals algorithm _ Prims algorithm

45.Explain topological sorting? _ definition _ algorithm and example _ implementation

ECE III SEM

nl o

_ Depth first traversal

_ Efficiency of Depth first traversal _ Breadth first traversal

ad ed

fro m

re j
DS & OOPS QB

in

pa ul .c

om

Vous aimerez peut-être aussi