HW 17454
HW 17454
HW 17454
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.
– Operator Overloading
– Function Overloading
– Virtual Functions
Q. What is an array?
Q. What is a matrix?
Ans.
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.
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.
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.
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.
1. If Top=Maxsize-1
2. Set Top=Top+1
3. Set stack[Top]=Item
4. Exit
1. If Top<0
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.
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.
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.
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.
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?
It can be either:
Insertion Algorithm:
Deletion Algorithm:
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 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:……………
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.
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.
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.
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.
Ans.
3. Syntax analysis.
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.
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.
2) Display(preorder)the BT
3) Display(inorder)the BT
4) Display(postorder)the BT
6) Traversal of BT
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.
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.
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. 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.
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,
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?
If the 'pivotal value' (or the 'Height factor') is greater than 1 or less than -1.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.