24
CS 6301 – PROGRAMMING AND DATA STRUCTURES II CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING II YR / III SEM QUESTION BANK UNIT 1 1. Define object oriented programming? OOP is an approach that provides a way of modularizing programs by creating partitioned memory areas for both data and functions that can be used as an templates for creating copies of such modules on demand. 2. List some features of OOP? Emphasis is on data rather than procedures. Programs that are divided into what are known as objects. Follows bottom – up approach in program design. Functions that operate on the data of an object are tried together in the data structure. 3. List out the benefits of OOPS. Through inheritance, We can eliminate redundant code and extend the use of existing classes. The principle of data hiding helps the programmer to build secure programs. It is possible to have multiple instances of an object to co-exist without any interference. Object oriented systems can be easily upgraded from small to large systems. Software complexity can be easily managed. 4. List out the applications of OOPS. Real time systems Simulation and modeling Object oriented data bases AI and expert systems Neural networks and Parallel programming Prepared by Mrs. S.Deepajothi,AP/CSE Page 1

CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

Embed Size (px)

Citation preview

Page 1: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGYDEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

II YR / III SEM QUESTION BANK

UNIT 1

1. Define object oriented programming?

OOP is an approach that provides a way of modularizing programs by creating partitioned memory areas for both data and functions that can be used as an templates for creating copies of such modules on demand.

2. List some features of OOP?

Emphasis is on data rather than procedures. Programs that are divided into what are known as objects. Follows bottom – up approach in program design. Functions that operate on the data of an object are tried together in the data

structure.3. List out the benefits of OOPS.

Through inheritance, We can eliminate redundant code and extend the use of existing classes.

The principle of data hiding helps the programmer to build secure programs. It is possible to have multiple instances of an object to co-exist without any

interference. Object oriented systems can be easily upgraded from small to large systems. Software complexity can be easily managed.

4. List out the applications of OOPS.

Real time systems Simulation and modeling Object oriented data bases AI and expert systems Neural networks and Parallel programming Decision support and Office automation systems CAD/CAM systems.

5. State the difference between c and c++.

C C++(i). This is a Procedural programming language This is an Object-oriented programming

LanguagePrepared by Mrs. S.Deepajothi,AP/CSE Page 1

Page 2: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

(ii) Global variable can be declared It is an error to declare a variable as

global(iii) Function prototypes are optional All functions must be prototyped.(iv) Local variables can be declared only as

Local variables

It can be declared any where (v) We can call a main() function within This is not allowed

a program.

6. Define Class?

A Class is a collection of objects of similar type. The classes are user-defined data types and behave like built-in types of a

programming language. A class is a way to bind the data and its associated functions together. A class is a user-defined data type with a template that serves to define its

properties. A class is a blueprint that defines the variables & the methods common to all objects

of a certain kind.7. What do you mean by object?

Objects are basic run-time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle. Each object has the data and code to manipulate the data and theses objects interact with each other.

8. What is meant by Encapsulation?

The wrapping up of data and function into a single unit(class) is known as Encapsulation.

9. What do you mean by Data abstraction?

Abstraction refers to the act of representation of essential features without including the background details or explanations. Classes use the concept of abstraction & are defined as a list of abstraction attributes such as size, weight & cost & functions to operate on these attributes.

10. What is meant by storage class specifiers?

Storage class specifiers tell the compiler how to store the subsequent variable. There are five storage class specifiers supported by C++:

i. extern ii. static iii.register iv. autov.mutable

11. What are data members and member functions?

Prepared by Mrs. S.Deepajothi,AP/CSE Page 2

Page 3: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight, and cost and uses functions to operate on these attributes.The attributes are sometimes called as data members because they hold information. The functions that operate on these data are called as methods or member functions.Eg: int a,b; // a,b are data members

Void getdata ( ) ; // member function

12. What is the use of static data member? The static data member informs the compiler that only one copy of the data member exit and all objects of the class should share that variable without duplicating it for each instance of the class.

13. What are the properties of a static data member? The properties of a static data member are,

It is initialized to zero when the first object is created and no other initialization is permitted.

