HW 17454

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

BCA II

PROGRAMMING WITH C++ AND DATA STRUCTURES

Viva Questions
Q. What is a class and what are objects?

A class in C++ is a collection of objects. Variables created of a particular class are instances of
that class known as objects.

Q. What is abstraction?

Abstraction is a process of defining the essential concepts while ignoring the inessential details.

Q. What is polymorphism? How is it achieved in C++?

■ Ability to take more than one form is known as Polymorphism.

■ C++ supports polymorphism through :

– Operator Overloading

– Function Overloading

– Virtual Functions

Q. What is an array?

Ans. An array data structure or simply an array is a data structure consisting of a collection


of elements (values or variables), each identified by at least one array index or key. An array is
stored so that the position of each element can be computed from its index tuple by a
mathematical formula.

Q. What is the syntax of for loop?

Ans. for(variable initialization; test condition; increment/decrement variable)

Body of the loop

Q. What is the use of #include<iostream.h>?


Ans. iostream.h is a header file that contains the definition of basic_iostream class template,
which implements formatted input and output.

Q. What is the use of #include<conio.h>?

Ans. conio.h is a C header file used mostly by MS-DOS compilers to provide


console input/output.

Q. What is a matrix?
Ans.

A matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged


in rows and columns. The individual items in a matrix are called its elements or entries. An example of a
matrix with 2 rows and 3 columns is

Q. What are nested for loops?


Ans. A for loop within a for loop is known as nested for loop.

For example: for(i=0;i<=2;i++)


{ for(j=0;j<=2;j++)
{
// Body of the loop
}
}

Q. What will be index of the first element off a 2x2 matrix in C++?

Ans. 0,0
Q. Why do you use \n and \t?
Ans.
\n is used for new line and \t is used for tab
Q. What is the use of break statement?

Ans.  break statement is used to terminate the current loop immediately and transfer control to the
statement immediately following that loop.

Q. What is the use of flag?

Ans. flag is used for checking the status of initialized variable.


Q. What is factorial?
Ans. A factorial of a number n is the continued product n x (n-1) x (n-2)……..x 1

Q. What is single recursion and multiple recursion?

Ans. Recursion that only contains a single self-reference is known as single recursion, while
recursion that contains multiple self-references is known as multiple recursion. 

Q. What are the essential components of a function?

Ans. A) Function prototype

B) Function call

C) Function Body

Q. What is a function prototype?

Ans. A function prototype  is a declaration of a function that omits the function body but does specify
the function's return type, name and argument types. 

Q. Which data structure is applied when dealing with a recursive function?

Ans. Recursion, which is basically a function that calls itself based on a terminating
condition, makes use of the stack. Using LIFO, a call to a recursive function saves the return
address so that it knows how to return to the calling function after the call terminates.

Q. What is the algorithm for push and pop operations in a stack?

Ans. Algorithm for push operation:

1. If Top=Maxsize-1

then print overflow and exit.

2. Set Top=Top+1

3. Set stack[Top]=Item

4. Exit

Algorithm for pop operation:

1. If Top<0

then print underflow and exit.


2. Item=stack[Top]

3. Set Top=Top-1

4. Return Item

5. Exit

Q. What is a stack?

Ans. A stack is a data structure in which only the top element can be accessed. As data is
stored in the stack, each data is pushed downward, leaving the most recently added data on
top. It works on the principle of LIFO or FILO.

Q. Differentiate STACK from ARRAY.

Ans. Data that is stored in a stack follows a LIFO pattern. This means that data access
follows a sequence wherein the last data to be stored will the first one to be extracted.
Arrays, on the other hand, does not follow a particular order and instead can be accessed by
referring to the indexed element within the array.

Q. What is the difference between a PUSH and a POP?

Ans. Pushing and popping applies to the way data is stored and retrieved in a stack. A push
denotes data being added to it, meaning data is being “pushed” into the stack. On the other
hand, a pop denotes data retrieval, and in particular refers to the topmost data being
accessed.

Q. What is LIFO?

Ans. LIFO is short for Last In First Out, and refers to how data is accessed, stored and
retrieved. Using this scheme, data that was stored last , should be the one to be extracted
first. This also means that in order to gain access to the first data, all the other data that
was stored before this first data must first be retrieved and extracted.

Q. What is the data structure used to perform recursion?

Ans. Stack. Because of its LIFO (Last In First Out) property it remembers its 'caller' so
knows whom to return when the function has to return. Recursion makes use of system
stack for storing the return addresses of the function calls.

Every recursive function has its equivalent iterative (non-recursive) function. Even when
such equivalent iterative procedures are written, explicit stack is to be used.

