valliammai engineering college semester/cs6301-programming and...valliammai engineering college ......

21
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK VI SEMESTER CS6301-PROGRAMMING DATASTRUCTURE II Regulation 2013 Academic Year 2017 18 Prepared by Ms. R.Thenmozhi, Assistant Professor (Sel.G)/IT Ms. K.Mohanambal, Assistant Professor (O.G)/IT

Upload: trinhcong

Post on 21-Mar-2018

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

VALLIAMMAI ENGINEERING COLLEGE

SRM Nagar, Kattankulathur – 603 203

DEPARTMENT OF INFORMATION TECHNOLOGY

QUESTION BANK

VI SEMESTER

CS6301-PROGRAMMING DATASTRUCTURE II

Regulation – 2013

Academic Year 2017 – 18

Prepared by

Ms. R.Thenmozhi, Assistant Professor (Sel.G)/IT

Ms. K.Mohanambal, Assistant Professor (O.G)/IT

Page 2: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur – 603 203.

DEPARTMENT OF INFORMATION TECHNOLOGY

QUESTION BANK SUBJECT : Programming and Data Structures II

SEM / YEAR: III Sem/ II Year

UNIT 1 – OBJECT ORIENTED PROGRAMMING FUNDAMENTALS

Be familiar with the C++ concepts of abstraction, encapsulation, constructor, polymorphism, overloading and

Inheritance.

C++ Programming features – Data Abstraction – Encapsulation – class – object – constructors – static members – constant members – member functions – pointers – references – Role of this pointer – Storage classes – function as

arguments.

PART – A

Q.No. Questions

BT

Level Competence

1 Define Data Abstraction. BTL-1 Remembering

2 What is the use of “this” pointer? BTL-1 Remembering

3 Which is used for achieving data Hiding in C++? BTL-1 Remembering

4 List the various storage classes available in C++. BTL-1 Remembering

5 What is the significance of static data & static member function in

object oriented programming?

BTL-1 Remembering

6 Define Encapsulation. BTL-1 Remembering

7 Give the significance of declaring a member of a class static. BTL-2 Understanding

8 Give the characteristics of the constructor function. BTL-2 Understanding

9 Differentiate between realloc () and free (). BTL-2 Understanding

10 Give the features of object oriented C++ programming. BTL-2 Understanding

11 Show the working of copy constructor. BTL-3 Applying

12 What is a default constructor? Illustrate. BTL-3 Applying

13 What are objects? Illustrate with an example. BTL-3 Applying

14 Point out a when a function will be made online? BTL-4 Analysing

15 What are pointers? Point out the advantages of using pointers in

programming.

BTL-4 Analysing

16 Analyze and define operator overloading with an example. BTL-4 Analysing

17 Compare the working of structures and classes in C++. BTL-5 Evaluating

18 Summarize the working of destructors with an example. BTL-5 Evaluating

Page 3: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

19 Develop the member function to find the greater of two numbers

using “this” pointer.

BTL-6 Creating

20 Develop a simple C++ program using a class concept. BTL-6 Creating

PART – B

1 (i) List the types of constructors with examples. (6)

(ii) Describe the features of C++ programming Language . (7)

BTL-1 Remembering

2

(i) Describe the ways in which member functions of class can be

defined & called using a suitable example. (7)

(ii) Describe with an example the use of static members. (6)

BTL-1 Remembering

3

(i) What are the differences between pointer to constant & constant to

pointer? Give an example program & explain it. (7)

(ii) Describe the role of “this” pointer with an suitable program. (6)

BTL-1 Remembering

4 Explain the different types of storage classes of C++ using suitable

examples. (13)

BTL-1 Remembering

5 Discuss about the need to use the default arguments with an example

program. (13)

BTL-2 Understanding

6 (i) Describe about the copy constructor with an example. (7)

(ii) Differentiate between constructor and destructor. (6)

BTL-2 Understanding

7

Describe briefly about the following term with an suitable example:

(i) Objects. (3)

(ii) Classes. (3)