Only one copy of that member is created and shared by all the objects of that class.

It is visible only within the class, but the life time is the entire program.

14. What is a const member function?

If a member function does not alter any data in the class, then we may declare it as a const member function.

e.g. : void getbalance ( ) const;

voidmul(intint) const,;

15. Explain about static member functions.

A member function can have access to only other static members declared in the same class

A static member function can be called using the class name as followsClassname :: function name;

16. What do you mean by constructor?

Constructor is a member function It initializes the objects of its class It has the same name as the class It is automatically invoked when the objects are created It constructs the value of the data members of the class

Prepared by Mrs. S.Deepajothi,AP/CSE Page 3

Page 4: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

It has no return type.15. Give the various types of constructors.

There are four types of constructors. They are Default constructors – A constructor that accepts no parameters Parameterized constructors – The constructors that can take arguments Copy constructor – It takes a reference to an object of the same class as

itself as an argument Dynamic constructors – Used to allocate memory while creating objects

17.What does 'this' pointer refer to?

'this' is a pointer that points to the object for which this function was called.

Application of ‘this’ pointer:

It is used to return the object it points to.

Eg: The statement

return *this;

inside a member function will return the object that invoked the function.

18. What are the features required for object oriented language?

• Data encapsulation.

• Data hiding and access mechanisms.

• Automatic initialization and clear up of objects.

• Operator overloading.

• Inheritance.

• Dynamic binding.

19. What are the features required for object-based programming Language?

• Data encapsulation.

• Data hiding and access mechanisms.

• Automatic initialization and clear up of objects.

• Operator overloading.

Prepared by Mrs. S.Deepajothi,AP/CSE Page 4

Page 5: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

20. What is a scope resolution operator?

Scope resolution operator is used to uncover the hidden variables. It also allows access to global version of variables.

Eg: #include<iostream. h> int m=10; // global variable m void main ( ) { int m=20; // local variable m cout<<”m=”<<m<<”\n”; cout<<”: : m=”<<: : m<<”\n”; } output: 20 10 (: : m access global m)

21. what is the use of scope resolution operator?

Scope resolution operator is used to define the function outside the class. Syntax:

Return type <class name> : : <function name>

Eg: Void x : : getdata()

22. Write some special characteristics of constructor. Some special characteristics of constructor are,

i. They should be declared in the public section. ii. They are invoked automatically when the objects are created. iii. They do not have return types, not even void and therefore, and they cannot return values. iv. They cannot be inherited, though a derived class can call the base class v. They can have default arguments. vi. Constructors cannot be virtual function.

16 marks 1. What is a static member and what are common characteristicsPrepared by Mrs. S.Deepajothi,AP/CSE Page 5

Page 6: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

2. Explain about pointers with example

3 Explain the basic concepts of Object oriented programming

4 What are the difference between pointers to constants and constant topointers (8)

5. Write a C++ program to illustrate the static function (8)

6. Write a C++ program using this pointer.

UNIT 2

1. What are copy constructors? Explain with example?

The constructor that creates a new class object from an existing object of the same class.Eg:- integer i2(i1) or integer i2 = i1 would define the object i2 at the same time initialize the values of i1.

2. Define Compile time polymorphism / Early Binding / static Binding

Compile time polymorphism is implemented by using the overloaded functions and overloaded operators.The overloaded operators or functions are selected for invokation by matching arguments both by type and number. This information is known to the compiler at the compile time therefore the compiler is able to select the appropriate function for a particular function call at the compile time itself.

This is called as ‘Early Binding’ or ‘Static Binding’ or ‘Static Linking’ or ‘Compile time polymorphism’. Early binding simply means an object is bound to its function call at the compile time.

3. Define Runtime Polymorphism?

At runtime, when it is known what class objects are under consideration, the appropriate version of the function is invoked. Since the function is linked with a particular class much later after its compilation, this process is termed as ‘late binding’. It is also known as dynamic binding because the selection of the appropriate function is done dynamically at run time. This runtime polymorphism can be achieved by the use of pointers to objects and virtual functions.

4. What do you mean by Dynamic constructors?