Q. What is a queue?
Ans. A queue is a data structure that can simulates a list or stream of data. In this
structure, new elements are inserted at one end called rear and existing elements are
removed from the other end called front.

Q. What is FIFO?

Ans. FIFO is short for First-in, First-out, and is used to represent how data is accessed in a
queue. Data has been inserted into the queue list the longest is the one that is removed
first.

Q. What is the minimum number of queues needed when implementing a priority


queue?

Ans. The minimum number of queues needed in this case is two. One queue is intended for
sorting priorities while the other queue is intended for actual storage of data.

Q. What is a dequeue?

A dequeue is a double-ended queue. This is a structure wherein elements can be inserted or


removed from either end.

It can be either:

(a) Input restricted dequeue


(b) Output restricted dequeue

Q. What is the algorithm for insertion and deletion in a queue?

Insertion Algorithm:

1. If rear=max-1 then print “Queue full” and exit.


2. Set rear=rear+1
3. Set queue[rear]=item
4. Exit

Deletion Algorithm:

1. If front=rear then print ”Queue empty” and exit


2. Set front=front+1
3. Return item=queue[front]
4. Exit

Q. What is a circular queue?

Ans. A circular queue is a queue in which the link of the last element points back to the first element.
Q. How is a circular queue implemented?

Ans. A circular queue can be implemented using an array or a linked list.

Q. What is the use of a switch statement?

Ans. A switch statement is a type of selection control mechanism used to allow the value of
a variable or expression to change the control flow of program execution via a multiway
branch.

switch(variable)

case <variable_value1>:……………

break;

case <variable_value2>:……………

break;

……………

default:……………

Q. What is a menu driven program?

Ans. In a menu driven program the user gives his choice of input as indicated on the
console menu and depending upon this choice the program fragment is executed.

Q. What is the use of #define?

Ans. #define is used to assign value to a variable

Q. What is a linked list?

Ans. A linked list is a sequence of nodes in which each node is connected to the node
following it. This forms a chain-like link of data storage. Every node will have minimum two
fields: information field and link field. It will also have a start pointer indicating the start of
the link list and the NULL pointer in the link field of a node indicates the end of the linked
list.

Q. How do you search for a target key in a linked list?


Ans. To find the target key in a linked list, you have to apply sequential search. Each node
is traversed and compared with the target key, and if it is different, then it follows the link
to the next node. This traversal continues until either the target key is found or if the last
node is reached.

Q. What are the parts of a linked list?

Ans. A linked list typically has two parts: the head and the tail. Between the head and tail
lie the actual nodes consisting of info. and next pointer, with each node being linked in a
sequential manner.

Q. What is a structure?

Ans. Structure is the collection of variables of different types under a single name for better
handling. For example: You want to store the information about person about his/her name,
citizenship number and salary. You can create these information separately but, better
approach will be collection of these information under single name because all these
information are related to person.

Q. What is the use of a switch statement?

Ans. A switch statement is a type of selection control mechanism used to allow the value of
a variable or expression to change the control flow of program execution via a multiway
branch.

Q. List out few of the Application of tree data-structure?

Ans.

1. The manipulation of Arithmetic expression,


2. Symbol Table construction,

3. Syntax analysis.

Q. What are binary trees?

Ans. A binary tree is one type of data structure that has two nodes, a left node and a right
node. In programming, binary trees are actually an extension of the linked list structures.

Q. Explain Binary Search Tree

Ans. A binary search tree stores data in such a way that they can be retrieved very
efficiently. The left subtree contains nodes whose keys are less than the node’s key value,
while the right subtree contains nodes whose keys are greater than or equal to the node’s
key value. Moreover, both subtrees are also binary search trees.
Q. What is the minimum number of nodes that a binary tree can have?

Ans. A binary tree can have a minimum of zero nodes, which occurs when the nodes have
NULL values. Furthermore, a binary tree can also have 1 or 2 nodes.

Q. List the operations that can be performed on a Binary Tree.

Ans. 1) Insert a node in the BT

2) Display(preorder)the BT

3) Display(inorder)the BT

4) Display(postorder)the BT

5) Delete a node from BT

6) Traversal of BT

Q. What is Bubble Sort?

Ans. Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the
list to be sorted, comparing each pair of adjacent items and swapping them if they are in the
wrong order. The pass through the list is repeated until no swaps are needed, which indicates
that the list is sorted.

Q. What is Selection Sort?

Ans. The algorithm divides the input list into two parts: the sublist of items already sorted, which is
built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted
that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the
entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting
order) element in the unsorted sublist, exchanging it with the leftmost unsorted element (putting it in
sorted order), and moving the sublist boundaries one element to the right.

