Sie sind auf Seite 1von 8

EC6301 Object Oriented Programming and Data Structures

ECE - SEMESTER 03

TWO MARK QUESTION BANK


1. Define Constructor. List the type of constructor? (MAY /JUNE 2016)
A constructor is a special kind of member function that initializes an instance of
its class. A constructor has the same name as the class and no return value.
The different types of constructor are,
i) Default Constructor
ii) Parameterized Constructor
iii) Copy Constructor
2. List the operator that cannot be overloaded. (MAY /JUNE 2016)
?: (conditional)
. ( member selection)
.* (member selection with pointer-to-member)
:: (scope resolution)
sizeof (object size information)
typeid (object type information)
3. Write a simple C++ program to demonstrate the virtual functions. (MAY /JUNE 2016)
class Base
{
public:
virtual void show()
{
cout << "Base class";
}};
class Derived:public Base
{
public:
void show()
{
cout << "Derived Class";
}
}
int main()
{
Base* b;
Derived d;
b = &d;
b->show();
}

4. State about cast operator. (MAY /JUNE 2016)


A cast is a special operator that forces one data type to be converted into another.
As an operator, a cast is unary and has the same precedence as any other unary operator.
5. Convert the infix expression a+b*c+(d*e+f)*g into postfix. (MAY /JUNE 2016)
Prepared By - D. NAVIS
NAYAGAM

EC6301 Object Oriented Programming and Data Structures


ECE - SEMESTER 03

abc*+de*f+g*+
6. Define sentinel nodes, header node and tail node (MAY /JUNE 2016)
The first node in the list is referred to by a reference head node. The last node in
the list is optionally referred to by a reference tail node A sentinel node is a special node
which does not contain an element of the sequence. Sentinel nodes are useful to eliminate
some special cases that would otherwise arise when performing operations at the
beginning and end of the linked list.
7. Draw the expression tree for (a+b*c) + ((d*e+f) *g) (MAY /JUNE 2016)

8. What do you mean by articulation points? (MAY /JUNE 2016)


A vertex in an undirected connected graph is an articulation point (or) cut vertex if
removing it disconnects the graph. Articulation points when removed would split the
connected network into two or more disconnected components.
9. List the advantages and disadvantages of quick sort. (MAY /JUNE 2016)
Advantages of Quick sort are the efficient average case compared to any other sorting
algorithm, as well as the elegant recursive definition, and the popularity due to its high
efficiency.
Disadvantages include the difficulty of implementing the partitioning algorithm and
the average efficiency for the worst case scenario, which is not offset by the difficult
implementation.
10. Which search is faster and why? (MAY /JUNE 2016)
Binary search is faster for sorted elements. The time complexity for binary search
is O(log N) which is quite efficient than linear search which takes O(N)
11. Write a C++ code to swap values of two variable using reference variables in function.
(NOV/DEC 2014)

Prepared By - D. NAVIS
NAYAGAM

EC6301 Object Oriented Programming and Data Structures


ECE - SEMESTER 03

#include<iostream.h>
#include<conio.h>
void swap (int &a, int &b)
{
/* &a and &b are reference variables */
int temp;
temp=a;
a=b;
b=temp;
}
main()
{
clrscr();
int i=5,j=10;
cout<<"Before swapping I = "<<i<<" J = "<<j<<endl;
swap(i,j);
cout<<"After swapping I = "<<i<<" J = "<<j<<endl;
}
12. Write a C++ code to display pen object instantiated and pen object destroyed when
class for pen constructor and destructor are called. (NOV/DEC 2014)
class Pen
{
Pen()
{
cout << "pen object instantiated";
}
~Pen()
{
cout << "pen object destroyed";
}
};
int main()
{
Pen obj1;
}
13. Write a simple C++ code to show the usage of this pointer in C++.(NOV/DEC 2014)
#include<iostream>
using namespace std;
/* local variable is same as a member's name */
class Test
Prepared By - D. NAVIS
NAYAGAM

EC6301 Object Oriented Programming and Data Structures


ECE - SEMESTER 03

{
private:
int x;
public:
void setX (int x)
{
// The 'this' pointer is used to retrieve the object's x
// hidden by the local variable 'x'
this->x = x;
}
};
int main()
{
Test obj;
int x = 20;
obj.setX(x);
return 0;
}
14. Evaluate the value of expression 53 + 82 - * using stack (NOV/DEC 2014)

Prepared By - D. NAVIS
NAYAGAM

EC6301 Object Oriented Programming and Data Structures


ECE - SEMESTER 03

