Professional Documents
Culture Documents
2. List out the areas in which data structures are applied extensively?
Compiler Design,
Operating System,
Database Management System,
Statistical analysis package,
Numerical Analysis,
Graphics,
Artificial Intelligence,
Simulation
3. What are the major data structures used in the following areas : RDBMS, Network data model &
Hierarchical data model.
RDBMS – Array (i.e. Array of structures)
Network data model – Graph
Hierarchical data model – Trees
4. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to
connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable
of storing pointer to any type as it is a generic pointer type.
Null Branches
It will have only 6 (ie,5+1) null branches. In general,
A binary tree with n nodes has exactly n+1 null nodes.
i ii iii iv v
In general:
If there are n nodes, there exist 2n-n different trees.
9. List out few of the applications that make use of Multilinked Structures?
Sparse matrix,
Index generation.
10. What is the bucket size, when the overlapping and collision occur at same time?
One. If there is only one entry possible in the bucket, when the collision occurs, there is no way to
accommodate the colliding value. This results in the overlapping of values.
11. Traverse the given tree using Inorder, Preorder and Postorder traversals.
Given tree:
A
B C
D E F G
H I J
Inorder : DHBEAFCIGJ
Preorder: ABDHECFGIJ
Postorder: HDEBFIJGCA
12. There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them could have formed a full binary
tree?
15.
In general:
There are 2n-1 nodes in a full binary tree.
By the method of elimination:
Full binary trees contain odd number of nodes. So there cannot be full binary trees with 8 or 14
nodes, so rejected. With 13 nodes you can form a complete binary tree but not a full binary tree. So the correct
answer is 15.
Note:
Full and Complete binary trees are different. All full binary trees are complete binary trees but not vice
versa.
13. In the given binary tree, using array you can store the node 4 at which location?
2 3
At location 6
4
5
1 2 3 - - 4 - - 5
where LCn means Left Child of node n and RCn means Right Child of node n
65 70 75 80 85 60 55 50 45
Sorting takes place from the pivot value, which is the first value of the given elements, this is marked bold.
The values at the left pointer and right pointer are indicated using L and R respectively.
65 70L 75 80 85 60 55 50 45R
Since pivot is not yet changed the same process is continued after interchanging the values at L and R positions
65 45 75 L 80 85 60 55 50 R 70
65 45 50 80 L 85 60 55 R 75 70
65 45 50 55 85 L 60 R 80 75 70
65 45 50 55 60 R 85 L 80 75 70
When the L and R pointers cross each other the pivot value is interchanged with the value at right pointer. If the
pivot is changed it means that the pivot has occupied its original position in the sorted order (shown in bold italics)
and hence two different arrays are formed, one from start of the original array to the pivot position-1 and the other
from pivot position+1 to end.
60 L 45 50 55 R 65 85 L 80 75 70 R
55 L 45 50 R 60 65 70 R 80 L 75 85
50 L 45 R 55 60 65 70 80 L 75 R 85
45 50 55 60 65 70 75 80 85
15. For the given graph, draw the DFS and BFS?
Y
X H
E
G P M J
BFS: AXGHPEMYJ
DFS: AXHPEYMJG
24. Classify the Hashing Functions based on the various methods by which the key value is found.
Direct method,
Subtraction method,
Modulo-Division method,
Digit-Extraction method,
Mid-Square method,
Folding method,
Pseudo-random method.
25. What are the types of Collision Resolution Techniques and the methods used in each of the type?
Open addressing (closed hashing),
The methods used include:
Overflow block,
Closed addressing (open hashing)
The methods used include:
Linked list,
Binary tree…
26. In RDBMS, what is the efficient data structure used in the internal storage representation?
B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This
corresponds to the records that shall be stored in leaf nodes.
27. Draw the B-tree of order 3 created by inserting the following data arriving in sequence – 92 24 6 7 11 8
22 4 5 16 19 20 78
11 -
5 7 19 24
4 - 6 - 8 - 16 - 20 22 7
78 92
28. Of the following tree structure, which is, efficient considering space and time complexities?
(a) Incomplete Binary Tree
(b) Complete Binary Tree
(c) Full Binary Tree
30. Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes?
No.
Minimal spanning tree assures that the total weight of the tree is kept at its minimum. But it doesn’t mean
that the distance between any two nodes involved in the minimum-spanning tree is minimum.
31. Convert the given graph with weighted edges to minimal spanning tree.
600
1 3 200
612
410 310
2985 5
400
2 4
1421is:
the equivalent minimal spanning tree
1 3
200
410 612 310
2 4 5
* *
A B + /
C D P Q
Q 35.Define Arrays?
A.An array is a particular method of storing elements of indexed data. Elements of data are stored sequentially in
blocks within the array. Each element is referenced by an index, or subscript.
The index is usually a number used to address an element in the array. For example, if you were storing information
about each day in August, you would create an array with an index capable of addressing 31 values -- one for each
day of the month
Q36.What is searching?
A. The task of searching is one of most frequent operations in computer programming. It also provides an
ideal ground for application of the data structures so far encountered. There exist several basic variations of
the theme of searching, and many different algorithms have been developed on this subject. The basic
assumption in the following presentations is that the collection of data, among which a given element is to
be searched, is fixed.
Q38.What is Sorting?
A. Sorting is generally understood to be the process of rearranging a given set of objects in a specific order. The
purpose of sorting is to facilitate the later search for members of the sorted set. As such it is an almost
universally performed, fundamental activity. Objects are sorted in telephone books, in income tax files, in
tables of contents, in libraries, in dictionaries, in warehouses, and almost everywhere that stored objects have to be
searched and retrieved
• All keys in the left subtree precede the key in the root.
• All keys in the right subtree succeed the key in the root.
• The left and right subtrees of the root are again binary search trees.
A.An AVL tree is a binary search tree in which the heights of the left and right subtrees of the root differ by at most
1, and the left and right subtrees are again AVL trees.
A.The simplest algorithm to search a dictionary for a given key is to test successively against each element.This
works correctly regardless of the order of the elements in the list. However, in the worst case all elements might
have to be tested.
A.Binary Search is an incredibly powerful technique for searching an ordered list. It is familiar to everyone who
uses a telephone book.The basic algorithm is to find the middle element of the list, compare it against the key,
decide which half of the list must contain the key, and repeat with that half.
1.Random access of the list elements, so we need arrays instead of linked lists.
2.The array must contain elements in sorted order by the search key.
A.Asymptotic complexity is a way of expressing the main component of the cost of an algorithm, using idealized
units of computational work. Consider, for example, the algorithm for sorting a deck of cards, which proceeds by
repeatedly searching through the deck for the lowest card. The asymptotic complexity of this algorithm is the square
of the number of cards in the deck.
Q48.What is Big-O Notation?
A.Big-O is the formal method of expressing the upper bound of an algorithm's running time. It's a measure of the
longest amount of time it could possibly take for the algorithm to complete.
More formally, for non-negative functions, f(n) and g(n), if there exists an integer n0 and a constant c > 0 such that
for all integers n > n0, f(n) ≤ cg(n), then f(n) is Big O of g(n). This is denoted as "f(n) = O(g(n))".
A.For non-negative functions, f(n) and g(n), if there exists an integer n0 and a constant c > 0 such that for all integers
n > n0, f(n) ≥ cg(n), then f(n) is omega of g(n). This is denoted as "f(n) = Ω(g(n))".
This is almost the same definition as Big Oh, except that "f(n) ≥ cg(n)", this makes g(n) a lower bound function,
instead of an upper bound function. It describes the best that can happen for a given data size.
A.For non-negative functions, f(n) and g(n), f(n) is theta of g(n) if and only if f(n) = O(g(n)) and f(n) = Ω(g(n)). This
is denoted as "f(n) = Θ(g(n))".
This is basically saying that the function, f(n) is bounded both from the top and bottom by the same function, g(n).
A.For non-negative functions, f(n) and g(n), f(n) is little o of g(n) if and only if f(n) = O(g(n)), but f(n) ≠ Θ(g(n)).
This is denoted as "f(n) = o(g(n))".
This represents a loose bounding version of Big O. g(n) bounds from the top, but it does not bound the bottom.
A.For non-negative functions, f(n) and g(n), f(n) is little omega of g(n) if and only if f(n) = Ω(g(n)), but
f(n) ≠ Θ(g(n)). This is denoted as "f(n) = ω(g(n))".
Much like Little Oh, this is the equivalent for Big Omega. g(n) is a loose lower boundary of the function f(n); it
bounds from the bottom, but not from the top.
A.
1.Index - Fast access to every element in the array using an index [], not so with linked list where elements in
beginning must be traversed to your desired element.
2.Faster - In general, It is faster to access an element in an array than accessing an element in a linked-list.
A.
1. Resize - Can easily resize the link-list by adding elements without affecting the majority of the other
elements in the link-list.
2. Insertion - Can easily insert an element in the middle of a linked-list, (the element is created and then you
code pointers to link this element to the other element(s) in the link-list).
Q55.What ae Stacks?
A. A stack is a basic data structure that is used all throughout programming. The idea is to think of your data as a
stack of plates or books where you can only take the top item off the stack in order to remove things from it.
A stack is also called a LIFO (Last In First Out) to demonstrate the way it accesses data
Q56.Define Queues?
A.A queue is a basic data structure that is used throughout programming. You can think of it as a line in a grocery
store. The first one in the line is the first one to be served.Just like a queue.A queue is also called a FIFO (First In
First Out) to demonstrate the way it accesses data.
Q57.Define Trees.
A.A tree is a non-empty set, one element of which is designated the root of the tree while the remaining elements are
partitioned into non-empty sets each of which is a subtree of the root.
Tree nodes have many useful properties. The depth of a node is the length of the path (or the number of edges) from
the root to that node. The height of a node is the longest path from that node to its leaves. The height of a tree is the
height of the root.
A.
A.A graph is a collection of vertices (also called nodes) and edges (also called arcs) that connect these vertices. A
graph is a generalization of the tree structure, where instead of a strict parent/child relationship between
tree nodes, any kind of complex relationships between the nodes can be represented.
A.Start at vertex v, visit its neighbour w, then w's neighbour y and keep going until reach 'a dead end' then iterate
back and visit nodes reachable from second last visited vertex and keep applying the same principle.
A.Breadth first search visits the nodes neighbours and then the univisited neighbours of the neighbours etc. If it
starts on vertex a it will go to all vertices that have an edge from a. If some points are not reachable it will have to
start another BFS from a new vertex.
Q66.What is a Graph?
Informally, a graph is a finite set of dots called vertices (or
nodes) connected by links called edges (or arcs). More formally: a
simple graph is a (usually finite) set of vertices V and set of
unordered pairs of distinct elements of V called edges.
Q72.Define String.
A.The simplest kind of linked list is a singly-linked list (or slist for short), which contains a node having two fields,
one is information field and another is link field. This link points to the next node in the list, and last node points to a
null value
A singly linked list's node is divided into two parts. The first part holds or points to information about the node, and
second part holds the address of next node. A singly linked list travels one way.
Q78.What is a Doubly-linked list?
A.A more sophisticated kind of linked list is a doubly-linked list or two-way linked list. Each node has two links:
one points to the previous node, or points to a null value or empty list if it is the first node; and one points to the
next, or points to a null value or empty list if it is the final node.
A.In a circularly-linked list, the first and final nodes are linked together. This can be done for both singly and doubly
linked lists. To traverse a circular linked list, you begin at any node and follow the list in either direction until you
return to the original node. Viewed another way, circularly-linked lists can be seen as having no beginning or end.
This type of list is most useful for managing buffers for data ingest, and in cases where you have one object in a list
and wish to iterate through all other objects in the list in no particular order.
The pointer pointing to the whole list may be called the access pointer.
A.Linked lists are used as a building block for many other data structures, such as stacks, queues and their
variations.
The "data" field of a node can be another linked list. By this device, one can construct many linked data structures
with lists; this practice originated in the Lisp programming language, where linked lists are a primary (though by no
means the only) data structure, and is now a common feature of the functional programming style.
Sometimes, linked lists are used to implement associative arrays, and are in this context called association lists. This
use of linked lists is easily outperformed by other data structures such as self-balancing binary search trees even on
small data sets (see the discussion in associative array). However, sometimes a linked list is dynamically created out
of a subset of nodes in such a tree, and used to more efficiently traverse that set.
A. Arrays are used to implement mathematical vectors and matrices, as well as other kinds of rectangular tables. In
early programming languages, these were often the applications that motivated having arrays.
Because of their performance characteristics, arrays are used to implement other data structures, such as heaps, hash
tables, deques, queues, stacks, strings, and VLists.
One or more large arrays are sometimes used to emulate in-program dynamic memory allocation, particularly
memory pool allocation. Historically, this has sometimes been the only way to allocate "dynamic memory" portably.
Q82.What si a Deque?
A. a deque (short for double-ended queue—usually pronounced deck) is an abstract list type data structure, also
called a head-tail linked list, for which elements can only be added to or removed from the front (head) or back
(tail).
A. Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) complexity, making it
inefficient on large lists, and generally performs worse than the similar insertion sort. Selection sort is noted for its
simplicity, and also has performance advantages over more complicated algorithms in certain situations.