(iii) Polymorphism. (3)

(iv) Methods and message passing. (4)

BTL-2 Understanding

8

(i) Illustrate and write a C++ program to check how many instances of

a class are created using the static member function. (7)

(ii) Illustrate and write a C++ program that prints the factorial of a

given number using a copy constructor and destructor member

function. (6)

BTL-3 Applying

9

(i) How would you declare function to be a constant in C++? What are

the properties of such function? Demonstrate with a program. (7)

(ii) Demonstrate the mechanism for accessing data members and

member functions in the following cases. (6)

a. Inside the main program.

b. Inside a member function of the same class

c. Inside a member function of another class

BTL-3 Applying

10 Explain about constructors and destructors with example program. (13) BTL-4 Analysing

Page 4: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

11

(i)What do you mean by static member function? Explain in detail with an

example. (7)

(ii) Point out a detailed note on const member function. (6)

BTL-4 Analysing

12

(i) Pointout the advantages of OOP? (3)

(ii)Explain in detail about const,volatile and static functions. (10)

BTL-4 Analysing

13

Summarize the various function call mechanisms with suitable

programming example. (13)

BTL-5 Evaluating

14

Develop an object oriented program in C++ to prepare the mark sheet

of a university exam with the following items read from the keyboard.

Name of the student, Rollno, Subjectname, Subjectcode,

Internalmarks, and External marks.

Design a base class consisting of the data members such as name of the

student, roll number and subject code, internal marks and external

marks. The program should be able to do the following tasks” Build a

table, Display the table, Insert into the table, Delete from the table,

Edit entry and search for a record that is needed to be printed. (13)

BTL-6 Creating

PART - C

1

Define a class time with string containing seconds elapsed till midnight

(12.00AM) as a single data member. Write AddTime function which

adds two different Time objects and returns a new Time object. Write a

Display Normal function which converts the time in seconds and

display in a normal fashion HH:MM:SS. (15)

BTL-6 Creating

2

(i) Write a program in C++ that contains a function which takes an

integer array as argument and returns the sum of the array elements.(7)

(ii)Construct a class by name ‘Box’ with a constructor method and

volume method. Constructor initializes the length, breath, and height

of the box objects. Volume method computes the volume of the box

using the formula length*breath*height. Create three box objects and

compute their volume by declaring a pointer to the box class. (8)

BTL-5 Evaluating

3

(i)Write a C++ Program to find the smallest in an array of ‘n’ elements

using pointers. (7)

(ii)Write a C++ program to sort a list of strings using pointers. (8)

BTL-6 Creating

Page 5: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

4

Consider an example of declaring the examination result. Design three

classes: student, Exam and result. The “student” class has data

members such as that representing roll number, names etc.create the

class “Exam” by inheriting the “student” class. The “Exam” class adds

data members representing the marks scored in six subjects. Write an

interactive program to model this relationship. what type of inheritance

this model belongs to? (15)

BTL-5 Evaluating

UNIT 2 – OBJECT ORIENTED PROGRAMMING CONCEPTS

String Handling – Copy Constructor – Polymorphism – compile time and run time polymorphisms – function overloading – operators overloading – dynamic memory allocation – Nested classes - Inheritance – virtual functions

PART – A

Q.No. Question BT

Level Competence

1 List any four operators of C++ that cannot be overloaded. BTL-1

Remembering

2 What are pure virtual functions? Give example BTL-1 Remembering

3 Tell how the ‘C’ string differs from a C++ type string? BTL-1 Remembering

4 What is dynamic initialization of objects? BTL-1 Remembering

5 Define copy constructor & its use. BTL-1 Remembering

6 State the uses of virtual functions. BTL-1 Remembering

7 Distinguish the term overloading &overriding. BTL-2 Understanding

8 Summarize the different operators of C++ that can be overloaded.

Give an example

BTL-2 Understanding

9 Differentiate virtual function and pure virtual function. BTL-2 Understanding

10 Define multiple inheritance.Give example. BTL-2 Understanding