Prepared By - D. NAVIS
NAYAGAM

EC6301 Object Oriented Programming and Data Structures


ECE - SEMESTER 03

15. Find the maximum number of nodes in complete binary tree if d is the depth (NOV/DEC
2014)

2d 1
16. Write short notes on connected components (NOV/DEC 2014)
In graph theory, a connected component of an undirected graph is a sub-graph in
which any two vertices are connected to each other by paths, and which is connected to
no additional vertices in the super-graph.
17. Give the representation of a network of cities as weighted graph? (NOV/DEC 2014)

18. How to perform union operation? (NOV/DEC 2014)


Union(u,v) merges the sets containing the canonical elements u and v. To effect a
union(u,v), we combine the two trees with roots u and v by making u a child of v or viceversa.
19. What is the time complexity of quick sort and binary search? (NOV/DEC 2014)
Algorithm
Time Complexity
Best
Average
Worst
Quick-sort
(n log(n)) (n log(n)) O(n^2)
Binary Search
O (1)
O (log n) O (log n)
20. What is a reference variable? (APRIL/MAY 2015)
When a variable is declared as reference, it becomes an alternative name for an
existing variable. A variable can be declared as reference by putting & in the
declaration.

21. What is a friend function? (APRIL/MAY 2015)

Prepared By - D. NAVIS
NAYAGAM

EC6301 Object Oriented Programming and Data Structures


ECE - SEMESTER 03

A friend function of a class is defined outside that class' scope but it has the right
to access all private and protected members of the class. Even though the prototypes for
friend functions appear in the class definition, friends are not member functions.
22. What is overriding? (APRIL/MAY 2015)
If base class and derived class have member functions with same name and
arguments or if you create an object of derived class and write code to access that
member function then, the member function in derived class is only invoked, i.e., the
member function of derived class overrides the member function of base class. This
feature in C++ programming is known as function overriding.
23. Why there is need for operator overloading? (APRIL/MAY 2015)
Operator overloading feature in C++ programming allows programmer to redefine
the meaning of an operator when they operate on class objects (user defined data type).
24. What is ADT? (APRIL/MAY 2015)
An abstract data type (ADT) is a mathematical model for data types, where a data
type is defined by its behavior from the point of view of a user of the data, specifically in
terms of possible values, possible operations on data of this type, and the behavior of
these operations.
25. Write short notes on queue. (APRIL/MAY 2015)
Queue is a linear data structure, in which the first element is inserted from one end called
REAR(also called tail), and the deletion of existing element takes place from the other
end called as FRONT(also called head). This makes queue as FIFO data structure, which
means that element inserted first will also be removed first.
The process to add an element into queue is called Enqueue and the process of removal of
an element from queue is called Dequeue.
26. What is a tree? (APRIL/MAY 2015)
A tree is a non-linear data structure that is used to represents hierarchical
relationships between individual data items.
A tree is a finite set of one or more nodes such that, there is a specially designated
node called root. The remaining nodes are partitioned into n>=0 disjoint sets T1, T2,..Tn,
where each of these set is a tree T1,Tn are called the subtrees of the root.

27. How a graph is represented? (APRIL/MAY 2015)


Graphs are represented using Adjacency Matrix and Adjacency Lists

Prepared By - D. NAVIS
NAYAGAM

EC6301 Object Oriented Programming and Data Structures


ECE - SEMESTER 03

In Adjacency Matrix is a 2D array of size V x V where V is the number of vertices


in a graph. Let the 2D array be adj[][], a slot adj[i][j] = 1 indicates that there is an edge
from vertex i to vertex j.
In Adjacency Lists An array of linked lists is used. Size of the array is equal to
number of vertices. Let the array be array[]. An entry array[i] represents the linked list of
vertices adjacent to the ith vertex
28. What is meant by sorting? (APRIL/MAY 2015)
Sorting is an operation of arranging data, in some given order such as increasing (or)
decreasing with numerical data (or) alphabetically with character data. Sorting methods
can be characterized into two categories:

Internal sorting

External sorting

29. What is time complexity? (APRIL/MAY 2015)


Time complexity of an algorithm signifies the total time required by the program to run
to completion. The time complexity of algorithms is most commonly expressed using
the big O notation. Time Complexity is most commonly estimated by counting the
number of elementary functions performed by the algorithm. And since the
algorithm's performance may vary with different types of input data, hence for an
algorithm we usually use the worst-case Time complexity of an algorithm because
that is the maximum time taken for any input size.

Prepared By - D. NAVIS
NAYAGAM

Das könnte Ihnen auch gefallen