Q. What is a graph?

Ans. A graph is one type of data structure that contains a set of ordered pairs. These
ordered pairs are also referred to as edges or arcs, and are used to connect nodes where
data can be stored and retrieved.

Q. What is a spanning Tree?

Ans. A spanning tree is a tree associated with a network. All the nodes of the graph appear
on the tree once. A minimum spanning tree is a spanning tree organized so that the total
edge weight between nodes is minimized.
Q. What is a Directed Graph?

Ans. A directed graph or digraph is an ordered pair D = (V, A) with

 V a set whose elements are called vertices or nodes, and


 A a set of ordered pairs of vertices, called arcs, directed edges, or arrows.

Q. What is a Weighted Graph?

Ans. A graph is a weighted graph if a number (weight) is assigned to each edge. Such


weights might represent, for example, costs, lengths or capacities, etc. depending on the
problem at hand. Such a graph is also called a network.

Q. What is an Undirected graph?

Ans. An undirected graph is one in which edges have no orientation. The edge (a, b) is identical to
the edge (b, a), i.e., they are not ordered pairs, but sets {u, v} (or 2-multisets) of vertices. The
maximum number of edges in an undirected graph without a self-loop is n(n - 1)/2.

ADDITIONAL VIVA QUESTIONS:

1. What is data structure?

A data structure is a way of organizing data that considers not only the items stored, but
also their relationship to each other. Advance knowledge about the relationship between
data items allows designing of efficient algorithms for the manipulation of data.

2. List out the areas in which data structures are applied extensively?

1. Compiler Design,
2. Operating System,

3. Database Management System,

4. Statistical analysis package,

5. Numerical Analysis,

6. Graphics,

7. Artificial Intelligence,

8. Simulation
3. What are the notations used in Evaluation of Arithmetic Expressions using
prefix and postfix forms?

Polish and Reverse Polish notations.

4. In tree construction which is the suitable efficient data structure? (Array,


Linked list, Stack, Queue)

Linked list is the suitable efficient data structure.

5. In an AVL tree, at what condition the balancing is to be done?

If the 'pivotal value' (or the 'Height factor') is greater than 1 or less than -1.

6. When is a binary search best applied?

A binary search is an algorithm that is best applied to search a list when the elements are
already in order or sorted. The list is search starting in the middle, such that if that middle
value is not the target search key, it will check to see if it will continue the search on the
lower half of the list or the higher half. The split and search will then continue in the same
manner.

7. How do you reference all the elements in a one-dimension array?

To do this, an indexed loop is used, such that the counter runs from 0 to the array size
minus one. In this manner, we are able to reference all the elements in sequence by using
the loop counter as the array subscript.

8. In what areas are data structures applied?

Data structure is important in almost every aspect where data is involved. In general,
algorithms that involve efficient data structure is applied in the following areas: numerical
analysis, operating system, A.I., compiler design, database management, graphics, and
statistical analysis, to name a few.

9. What are multidimensional arrays?

Multidimensional arrays make use of multiple indexes to store data. It is useful when storing
data that cannot be represented using a single dimensional indexing, such as data
representation in a board game, tables with data stored in more than one column.

10. What is the primary advantage of a linked list?

A linked list is a very ideal data structure because it can be modified easily. This means that
modifying a linked list works regardless of how many elements are in the list.
11. What is a linear search?

A linear search refers to the way a target key is being searched in a sequential data
structure. Using this method, each element in the list is checked and compared against the
target key, and is repeated until found or if the end of the list has been reached.

12. What is a postfix expression?

A postfix expression is an expression in which each operator follows its operands. The
advantage of this form is that there is no need to group sub-expressions in parentheses or
to consider operator precedence.

13. What is Data abstraction?

Data abstraction is a powerful tool for breaking down complex data problems into
manageable chunks. This is applied by initially specifying the data objects involved and the
operations to be performed on these data objects without being overly concerned with how
the data objects will be represented and stored in memory.

14. What are dynamic data structures?

Dynamic data structures are structures that expand and contract as a program runs. It
provides a flexible means of manipulating data because it can adjust according to the size of
the data.

15. Differentiate linear from non linear data structure.

Linear data structure is a structure wherein data elements are adjacent to each other.
Examples of linear data structure include arrays, linked lists, stacks and queues. On the
other hand, non-linear data structure is a structure wherein each data element can connect
to more than two adjacent data elements. Examples of non linear data structure include
trees and graphs.

16. What is an AVL tree?

An AVL tree is a type of binary search tree that is always in a state of balanced. The balance
is measured as a difference between the heights of the subtrees from the root.

You might also like