11 What is Inheritance? Illustrate. BTL-3 Applying

12 Examine how one invoke a constructor function. BTL-3 Applying

13 Illustrate the working of type conversion with an example. BTL-3 Applying

14 Compare multiple and inheritance with example. BTL-4 Analysing

15 Differentiate Operator overloading and function overloading. BTL-4 Analysing

16 Compare Run time polymorphism and Compile time polymorphism. BTL-4 Analysing

17 Summarize the working of inline functions with an example. BTL-5 Evaluating

18 Compare private and protected visibility. BTL-5 Evaluating

19 Develop a simple C++ program using inline function. BTL-6 Creating

Page 6: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

20 Develop and write the syntax to dynamically allocate memory

through constructor.

BTL-6 Creating

PART – B

1

(i) Describe how memory is dynamically allocated & recovered in C++?

Illustrate with an example program. (7)

(ii) List the rules associated with operator overloading? What are the

operators that cannot be overloaded? Write a program to overload any one of

the binary operator. (6)

BTL-1 Remembering

2

(i) Define a class shape with constructor, destructor & pure virtual

functions GetArea (), GetPrim () &Draw (). Derive class circle &

Rectangle from shape. Derive another class square from rectangle.

Implement this hierarchy with essential functions & write a main. (7)

(ii) Define a class area to identify the area of square & rectangle using

constructor & destructor. Use the parameter length (l) & breadth (b) for the

constructor functions. (6)

BTL-1 Remembering

3 With suitable C++ program describe how the polymorphism is

achieved at compile time & run time. (13)

BTL-1 Remembering

4

Describe about the following concepts with their syntax.

(i) Copy constructor. (3)

(ii) Virtual functions. (3)

(iii) Pure virtual functions. (3)

(iv) Inline functions. (4)

BTL-1 Remembering

5

(i) Describe and Write a C++ program to overload the increment

operator with prefix & postfix forms. (7)

(ii) Distinguish the term overloading & overriding. (6)

BTL-2 Understanding

6 Discuss the types of inheritance in detail. (13) BTL-2 Understanding

7

Assume the classes Person Student and PartTimeStudent are inherited from

one another. Describe classes with suitable data members(common and

special attributes)and methods using C++ program to demonstrate the types

of inheritance. (13)

BTL-2 Understanding

8

(i) Write a program to illustrate dynamic initialization of objects. (6)

(ii)Write a program to illustrate the process of multilevel-multiple

inheritance concepts of C++ language. (7)

BTL-3 Applying

9 What is meant by function overloading? Write a C++ program to

illustrate the concept of function overloading. (13)

BTL-3 Applying

Page 7: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

10

(i)Analyze and Write a C++ program using operator overloading to add

two time values in the format HH:MM:SS to the resulting time along

with rounding off when 24 hours is reached. A time class is created and

operator +is overloaded to add the two time class objects. (7)

(ii)Write a C++ program to explain unary and binary operator

overloading. (6)

BTL-4 Analysing

11 Explain overloading the assignment operator with examples. (13) BTL-4 Analysing

12

Explain the following string operations using C++ program.(i)Finding the

length of string (ii)finding the substring from the string.(iii)replace a given

substring in a string (iv)concatenate two strings (v)compare two strings

(vi)insert a substring in a given string. (13)

BTL-4 Analysing

13

(i) Explain and Write a program to perform string copy operation using

dynamic constructor. (6)

(ii) Consider the following arithmetic operations.

C=2+B & k=S-T where B,C,K,S &T are the objects of a class called

‘ID Array’ Write a program to perform these operations by overloading

the + and – operators appropriately. (7)

BTL-5 Evaluating

14

Develop a program in C++ to demonstrate runtime polymorphism in

hierarchy of classes on a member function that performs dynamic

casting. (13)

BTL-6 Creating

PART - C

1.

Write a C++ program to create a base class called house. There are

two classes called door and window available. The house class has

members which provide information related to the area of construction,

doors and windows details. It delegates responsibility of computing the

cost of doors and window construction to door and window classes