The constructors can be used to allocate memory while creating objects. This will enable the system to allocate the right amount of memory for each object, thus resulting in saving of memory. Allocation of memory to objects at the time of their construction is known as dynamic construction of objects. The memory is allocated with the help of ‘new’ operator.

5. What is meant by inheritance?

Prepared by Mrs. S.Deepajothi,AP/CSE Page 6

Page 7: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

The mechanism of deriving a new class from an old one is called inheritance. The old class is referred to as the base class and the new one is called the derived class or the subclass.

The syntax of deriving a new class from an already existing class is given by,

class derived-class : visibility-mode base-class

{

body of derived class

}

6. Define operator overloading?

A language feature that allows a function or operator to be given more than one definition. For instance C++ permits to add two variables of user defined types with the same syntax that is applied to the basic types. The mechanism of giving such special meaning to an operator is known as operator overloading.

7. Give the operator in C++ which cannot be overloaded?

Sizeof ->size of operator :: - scope resolution opertor ?: - conditional operator . - Membership operator .* - pointer to member operator

8. Give any four rules for operator overloading?

Only existing operators can be overloaded. The overloaded operator must have at least one operand that is of user defined type. We cannot used friend functions to overload certain operators. Overloaded operators follow the syntax rules of the original operators.

9. Define function overloading. A single function name can be used to perform different types of tasks. The same function name can be used to handle different number and different types of arguments. This is known as function overloading or function polymorphism.

10. How the objects are initialized dynamically?

To call parameterized constructor we should the pass values to the object ie,for the constructor integer(int a,int b) it is invoked by integer a(10,18) this value can be get during run time. i.e., f or above constructor int p,q;

Prepared by Mrs. S.Deepajothi,AP/CSE Page 7

Page 8: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

cin>>p>>q; integer a(p,q);

11. What are the types in inheritance?

Single inheritance Multiple inheritance Multilevel inheritance Hierarchical inheritance Hybrid inheritance

12. What's the difference between public, private, and protected?

A member (either data member or member function) declared in a private section of a class can only be accessed by member functions and friends of that class

A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes

A member (either data member or member function) declared in a public section of a class can be accessed by anyone.

13. What do you mean by virtual function?

When we use the same function name in both the base and derived classes, the function in base class is declared as virtual using the keyword virtual preceding its normal declaration.

When a function is made virtual c++ determines which function to use at runtime based on the type of object pointed to by the base pointer, rather than the type of the pointer. Thus by making the base pointer to point to different objects, we can execute different versions of the virtual function.

14. What are the rules for virtual function?

They cannot be static members They are access by using object pointers A virtual function can be a friend of another class.

15. What are pure virtual functions? Write the syntax.

A pure virtual function is a function declared in a base class that has no definition relative to the base class. In such cases, the compiler requires each derived class to either define the function or redeclare it as a pure virtual function. A class containing pure virtual functions cannot be used to declare any object of its own. It is also known as “donothing” function. The “do-nothing” function is defined as follows: virtual void display ( ) =0;

Prepared by Mrs. S.Deepajothi,AP/CSE Page 8

Page 9: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

16 MARKS

1. Explain Nested classes with an example

2. Explain the copy constructors with an example? (8)

3. What is operator overloading? How many arguments are required in the definition of an overloaded binary operator?

4. Explain the different types of polymorphism (16)

5 Explain various types of Inheritance.

6. Explain briefly about function overloading with a suitable example

UNIT 3

1. What is an abstract class?

An abstract class is one that is not used to create objects. An abstract class is designed only to act as a base class.

2. What do you mean by containership or nesting?

A class contains objects of other classes as its member, and then it is called as nesting or containership.

3. What is meant by exception handling?

C++ provides a built-in error handling mechanism called Exception handling. Exception handling is the subsystem of C++ that allows us to handle errors that occur at run time in a structured and controlled manner. With exception handling, program can automatically invoke an error handling routine when an error occurs.

4. Define the keywords upon which exception handling is built

Exception handling is built upon three keywords

try, catch and throw.

try: the block of statements which may generate exceptions is given in try block.

