Viva Questions and Answers
Viva Questions and Answers
Data structures refers to the way data is organized and manipulated. It seeks to find ways to make
data access more efficient. When dealing with data structure, we not only focus on one piece of
data, but rather different set of data and how they can relate to one another in an organized manner.
Basically, the key difference is the memory area that is being accessed. When dealing with the
structure that resides the main memory of the computer system, this is referred to as storage
structure. When dealing with an auxiliary structure, we refer to it as file structures.
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.
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.
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 structures 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.
7) What is LIFO?
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.
8 ) What is a queue?
A queue is a data structures that can simulates a list or stream of data. In this structure, new
elements are inserted at one end and existing elements are removed from the other end.
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.
10) Which data structures is applied when dealing with a recursive function?
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.
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.
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
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.
It actually depends on where you intend to apply linked lists. If you based it on storage, a linked
list is considered non-linear. On the other hand, if you based it on access strategies, then a linked
list is considered linear.
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.
An ordered list is a list in which each node’s position in the list is determined by the value of its
key component, so that the key values form an increasing sequence, as the list is traversed.
Merge sort takes a divide-and-conquer approach to sorting data. In a sequence of data, adjacent
ones are merged and sorted to create bigger sorted lists. These sorted lists are then merged again
to form an even bigger sorted list, which continuous until you have one single sorted list.
Null is actually a value, whereas Void is a data type identifier. A variable that is given a Null value
simply indicates an empty value. Void is used to identify pointers as having no initial size.
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.
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.
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.
Basically, the heap is more flexible than the stack. That’s because memory space for the heap can
be dynamically allocated and de-allocated as needed. However, memory of the heap can at times
be slower when compared to that stack.
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.
A binary tree is balanced if the depth of two subtrees of every node never differ by more than
one)
27). Which data structure is needed to convert infix notations to post fix notations?
Stack
27). What is data structure or how would you define data structure?
In programming the term data structure refers to a scheme for organizing related piece of
information. Data Structure = Organized Data + Allowed Operations.)
Hashing is a technique to convert a range of key values into a range of indexes of an array.
31)What is Data Structure?
Data structure is a fundamental concept of any programming language, essential for algorithmic
design.
DS is how data and the relationship amongst different data is represented, that aids in how
efficiently various functions or operations or algorithms can be applied
32)What is an array?
Arrays are the collection of similar types of data stored at contiguous memory locations.
It is the simplest data structure where the data element can be accessed randomly just by using its
index number.
Multi-dimensional arrays are those data structures that span across more than one dimension.
This indicates that there will be more than one index variable for every point of storage. This type
of data structure is primarily used in cases where data cannot be represented or stored using only
one dimension. Most commonly used multidimensional arrays are 2D arrays.
2D arrays emulates the tabular form structure which provides ease of holding the bulk of data that
are accessed using row and column pointers.
A linked list is a data structure that has sequence of nodes where every node is connected to the
next node by means of a reference pointer. The elements are not stored in adjacent memory
locations. They are linked using pointers to form a chain. This forms a chain-like link for data
storage.
• a data field
• a reference (or pointer) to the next node.
The first node in a linked list is called the head and the last node in the list has the pointer to NULL.
Null in the reference field indicates that the node is the last node. When the list is empty, the head
is a null reference.
How are linked lists more efficient than arrays?
Insertion and deletion process is expensive in an array as the room has to be created for the new
elements and existing elements must be shifted.
But in a linked list, the same operation is an easier process, as we only update the address present
in the next pointer of a node.
Linked list is a dynamic data structure that means there is no need to give an initial size at the time
of creation as it can grow and shrink at runtime by allocating and deallocating memory.
Whereas, the size of an array is limited as the number of items is statically stored in the main
memory.
No wastage of memory
As the size of a linked list can grow or shrink based on the needs of the program, there is no
memory wasted because it is allocated in runtime.
In arrays, if we declare an array of size 10 and store only 3 elements in it, then the space for 3
elements is wasted. Hence, chances of memory wastage is more in arrays.
This is a complex type of a linked list wherein a node has two references:
A music playlist with next song and previous song navigation options.
The undo and redo functionality on platforms such as word, paint etc, where you can reverse the
node to get to the previous page.
Stack is a linear data structure that follows LIFO (Last In First Out) approach for accessing
elements.
Push, pop, and top (or peek) are the basic operations of a stack.
A queue is a linear data structure that follows the FIFO (First In First Out) approach for accessing
elements.
Dequeue from the queue, enqueue element to the queue, get front element of queue, and get rear
element of queue are basic operations that can be performed.
How is a stack different from a queue?
In a stack, the item that is most recently added is removed first whereas in queue, the item least
recently added is removed first.
Tree is a recursive, non-linear data structure consisting of the set of one or more data nodes
where one node is designated as the root and the remaining nodes are called as the children
of the root.
Tree organizes data into hierarchial manner.
The most commonly used tree data structure is a binary tree and its variants.
Some of the applications of trees are:
1. Filesystems —files inside folders that are inturn inside other folders.
2. Comments on social media — comments, replies to comments, replies to replies
etc form a tree representation.
3. Family trees — parents, grandparents, children, and grandchildren etc that
represents the family hierarchy.
A binary Tree is a special type of tree where each node can have at most two children. Binary tree
is generally partitioned into three disjoint subsets, i.e. the root of the tree, left sub-tree and right
sub-tree.