respectively. Write a C++ program to model the above relationship and

find the cost of constructing the house. (15)

BTL-5 Evaluating

2.

Consider an example of book shop which sells book and video tapes.

These two classes are inherited from the base class called media. The

media class has command data members such as title and publication.

The book class has data members for storing number of pages in a

book and the tape class has the playing time in a tape. Each class will

have member function such as read() and show() in the base class,

these members have to be defined as virtual functions, Write a program

which models the class hierarchy for book shop and process objects of

these classes using pointers to the class. (15)

BTL-6 Creating

Page 8: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

3

The manager class is derived from Employee class.Use C++ virtual function

to calculate salary of Employee/Manager class.Increments for employees

differ based on their category.Assume suitable common and special attributes

for the classes.Implement this scenario using C++ code to prepare the

monthly and annual payment of each employee category. (15)

BTL-6 Creating

4

Write a C++ program to calculate the volume of cube,cylinder and

rectangular box. Summerize the concept of function overloading and

write a main class to call these functions. (15)

BTL-5 Evaluating

UNIT 3 – C++ PROGRAMMING ADVANCED FEATURES

Abstract class – Exception handling – Standard libraries – Generic Programming – templates – class template – function template – STL – containers – iterators – function adaptors – allocators - Parameterizing the class – File

handling concepts.

PART – A

Q.No Question BT Level Competence

1 When do we use multiple catch handle BTL-1 Remembering

2 What is the significance of Iterators? BTL-1 Remembering

3 List out the types of containers. BTL-1 Remembering

4 When do we use multiple catch handlers? BTL-1 Remembering

5 What is an abstract class? Give example. BTL-1 Remembering

6 What is a function adaptor? BTL-1 Remembering

7 Distinguish the term template class & class template. BTL-2 Understanding

8 Give the various file stream classes needed for file manipulation. BTL-2 Understanding

9 Summarize the use of abstract base class with an example. BTL-2 Understanding

10 Give the meaning of the flag ios::out. BTL-2 Understanding

11 Illustrate how overriding can be prevented. BTL-3 Applying

12 What happens when a raised exception is not caught by catch block?

Summarize

BTL-3 Applying

13 Demonstrate the use of an exception with an example. BTL-3 Applying

14 Compare overloaded functions versus function Template. BTL-4 Analysing

15 Point out the uses of templates in C++ programming. BTL-4 Analysing

16 Point out the advantages of using streams in a program. BTL-4 Analysing

17 Is Abstract base class, used to create objects? Justify your answer in

brief.

BTL-5 Evaluating

18 Compare the working of function and class template. BTL-5 Evaluating

19 Develop a simple C++ program to demonstrate exception handling. BTL-6 Creating

Page 9: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

20 Develop a simple C++ program to demonstrate a abstract class

concept.

BTL-6 Creating

PART – B

1

(i)Write C++ file handling routine to copy one content of file into another file. (7)

(ii)Explain the use of exception handling in C++ with suitable example. (6)

BTL-1 Remembering

2 (i)Write short notes on C++ exception handling. (7)

(ii) Write a C++ program to write a set of characters to a file. (6) BTL-1 Remembering

3 (i)Define STL. Explain its key components and types. (5)

(ii)Write C++ code using function template to sort the items of an array. (8) BTL-1 Remembering

4

(i)Describe the components of STL. (6)

(ii)Describe and Write a class template to represent a stack of any

possible data types. (7)

BTL-1 Remembering

5

(i) Describe and write a program to implement stack operations using

class template. (7)

(ii) Describe and Write a template function to sort the elements of an

array. (3)

(iii)What is an exception? Explain how the control is transferred and

handled in C++ programs. (3)

BTL-2 Understanding

6

Discuss in detail about exception handling constructs and write a

program to illustrate divide by zero exception. (13)

BTL-2 Understanding

7 (i) Discuss about class template with suitable example. (7)

(ii)Discuss about Abstract classes with suitable example. (6)

BTL-2 Understanding

8

(i) Write a class template to represent a queue of any possible data