catch: A catch block defined by the keyword catch ‘catches’ the exception

Prepared by Mrs. S.Deepajothi,AP/CSE Page 9

Page 10: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

‘thrown’ by the throw statement in try block.

throw: when an exception is detected, it is thrown using a throw statement in the try block.

5. List some drawbacks of exception handling.1.When we are using library function and are unaware of some specific exception and if an exception is thrown the program would crash. 2. The executable code size and execution time would both increase

6.What are the tasks to be handled by exception handling?

Find the problem(hit the exception) Inform that an error has occurred(throw the exception) Receive the error information(catch the exception) Take corrective actions(handle the exception)

7. What is generic programming? Generic programming is an approach where generic types are used as parameters in algorithms so that they work for a variety of suitable data types and data structures.

8. Define templates

The templates is the most sophisticated & high powered feature of C+ +. Using template it is possible to create generic functions and classes. In a generic function or class, the type of data which the function or class operated is specified as a parameter. Thus it is possible to use one function or class with several different types of data without having to explicitly recode versions of each data type.

application of templates. It is a new concept which enables to define generic classes and functions and thus

provides support for generic programming.

9. Define class template. Write the syntax. Process of creating a generic class using template with an anonymous type

is called as class templatetemplate<class T> class classname{ // class member specification with anonymous type T}

10. What is Generic function? Or Define function template

Prepared by Mrs. S.Deepajothi,AP/CSE Page 10

Page 11: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

A generic function defines a general set of operations that will be applied to various types data. The type of data that the function will operate upon is passed to it as a parameter. Through a generic function, a single general procedure can be applied to a wide range of data.

A generic function is created using the keyword ‘template’

General format:

Template <class T type>ret_type function name(arg list)

{

body of function

}

Note: T type is a place holder name for a data type used by the function.

11. Differentiate between function template & function overloading.

Function Template Function Overloading

1.Only one function definition 1. Several function definitions with the same function name with different argument list.

2. Here the data type upon which the function operates is passed as parameter

2. Here the function can operate on only one data type. For another data type we have to redefine the function with same name with different argument list.

3.Program space is less 3. Program space is large

4. Generic function must perform same general action for all versions.Only data type differs.

4. Different actions can be performed within the body of each function

12. Why Templates are used in C++? The Templates are used to develop reusable software component such as functions, classes, etc. Templates allow the construction of a family of templates functions and classes to perform the same operations on different data types.

13. What is Standard Template Library?

Prepared by Mrs. S.Deepajothi,AP/CSE Page 11

Page 12: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

The collection of these generic classes and functions is called the Standard Template Library

14. List the components of STL

The STL contains several components. They are

1)Containers

2)Algorithms

3)Iterators

15. What is container?

A container is an object that actually stores data.It is a way data is organized in memory. The STL containers are implemented by template classes and therefore can be easily customized to hold different types of data

16. What is an iterator?

An iterator is an object that points to an element in a container. We can use iterators to move through the contents of containers.Iterators are handled just like pointers

17. What are the three types of containers?

The STL contains three types of containers

1) Sequence containers

2) Associative containers

3) Derived containers

18. What is a file?

A file is a collection of related information defined by its creator. Files represent programs (both source and object forms) and data.Data may be numeric,alphabetic, or alphanumeric.Files may be free-form,such as text files,or may be rigidly formatted.

19. List some of the file modes

Prepared by Mrs. S.Deepajothi,AP/CSE Page 12

Page 13: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

1)ios::in

2)ios::out

3)ios::ate

4)ios::app

5)ios::trunk

6)ios::nocreate

7)ios::noreplace

8)ios::binary

16 MARKS

1. What is standard template library? Write the types of STL? Write an example program for each STL types.

2. Explain exception handling with suitable example

3. Discuss the need for exception with try, catch and throw keywords

4. What is Function Template? Write the syntax for function template. Write an example program for function template.

5. What is class template? Write the syntax for class template. Write an example program for class template.

UNIT 41. Define tree.

A tree is a collection of N nodes, one of which is the root, and N-1 edges.

