Question Bank For EC6301 - Object Oriented Programming and Data Structures
Question Bank For EC6301 - Object Oriented Programming and Data Structures
UNIT I
PART A
6. What is the difference between local variable and data member? [Nov-2011]
A data member belongs to an object of a class whereas local variable belongs to its
current scope.
1
A local variable is declared within the body of a function and can be used only from the
point at which it is declared to the immediately following closing brace.
A data member is declared in a class definition, but not in the body of any of the class
member functions.
Data members are accessible to all member function of the class.
7. What is the function parameter? Difference between parameter and Argument. [Nov-
2011]
A function parameter is a variable declared in the prototype or declaration of a function:
void foo[int x]; // prototype -- x is a
parameter void foo[int x] // declaration -- x
is a parameter
{
}
An argument is the value that is passed to the function in place of a parameter
10. List out the basic concepts of Object Oriented Programming. [Nov-2009]
Objects
Classes
Data Abstraction and Encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message Passing
16. Write a C++ program to check the given integer is prime or composite number. [Apr-
2010]
#include<conio.h>
#include<stdio.h>
int main[]
{
int num,d,ctr;
clrscr[];
printf["\n Enter a number="];
scanf["%d",&num];
d=1; ctr=0;
while[d<=num]
{
if[num%d==0]
ctr++;d=d+1;
}
if[ctr==2]
printf["\n %d is a prime number",num];
else
printf["\n %d is a composite number",num];
getch[];
return[0];
}
3
19. What is an identifier?
Identifiers are names for various programming elements in c++ program. such as variables,
arrays, function, structures, union, labels ect., An identifier can be Composed only of uppercase,
lower case letter, underscore and digits, but should start only with an alphabet or anunderscore.
20. What is a keyword?
Keywords are word whose meanings have been already defined in the c compiler. They are
also called as reserved words.
(ex) main(), if, else, else, if, scanf, printf, switch, for, goto, while ect.,
21. List out the benefits of oops.
Can create new programs faster because we can reuse code
Easier to create new data types
Easier memory management
Programs should be less bug-prone, as it uses a stricter syntax and type checking.
`Data hiding', the usage of data by one program part while other program parts cannot access
the data Will whiten your teeth22. List out the application of oops.
Client server computing
Simulation such as flight simulations.
Object-oriented database applications.
Artificial intelligence and expert system
Computer aided design and manufacturing systems.
35.List any four Operators that cannot be overloaded.(DEC 2010) (DEC 2009) (DEC 2011)
Class member access operator (. , .*)
Scope resolution operator (::)
Size operator ( sizeof )
Conditional operator (?:)
36.What is a Destructor? (DEC 2012)
A destructor is used to destroy the objects that have been created by a constructor. It is a
special member function whose name is same as the class and is preceded by a tilde ~ symbol.
When an object goes out from object creation, automatically destructor will be executed.
Example:
class File {
public:
~File(); //destructor declaration
};
File::~File()
close(); // destructor definition
5
37.What is the Need for initialization of object using Constructor? (DEC 2012)
If we fails to create a constructor for a class, then the compiler will create a constructor
by default in the name of class name without having any arguments at the time of
compilation and provides the initial values to its data members. So we have to initialize the
objects using constructor
cout<<"\nValues :"<<a<<"\t"<<b;
}
};
int main() {
Example Object(10,20);
//Copy Constructor
Example Object2=Object;
// Constructor invoked.
Object.Display();
Object2.Display();
// Wait For Output Screen
getch();
return 0;
6
41.Explain the functions of Default Constructor(MAY 2011)
The main function of the constructor is, if the programmer fails to create a constructor for
a class, then the compiler will create a constructor by default in the name of class name without
having any arguments at the time of compilation and provides the initial values to its data members.
Since it is created by the compiler by default, the no argument constructor is called as default
constructor.
7
UNIT II
PART A
It is new concepts which enable us to define generic classes and functions and thus
provides support for generic programming.
Catch- A catch block defined by the keyword catch catches the exception
thrown by the thrown statement in the try block and handles its appropriately.
3. What happens when a raised exception is not caught by catch block? (AUC MAY 2010)
If the type of object thrown matches the arg type in the catch statement, then
catch block is executed for handling the exception.
If they do not match the program is aborted with the help of abort() function which is
invoked by default.
When no exception is detected and thrown, the control goes to the statement
immediately after the catch block. That is the catch block is skipped.
4. Give the syntax of a pointer to a function which returns an integer and takes arguments
one of integer type and 2 of float type. What is the difference between a class and a
structure?
Exceptions are run time anomalies or unusual conditions that a program may
encounter while executing.
Like class template, we can also define function templates that could be used to
create a family of functions with different argument types.
template<class T>
//
//..
Division by zero
template<class T>
9
classclassname
//,..
catch
13. What is the difference between base class and derived class?
The biggest difference between the base class and the derived class is that the derived
class contains the data members of both the base and its own data members. The other difference
is based on the visibility modes of the data members.
14. What are the rules governing the declaration of a class of multiple inheritance?
More than one class name should be specified after the : symbol.
Visibility modes must be taken care of.
If several inheritance paths are employed for a single derived class the base class must be
appropriately declared
10
16. Define dynamic binding. APRIL AMY 2010
Dynamic binding means that the code associated with a given procedure call is not
known until the time of the call at run-time.
11
23 .Give the syntax of exception handling mechanism.
The syntax of exception handling mechanism is as follows:
try
{
---------------------
throw exception
---------------------
}
catch(type arguments)
{
---------------------
---------------------
PART B
12
UNIT III
PART-A
Structure Property
A heap is a binary tree that is completely filled, with the possible exception of the bottom level,
which is filled from left to right. Such a tree is known as a complete binary tree
3. Define Algorithm?
Algorithm is a solution to a problem independent of programming language. It consist of set of
finite steps which, when carried out for a given set of inputs, produce the corresponding output
and terminate in a finite time.
12. What are the two basic operations that access an array?
Extraction:
Extraction operation is a function that accepts an array, a ,an index,i,and
returns an element of the array.
Storing:
Storing operation accepts an array , a ,an index i , and an element x.
14
21. What is a doubly linked list?
In a simple linked list, there will be one pointer named as 'NEXT POINTER' to point the next
element, where as in a doubly linked list, there will be two pointers one to point the next
element and the other to point the previous element location.
PART B
1. Explain about Linked list, its Types, insertion and deletion routines with suitable example.
2. Explain the insertion and deletion operation in singly linked list.
3. Explain array based implementation of list with an example program.
4. Given singly linked list whose first node is pointed to by the pointer variab le C formulate an
algorithm to delete the first occurrence of X from the list and Insert the e lement X after the
position P in the list.
5. Exp lain the imp le mentation stack using linked list.
6. Write the ADT operation for insertion and deletion routine in stack.
7. Exp lain the process of postfix, prefix, infix e xpression e valuation with an examp le.
8. Give a procedure to convert an infix e xpression a+b*c+(d*e+f)* g to postfix notation.
9. Write a routine to insert an ele ment in a linked list
10. What is a queue? Write an algorithm to imp lement queue.
11. Exp lain the process of conversion from infix e xp ression to postfix using stack.
12. Write the ADT operation for insertion and deletion routine in linked lists & Queue
15
UNIT IV
PART A (2Marks)
The root of each subtree is said to be a child of r and r is the parent of each
subtree root.
4. Define leaf?
In a directed tree any node which has out degree o is called a terminal node or
a leaf.
16
10. Define Graph?
A graph G consist of a nonempty set V which is a set of nodes of the graph, a
set E which is the set of edges of the graph, and a mapping from the set for edge E to a
set of pairs of elements of V.
It can also be represented as G=(V, E).
11. Define adjacent nodes?
Any two nodes which are connected by an edge in a graph are called adjacent
nodes. For Example, if and edge xE is associated with a pair of nodes (u,v) where u, v
V, then we say that the edge x connects the nodes u and v.
12.Name the different ways of representing a graph?
a. Adjacency matrix
b. Adjacency list
13. What are the two traversal strategies used in traversing a graph?
a. Breadth first search
b. Depth first search
14. What is an acyclic graph?
A simple diagram which does not have any cycles is called an acyclic graph.
15. Give some example of NP complete problems.
Hamiltonian circuit.
Travelling salesmen problems
16.What a2r0e.W
AhVaLt tarreeesth?e algorithms used to find the minimum spanning tree?
Dijikstras algorithm
17
21. Define complete binary
tree.
It is a complete binary tree only if all levels, except possibly the last level have
the maximum number of nodes maximum.
22. Define binary search tree. Why it is preferred rather than the sorted linear array
and linked list?
Binary search tree is a binary tree in which key values of the left sub trees are lesser
than the root value and the key values of the right sub tree are always greater than the
root value.
In linear array or linked list the values are arranged in the form of increasing or
decreasing order. If we want to access any element means, we have to traverse the
entire list.
But if we use BST, the element to be accessed is greater or smaller than the root
element means we can traverse either the right or left sub tree and can access the
element irrespective of searching the entire tree.
25. What is the difference between binary tree and binary search tree?
A tree is said to be a binary tree if it A BST is binary tree in which the key values in the left sub
tree is lesser than the
18
has at most two children root and key values of the right sub tree is
greater than the root value.
4
4
3
7 8
8
7
1 1
1
26. Show the maximum number of nodes in a binary tree of height H is 2H+1 1.
Consider H = 3
= 23+1
1
= 24 1
= 15 nodes
We know that a full binary tree with height h=3 has maximum 15 nodes.
Hence proved.
27. List out the cases involved in deleting a node from a binary search tree.
Case 1: Node to be deleted is a Leaf node
Case 2: Node to be deleted has one child
Case:3: Node to be deleted has two children.
28. Write the pre-order, in-order, post-order traversal for the tree. (AUC NOV/ DEC
2010)
+
19
* +
A B * E
C D
In order traversal: (A * B) + (C * D) + E
3
8
31. Define threaded Binary Tree. (AUC NOV/
DEC
2010)
A binary tree is threaded by makin g all
7 pointers that would normally
right child
1
20
be null point to the inorder successor of the node, and all left child pointers that would
normally be null point to the inorder predecessor of the node.
32. Write the advantages of threaded binary tree. (AUC NOV/ DEC2009)1.
By doing threading we avoid the recursive method of traversing a Tree , which makes use of
stack and consumes a lot of memory and time.
2. The node can keep record of its root
33. Write an algorithm to declare nodes of a tree structure. (AUC APR / MAY
2010)
Struct tree node
* +
A B * EC D
PART B
1. Exp la in the operations of insertion of nodes into and deletion of nodes from, a binary search tree
with code.
2. Narrate insertion deletion with example.
3. Give the analysis of insertion and de letion operations of nodes in binary search tree.
4. Draw the binary search tree for the fo llo wing input list 60, 25,75,15,50,66,33,44. Trace an
algorithm to de lete the nodes 25, 75, 44 from the tree.
5. Exp la in the operations of insertion of nodes into and deletion of nodes from, a binary search tree
with code.
6. Explain the two applications of trees with a neat example.
7. How do you insert an e lement in a binary search tree?
8. What are the graph traversal methods? Exp lain it with e xamp le.
9. Give an algorithm to find minimum Spanning tree, explain it with suitab le exa mple.
10. Write an algorithm for find ing minimum spanning tree and exp lain app lica tion, illustrate the
algorithm with typ ica l data of yours own exa mp le.
11. Exp lain the algorithm for depth first search and breadth first search with the fo llowing graph
12. Explain connected component.
21
UNIT V
PART A
If we want the elements in the more typical increasing sorted order, we can
change the ordering property so that the parent has a larger key than the child. it is called max
heap.
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.
Mergesort
5. What are the three cases that arise during the left to right scan in quicksort?
I and j cross each other
I and j do not cross each other
I and j points the same position
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.
It is a basic external sorting in which there are two inputs and two outputs tapes.
We read as many records as possible and sort them. Writing the result to some tapes. This
seems like the best approach possible until one realizes that as soon as the first 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.
Sorting is the process of arranging the given items in a logical order. Sorting is an
example where the analysis can be precisely performed.
The mergesort algorithm is a classic divide and conquer strategy. The problem is
divided into two arrays and merged into single array
23