type with illustration. (7)

(ii) Illustrate about how exceptions are handled using multiple catch

handlers. (6)

BTL-3 Applying

9

Illustrate the working of the following concepts with an example

(i)Containers. (3)

(ii)Function adapters. (3)

(iii)Iterators. (3)

(iv Allocators. (4)

BTL-3 Applying

10

(i) Explain and Write a program to illustrate the concept of re-

throwing an exception. (7)

(ii) Explain and Write a program to read a string to store it in a file

and read the same string from the file to display it on the output

device. (6)

BTL-4 Analysing

11 Explain in detail about different STL containers. (13) BTL-4 Analysing

Page 10: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

12 Explain various file stream classes needed for file manipulations. (13) BTL-4 Analysing

13

(i) Write a function template to find the minimum value contained in

an array . (7)

(ii) Write a C++ program that reads a text file & creates another file

that is identical except that every sequence of consecutive blank space

is replaced by a single space. (6)

BTL-5 Evaluating

14

(i) Develop a program to write the text in a file. Read the text from the

file, from end of the file. Display the contents of file in reverse order.

Append the contents to the existing file. (7)

(ii) Develop a C++ program using exception handling concept. (6)

BTL-6 Creating

PART - C

1

What are abstract classes? Write a program having student as an

abstract class and create many derived classes such as engineering,

science, medical etc., from the student class. Create their object and

process them. (15)

BTL-6 Creating

2

Write a program in C++ using a random access file function to create

a database of student’s information such as name, roll no,sex,address

and the program should have the following facilities (15)

(i) To display the entire database

(ii) To display only a particular record

(iii)To update a record

(iv) To delete a record

BTL-5 Evaluating

3 Prepare a C++ generic function with multiple parameters that performs

recursive binary search on a linear array. (15) BTL-6 Creating

4

Write a C++ Program to compute the square root of a number .The

input value must be tested for validity .If it negative the user defined

function mysqrt() should raise and exception. (15)

BTL-5 Evaluating

UNIT 4 – ADVANCED NON-LINEAR DATA STRUCTURES AVL trees – B-Trees – Red-Black trees – Splay trees – Binomial Heaps – Fibonacci Heaps – Disjoint Sets –

Amortized Analysis – accounting method – potential method – aggregate analysis.

PART – A

Q.No Question BT Level Competence

1 Define Fibonacci Heaps BTL-1 Remembering

2 Write a note on amortized analysis. BTL-1 Remembering

3 Define Balance Factor of AVL Tree. BTL-1 Remembering

Page 11: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

4 What are splay trees? BTL-1 Remembering

5 List out the various operations that can be performed on B-trees BTL-1 Remembering

6 What are the various types of rotations in AVL tree during the

insertion of a node?

BTL-1 Remembering

7 Differentiate Fibonacci heaps and binomial heaps? BTL-2 Understanding

8 Give the properties of Red Black Tree. BTL-2 Understanding

9 What are Red black trees? Give an example. BTL-2 Understanding

10 Predict a binary tree for the expression A*B-(C+D)*(P/Q). BTL-2 Understanding

11 What is amortized analysis? Show that the stack operation

MULTIPOP costs O(1) amortized time

BTL-3 Applying

12 Show the result of inserting 2;1;4;5;9;3;6;7 into an initially empty

AVL tree.

BTL-3 Applying

13 Illustrate aggregate analysis with an example. BTL-3 Applying

14 Point out the applications of trees. BTL-4 Analysing

15 Compare AVL tree and B-tree. BTL-4 Analysing

16 Analyze and write a Pseudo code to find the smallest element in the

binary search tree.

BTL-4 Analysing

17 Summarize the advantages of using Fibonacci heaps. BTL-5 Evaluating

18 Compare AVL tree and Binary search tree. BTL-5 Evaluating

19 Develop an algorithm for inserting an element in a binary search tree. BTL-6 Creating

20 Develop an algorithm for simple disjoint set Find () operation. BTL-6 Creating

PART – B

1

(i)What is a red-Black tree? Mention the properties that a Red-Black

tree holds. (7)

(ii)Define AVL tree & starting with an empty AVL search tree, Insert

the following elements in the given order 35,45,65,55,75,15,25 (6)

BTL-1 Remembering

2

(i) Describe the AVL rotations with suitable example . (7)

(ii) Describe in detail the binary heaps. Construct a min heap tree for

the following: (6)

5,2,6,7,1,3,8,9,4

BTL-1 Remembering

3

(i) Delete AVL tree and starting with an empty AVL search tree,

insert the following elements in the given order: 2,1,4,5,9,3,6,7 (7)

(ii) Construct a B-tree with order m=3 for the key values

2,3,7,9,5,6,4,8,1 & delete the values 4 &6.Show the tree in performing

all operations . (6)

BTL-1 Remembering

Page 12: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

4

Describe insertion and deletion operations on Fibonacci heaps. Construct

Fibonacci heaps for the following set of elements 10, 11, 5, 35, 8, 4, 2, 3,

77,1, 45. (13)

BTL-1 Remembering

5

(i)Perform the splaying operation on a binary search tree obtained by

inserting the key values 1,2,3,4,5,6,7,8 in this order into an initially

empty tree. Describe and Write the code to do the same (splay &

insert) (7)

(ii) On an initially empty binomial heap, carry out the following

sequence of operations

Insert(27) Insert(17) insert(19) insert(20) insert(24) insert(12)

insert(11) insert(10) insert(14) insert(18) deletemin. After each

operation Describe and draw the resulting structure of the binomial

heap. (6)

BTL-2 Understanding

6

(i) Describe the properties of binary heaps with an example. (7)

(ii) Describe about Amortized Analysis in detail. (6)

BTL-2 Understanding

7

(i)Draw B-tree of order m=5 for the keys{K,O,S,V,M,F,B,G,T,U,W } (7)

(ii)Delete the keys K and G in order. (3)

(iii) Justify the number of splits needed for insert/delete with proper reasons.

(3)

BTL-2 Understanding

8 Illustrate the construction of Binomial Heaps & its operations with a

suitable example. (13)

BTL-3 Applying

9

(i) Show the result of inserting 43, 11, 69, 72&30 into an initially

empty AVL tree. Show the results of deleting the nodes 11 & 72 one

after the other of the constructed tree. (7)

(ii) Illustrate the concept of potential method and accounting method

with an example. (6)

BTL-3 Applying

10 (i) Explain about aggregate analysis with an example. (7)

(ii)Explain about the smart union algorithms with suitable example.(6)

BTL-4 Analysing

Page 13: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

11

(i) Merge the given Binomial heaps.Explain the procedure for merge

operation. (5+3)

H1:

H2:

(ii)Delete three elements from the merged Binomial Queue. (5)

BTL-4 Analysing

12

Starting from an empty height balanced tree insert the following data

one-by-one in the sequence as given and ensure that insertion of each

node results a height balanced tree. Explain and write the algorithm

for balancing the tree. (13)

8,9,10,2,1,5,6,4,7,11,12,3

BTL-4 Analysing

13

(i) Consider the following list of numbers

14,15,4,9,7,18,3,5,16,4,20,17,9,14,5

Using that construct a binary search tree. (7)

(ii)Summarize the working of Find () operation using a path

compression. (6)

BTL-5 Evaluating

14

(i)Create a max heap tree for the numbers(in order):

95,85,45,75,25,35,15,55 and then (7)

a. insert 17

b. insert 100

c. delete 100

(ii)Formulate algorithms to perform insertion and deletion in a binary

search tree. (6)

BTL-6 Creating

PART - C

1

(i) Construct an AVL tree with values F,S,Q,K,C,L,H,T,V,M,R into

an initially empty tree. Write the algorithm for inserting into an AVL

tree. (10)

(ii)Write a note on general trees with an example. (5)

BTL-6 Creating

3 6

1

4

1

1

1

9

1

0

4 8

2

7

5 1

2 2

1

Page 14: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

2

Write a program to accept keys from the user one at time. Build them

into an AVL tree and write out the tree at each stage. Also write a

function to delete a node from AVL tree. (15)

BTL-5 Evaluating

3

Assume the following keys form the Binary search

tree{50,30,60,40,35,80,90} Analyze the time complexity involved in

searching the keys 90 and then 80,when the given BST is converted into

AVL or Splay tree. Formulate the suitable tree data structure for representing

this data and justify your answer with valid reasons. (15)

BTL-6 Creating

4

(i) Prepare the function to insert and delete a node from a binary

search tree. (8)

(ii) Make a Binary search tree for the following sequence of numbers:

45,36,76,23,89,115,98,39,41,56,69,48

Traverse the tree in Preorder, Inorder, Postorder. (7)

BTL-5 Evaluating

UNIT 5 – GRAPHS

Representation of Graphs – Breadth-first search – Depth-first search – Topological sort – Minimum Spanning Trees – Kruskal and Prim algorithm – Shortest path algorithm – Dijkstra’s algorithm – Bellman-Ford algorithm –

Floyd – Warshall algorithm

PART – A

Q.No

.

Question BT Level Competence

1 Define minimum spanning tree for a graph. BTL-1 Remembering

2 State the principle of Topological Sorting. BTL-1 Remembering

3 What is the minimum number of spanning trees possible for a

complete graph with ‘n’ vertices?

BTL-1 Remembering

4 What is the principle behind Bellman-Ford algorithm to delete the

negative weight cycles?

BTL-1 Remembering

5 List the drawbacks of Floyd-Warshall algorithm. BTL-1 Remembering

6 Write procedure for Depth First search algorithm. BTL-1 Remembering

7 Give the way in which a graph can be represented with an example. BTL-2 Understanding

8 Discuss about Undirected graph in a very short way. BTL-2 Understanding

9 Give any 2 applications of graph. BTL-2 Understanding

10 What is an articulation point? Give a suitable example. BTL-2 Understanding

Page 15: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

11

Illustrate the Breadth First Search for the following instance of Graph

BTL-3 Applying

12 Show that “Number of vertices ,V(g), in rank group g>0 is at most

N/2F(g-1)

BTL-3 Applying

13 Illustrate the working of Euler’s circuit with an example. BTL-3 Applying

14 Compare the graph traversal methods. BTL-4 Analysing

15

Analyze and Write the adjacency matrix for the following graph.

BTL-4 Analysing

16 Differentiate indegree and outdegree of a graph. BTL-4 Analysing

17 Does either prim’s or kruskal’s algorithm work if there are negative

edge weights? Justify your answer.

BTL-5 Evaluating

18 Summarize the working of topological sort in a short and precise way. BTL-5 Evaluating

19 Design a looping graph and give the definition. BTL-6 Creating

20 Design a bi-connected graph and give the definition.

BTL-6 Creating

PART – B

1

Describe Prim’s&Kruskal’s algorithm in detail. Find the minimum

spanning tree for the following graph using any one of the algorithm.

(13)

BTL-1 Remembering

A

A C

A

A

D

A

A

B

A

A F

B

A

A

E

B

A

A

Page 16: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

2 Describe and Explain the Dijksra’s algorithm for finding the shortest

path with a sample graph. (13)

BTL-1 Remembering

3

Show the minimum spanning tree of a given Graph using

Kruskal’saalgorithm.Write Kruskal’s MST algorithm. (10+3)

BTL-1 Remembering

3

c b 3

4

4

4

2

11 d

B A

A

a

2

4

e

B

A

A

1 2

4

g

B A

A

f

B A

A

5

4

3

4

4

4

Fig(1)

0

7

1

5 6

4

3 2

8

8

4

1

1

1 2

8 7

9

1

0

1

4

4

2

6

7

Page 17: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

4

(i) What are the different ways of representing a graph? Represent the

following graph using those ways. (7)

(ii)Describe and Show the result of running BFS and DFS on the

directed graph given above. (6)

BTL-1 Remembering

5

(i) Describe Topological sort? Write a Pseudo code to perform a

topological sort. (7)

(ii)Describe and explain Kruskal’s algorithm to construct minimum

spanning tree in an undirected graph. (6)

BTL-2 Understanding

6

Describe and explain prim’s algorithm to find the minimum spanning

tree of the following graph. write the algorithm. (13)

1

4

3 3 5

4 2

4 6

BTL-2 Understanding

F B A

E D C

A

F

F

F

F

F

C

F

F

F

F

F

D

F

F

F

F

F

B

F

F

F

F

F

F

F

F

F

F

F

E

F

F

F

F

F

Page 18: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

7

(i) Describe and Write an algorithm to determine the biconnected

components in the given graph. (7)

(ii) Interpret the biconnected components from the following graph.(6)

BTL-2 Understanding

8 Examine how transitive closure of a graph can be found using Warshalls

algorithm. (13) BTL-3 Applying

9

(i)Illustrate the Dijkstra’s algorithm for finding the shortest path with

the following graph . (7)

(ii) Illustrate the comparison of Floyd’s algorithm with Dijkstra’s

algorithm. (6)

BTL-3 Applying

10

(i) Explain any two applications of depth-first search. (7)

(ii)Explain briefly about single shortest path algorithm with an

example. (6)

BTL-4 Analysing

11

(i) Explain and write a pseudo code to find a minimum spanning tree

using kruskal’s algorithm. (7)

(ii)Write routines to find shortest path using Dijkstra’s algorithm. (6)

BTL-4 Analysing

2

5

1

6

7

3

4 10

0

8

9

1

5

2

4

3 10

100

30

10

20

60

Page 19: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

12

Consider the following graph.Determine the shortest distance to all other

nodes using Dijikstra’s algorithm Write Procedure. (10+3)

BTL-4 Analysing

13

(i) Explain in detail about bi connectivity. (7)

(ii) Consider the following specification of a graph G

V(G)={1 , 2, 3, 4}

E(G)={(1, 2),(1, 3),(3, 3),(3, 4),(4, 1)}

1. Draw an undirected graph.

2. Draw its adjacency matrix. (6)

BTL-5 Evaluating

14 Prepare the pseudocodes of the different graph traversal methods

and demonstrate with an example. (13)

BTL-6 Creating

PART - C

1

(i) Create an algorithm for breadth first search on a graph & give the

nodes of the graph ‘G’ given in the fig(1). based on the algorithm. (8)

(ii) Using Dijiktra’s algorithm, find the shortest path from the source to

all other nodes of the graph ‘G’ given in fig(2). (7)

BTL-6 Creating

2 3

1

0

4

2 2

2

2

4

6

9

6

2 8

6

Page 20: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

fig(1)

fig(2)

2

(i) Find the Shortest weighted path from A to all other vertices for the

graph in given below figure. (8)

(ii) Find the shortest weighted path from B to all other vertices for the

graph in the given below figure. (7)

BTL-5 Evaluating

V

1 A

V3

V6

B A

A

V4

B A

A

V2

V7

B A

A

V5

B A

A

4

5

4

2

4

1

4

1

4

3

2

4

10

6

4

8

4

2

C

F A B E

D

G

B

A

A

A

D

C

B A

A

G

B A

A

F

B A

A

E

B A

A

5

2

4

3

4

2

1

4

6

3

7

4

1

1

4

7

4

2

1

Page 21: VALLIAMMAI ENGINEERING COLLEGE Semester/CS6301-Programming and...VALLIAMMAI ENGINEERING COLLEGE ... Illustrate and write a C++ program that prints the factorial of a given number using

3

Using Dijkstra’s algorithm to find the shortest path from the source node

A. (15)

BTL-5 Evaluating

4

(i)Prepare the pseudo code to find a minimum spanning tree using

kruskal’s algorithm. (7)

(ii)Find the topological ordering of the below graph. (8)

BTL-6 Creating

A

e c

b

d

f

g