Prepared by Mrs. S.Deepajothi,AP/CSE Page 13

E

D

CB

A

Page 14: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

2. Define leaves and siblings.Nodes with no children are known as leaves.Nodes with the same parent are known as siblings.

3. Define binary tree.A binary tree is a tree in which no node can have more than two children.

4. Define expression tree.An expression tree is a tree with leaves as operands such as constants or variable names and other nodes contain operators

5. How do we calculate the balance factor for each node in a AVL tree?Balace factor (BF) of a node T in a AVL tree is calculated using following formula

BF(T) = hl - hr

Where hl and hr are the heights of left and right subtrees of T.

6. Write the difference between full and complete binary tree.A full binary tree (sometimes proper binary tree or 2-tree) is a tree in which every

node other than the leaves has two childrenA complete binary tree is a binary tree in which every level, except possibly the

last, is completely filled, and all nodes are as far left as possible.

7. Define leaves and siblings.Nodes with no children are known as leaves.Nodes with the same parent are known as siblings.

8. Define binary tree.A binary tree is a tree in which no node can have more than two children.

Prepared by Mrs. S.Deepajothi,AP/CSE Page 14

ED

CB

A

BA

9+

*

CB

A

Page 15: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

9. Define expression tree.An expression tree is a tree with leaves as operands such as constants or variable

names and other nodes contain operators

10. Define binary search tree.A binary search tree is a binary tree in which the left subtree is always less than

the root and the right subtree is always greater than the root.

11. What are the three traversal strategies used in traversing a tree? Inorder Traversal Preorder Traversal Postorder Traversal

12. Define AVL Tree.An AVL tree is a height balanced binary search tree in which height of the left and

right subtrees can differ by at most 1.

13. How do we calculate the balance factor for each node in a AVL tree?Balance factor (BF) of a node T in a AVL tree is calculated using following formula

BF(T) = hl - hr

Where hl and hrare the heights of left and right subtrees of T.Prepared by Mrs. S.Deepajothi,AP/CSE Page 15

BA

9+

*

31

72

5

31

72

5

Page 16: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

14. Write the steps to rebalance the violation of AVL property once insert a new node.

Single Rotation Double Rotation

15. Define splay tree. A splay tree is a binary search tree in which restructuring is done using a scheme

called splay. The splay is a heuristic method which moves a given vertex v to the root of the splay tree using a sequence of rotations.

16. Define Red-Black tree. A Red-Black tree is a binary search tree with the following coloring properties

Every node is colored either red or black The root is black If a node is red, its children must be black Every path from a node to a NULL pointer must contain the same number of black

nodes

17. Define B-Tree.A B-Tree of order M is an M-ary treewith the following properties

The data items are stored at leaves The nonleaf nodes store up to M-1 keys to guide the searching; key I represents

the smallest key in subtree i+1 The root is either a leaf or has between two and M children

All nonleaf nodes (except the root) have between ┌M/2┐and M children

All leaves are at the same depth and have between ┌L/2┐and L data items, for some L

18. What is a disjoint set? Define the ADT for a disjoint set.A disjoint set is a data structure that keeps track of a set of elements partitioned

into a number of disjoint subsets. Disjoint set ADT is a collection of distinguishable objects.

16 MARKS

1. Write an algorithm for inserting and deleting a node in a binary search tree.2. Explain the three standard ways of traversing a binary tree T with a recursive algorithm.3. What are AVL tree? Describe the different rotations defined for AVL tree.4. Discuss Red-Black trees with necessary example.5. Discuss splay trees with necessary example.6. Describe in detail the Binomial heap with example.7. Discuss Fibonacci heap with necessary example.

Prepared by Mrs. S.Deepajothi,AP/CSE Page 16

Page 17: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

8. Explain about disjoint sets and its operation in detail.

UNIT 5

1. Define graph. Write its types.A graph is a collection of two sets V and E where V is a finite non empty set of

vertices and E is a finite non empty set of edges.There are two types of graphs

Directed graph Undirected graph

2. What are the two ways of representing a graph? Adjacency matrix representation Adjacency list representation

3. Define DAG.DAG stands for Directed Acyclic Graph. A directed graph is acyclic if it has no cycles.

4. Define topological sort.A topological sort is an ordering of vertices in a directed acyclic graph, such that if there is a

path from vi to vj, vj appears after vi in the ordering.

5. Define Single-Source Shortest –Path Problem.Let G = (V,E) be a weighted graph and a distinguished vertex s, find the shortest

weighted path from s to every other vertex in G.

6. Define indegree and out degree of a graph.Indegree : In a directed graph , for any node v, the number of edges which have v as their terminal node is called indegree of node v.Out degree :Iin a directed graph , for any node v, the number of edges which have v as their initial node is called out degree of node v.

7. What is spanning tree?

Prepared by Mrs. S.Deepajothi,AP/CSE Page 17

V3

V4

V2

V1

Page 18: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

A spanning tree of a graph G is a subgraph which is basically a tree and it contains all the vertices of G containing no circuit.

8. What is a minimum spanning tree? A minimum spanning tree of an undirected graph G is a tree formed from graph

edges that connects all the vertices of G at the lowest total cost.

9. Name two algorithms two find minimum spanning tree Kruskal’salgorithm Prim’s algorithm

10. What are the two traversal strategies used in traversing a graph? Breadth first search (BFS) Depth first search (DFS)

11. What is the difference between BFS and DFS methods?BFS DFS

1. BFS stands for Breadth First Search2. This traversal is done with the help

of queue data structures3. BFS sequence is composed of tree

edges and cross edges4. It works using one ordering

1. DFS stands for Depth First Search2. This traversal is done with the help

of stack data structures3. DFS sequence is composed of tree

edges and back edges4. It works using two ordering

12. Define graph. Write its types.A graph is a collection of two sets V and E where V is a finite non empty set of

vertices and E is a finite non empty set of edges.There are two types of graphs

Directed graph Undirected graph

13. What are the two ways of representing a graph? Adjacency matrix representation Adjacency list representation

14. What are the two traversal strategies used in traversing a graph? Breadth first search (BFS) Depth first search (DFS)

15. Define indegree and out degree of a graph.

Prepared by Mrs. S.Deepajothi,AP/CSE Page 18

Page 19: CS 6301 – PROGRAMMING AND DATA …chettinadtech.ac.in/.../14-07-02-12-16-09-2652-Deepa.docx · Web viewCS 6301 – PROGRAMMING AND DATA STRUCTURES II Prepared by Mrs. S.Deepajothi,AP/CSE

CS 6301 – PROGRAMMING AND DATA STRUCTURES II

Indegree : In a directed graph , for any node v, the number of edges which have v as their terminal node is called indegree of node v.Out degree : Iin a directed graph , for any node v, the number of edges which have v as their initial node is called out degree of node v.

16. What is spanning tree? A spanning tree of a graph G is a subgraph which is basically a tree and it contains all the vertices of G containing no circuit.

17. What is a minimum spanning tree? A minimum spanning tree of an undirected graph G is a tree formed from graph

edges that connects all the vertices of G at the lowest total cost.

18. What is the difference between BFS and DFS methods?BFS DFS

5. BFS stands for Breadth First Search6. This traversal is done with the help

of queue data structures7. BFS sequence is composed of tree

edges and cross edges8. It works using one ordering

5. DFS stands for Depth First Search6. This traversal is done with the help

of stack data structures7. DFS sequence is composed of tree

edges and back edges8. It works using two ordering

16 MARKS

1. Write routines to find shortest path using Dijkstra’s algorithm.2. Write the pseudo code to find a minimum spanning tree using Kruskal’s algorithm.3. What is topological sort? Write an algorithm to perform topological sort.4. Write the procedures to perform the BFS and DFS search of a graph.5. Explain Prim’s algorithm to construct a minimum spanning tree from an undirected

graph.6. Explain Floyd’s algorithm with necessary example.7. Explain Bellman-Ford algorithm with necessary example.8. Discuss Warshall algorithm with example.

Prepared by Mrs. S.Deepajothi,AP/CSE Page 19