Академический Документы
Профессиональный Документы
Культура Документы
1. What is Information?
Information is defined as arranging data in an appropriate sequence, then it forms a structure and
gives us a meaning. The basic unit of Information is a bit, Binary Digit. So, we found two things
in Information: One is Data and the other is Structure.
2. Define List.
A list is a sequential data structure, ie. a collection of items accessible one after another
beginning at the head and ending at the tail.
It is a widely used data structure for applications which do not need random access
Addition and removals can be made at any position in the list
lists are normally in the form of a 1,a2,a3.....an. The size of this list is n.The first element of
the list is a1,and the last element is an.The position of element ai in a list is i.
List of size 0 is called as null list.
55
Appendix A – Two Mark Question Bank
this sort method is somewhat counterintuitive, in the sense that the numbers are sorted on the
least-significant digit first, followed by the second-least significant digit and so on till the most
significant digit.
1. Define stack.
A stack is a list with the restriction that inserts and deletes can be performed in only one position,
namely the end of the list called the top. The fundamental operations on a stack are push, which
is equivalent to an insert, and pop, which deletes the most recently inserted element. It is also
called Last In First Out (LIFO)
57
Appendix A – Two Mark Question Bank
If we see a right parenthesis then pop the stack, writing symbols until we
encounter a left parenthesis.
If we see any symbols(‘+’,’*’,’( ‘) the we opp entries from thee stack until we
find an entry of lower priority.
7. What are the postfix and prefix forms of the expression A+B*(C-D)/(P-R) ?
Postfix form: ABCD-*PR-/+
Prefix form: +A/*B-CD-PR
Chapter 4 - Queue
1. Define queue.
Queue is an linear data structure which insert an element into the rear(enqueue) and dete an
element from the front(dequeue). It is also called First In First Out(FIFO). That is the first
inserted element will be deleted first.
58
Appendix A – Two Mark Question Bank
1. Define tree.
A (rooted) tree consists of a set of nodes (or vertices) and a set of arcs (or edges). Each arc links
a parent node to one of the parent's children.
2. Define root, leaf, path, sibling, Ancestor and Descendent, Subtree, Height and depth
Root -> A node which does not contain any parent is called parent
Leaf -> A node which does not contain any child is called leaf
Path -> A sequence of nodes n1, n2,..., nk, such that ni is the parent of ni + 1 for i = 1, 2,..., k - 1.
The length of a path is 1 less than the number of nodes on the path. Thus there is a path of length
zero from a node to itself.
Siblings -> The children of a node are called siblings of each other.
Ancestor and Descendent -> If there is a path from node a to node b, then a is called an ancestor
of b is called a descendent of a
Subtree -> A subtree of a tree is a node in that tree together with all its descendents.
Height of a node -> The height of a node in a tree is the length of a longest path from the node to
a leaf.
Depth of a node -> The depth of a node in a tree is the length of a longest path from the node to
a root.
Depth of the tree (or) height of the tree ->The depth of the tree (or) height of the tree is the
length of the unique path from the root to the leaf. The height of a tree is the height of its root.
59
Appendix A – Two Mark Question Bank
60
Appendix A – Two Mark Question Bank
62
Appendix A – Two Mark Question Bank
Binary tree
Depth-first
Pre-order traversal sequence: F, B, A, D, C, E, G, I, H (root, left, right)
In-order traversal sequence: A, B, C, D, E, F, G, H, I (left, root, right)
Post-order traversal sequence: A, C, E, D, B, H, I, G, F (left, right, root)
Breadth-first
Level-order traversal sequence: F, B, G, A, D, I, C, E, H
63
Appendix A – Two Mark Question Bank
64
Appendix A – Two Mark Question Bank
A Single Right Rotation is used when the node that is out of balance to the left (balance factor <=
-2), and the left subtree is left heavy (balance factor = -1). This is sometimes called the Left-Left
case:
8. List out the possible cases for performing insertion into an AVL trees.
A difference of levels between left and right subtrees can be increased, through insertion of a
new node into the tree, in 4 possible ways:
1. Insertion into left subtree of left branch. (Left-left case)
2. Insertion into right subtree of left branch. (Right-left case)
3. Insertion into left subtree of right branch. (Left-right case)
4. Insertion into right subtree of right branch. (Right-right case)
Rotations which reduce or correct the resulting imbalances are diagrammed for these 4 cases
below.
Chapter 7 – Binary Heaps
65
Appendix A – Two Mark Question Bank
There are three ways for implementing priority queue. They are:
1. Linked list
2. Binary Search tree
3. Binary Heap
66
Appendix A – Two Mark Question Bank
1. Define B-tree.
A B+ tree is in the form of a balanced tree in which every path from the root of the tree to a leaf
of the tree is the same length. Each non-leaf node in the tree has between [n/2] and n
children, where n is fixed. B+ trees are good for searches, but cause some overhead issues
in wasted space.
67
Appendix A – Two Mark Question Bank
A splay tree is a self-adjusting binary search tree with the additional property that
recently accessed elements are quick to access again.
Search, insert, and delete operations are like in binary search trees, except at the end of
each operation a special step called splaying is done. Splaying ensures that all operations
take O(log n) amortized time.
The basic idea of the splay tree is that after a node is accessed, it is pushed to the root by
a series of AVL tree rotations.
68
Appendix A – Two Mark Question Bank
Zig-Zag: A double rotation between target, parent and grandparent.(same as AVL tree double
rotation)
Zig-Zig: a single rotation between target, parent and grandparent. This is not an AVL tree
rotation.
Zig: a single rotation between target and parent (for root).This is similar to AVL tree single
rotation but for root. When the target is just below the root, use Zig, otherwise use Zig-Zag or
Zig-Zig.
Chapter 9 – Hashing
1. Define hashing.
Hashing is a method to store data in an array so that storing, searching, inserting and deleting
data is fast (in theory it's O(1)). For this every record needs an unique key. The basic idea is not
to search for the correct position of a record with comparisons but to compute the position within
the array. The function that returns the position is called the 'hash function' and the array is called
a 'hash table'.
69
Appendix A – Two Mark Question Bank
A key is multiplied by itself and the hash value is obtained by selecting an appropriate number of
digits from the middle of the square. This method works best if the table size is a power of two.
The same positions in the square must be used for all keys.
70
Appendix A – Two Mark Question Bank
Linear probing is a linear function of i, typically (i) = i. This amounts to trying cells sequentially
(with wraparound) in search of an empty cell.
possibilities suggest that it is important for the bits to be fairly random. This can be accomplished
by hashing the keys into a reasonably long integer; hence the reason for the name.
1. What is equivalence relation? (or) What are the properties of equivalence relations?
An equivalence relation is a relation R that satisfies three properties:
1. (Reflexive) a R a, for all a S.
2. (Symmetric) a R b if and only if b R a.
3. (Transitive) a R b and b R c implies that a R c.
3. Define Relations.
72
Appendix A – Two Mark Question Bank
A relation R is defined on a set S if for every pair of elements (a, b), a, b S, a R b is either true or
false. If a R b is true, then we say that a is related to b. An equivalence relation is a relation R
that satisfies three properties:
1. (Reflexive) a R a, for all a S.
2. (Symmetric) a R b if and only if b R a.
3. (Transitive) a R b and b R c implies that a R c.
6. What is union-by-size?
Union-by-size performs union by making the smaller tree a subtree of the larger.
7. Define union-by-height.
Union-by-height performs union by making the shallow tree a subtree of the deeper tree.
Chapter 11 – Graphs
1. Define graph.
A graph consists of a set of nodes (or Vertices) and a set of arc (or edge). Each arc in a graph
is specified by a pair of nodes. Graph consists of a non-empty set of points called vertices and
a set of edges that link vertices.
73
Appendix A – Two Mark Question Bank
Any two nodes which are connected by an edge in a graph are called adjacent nodes. For
example, if and edge xÎE is associated with a pair of nodes (u, v) where u, v Î V, then we say that
the edge x connects the nodes u and v.
3. Define loop.
Loop is an edge that connects a vertex to itself. Edge e6 in the figure below is a loop. Edges
with same end vertices are called parallel edges. Edges e4 and e5 are parallel edges in the
below figure.
74
Appendix A – Two Mark Question Bank
Size of the adjacency lists is proposal to number of edges and vertices. It is an efficient memory
use for sparse graphs. Accessing an element takes linear time, since it involves traversal of
linked list.
75
Appendix A – Two Mark Question Bank
76
Appendix A – Two Mark Question Bank
solution depth d and this value is rarely known in advance of actually solving the
problem. If the chosen cutoff depth is less than d, the algorithm will fail to find a
solution, whereas if the cutoff depth is greater than d, a large price is paid in execution
time, and the first solution found may not be an optimal one.
Depth-First Search is not guaranteed to find the solution.
And there is no guarantee to find a minimal solution, if more than one solution exists.
DFS BFS
Depth-first search (DFS) is an algorithm for Breadth-first search (BFS) is a graph search
traversing or searching a tree, tree structure, or algorithm that begins at the root node and
graph. Intuitively, one starts at the root explores all the neighboring nodes. Then for
(selecting some node as the root in the graph each of those nearest nodes, it explores their
case) and explores as far as possible along unexplored neighbor nodes, and so on, until it
each branch before backtracking. finds the goal.
Uses stack Uses queue
Applications are finding articulation points, Applications are finding minimum spanning
euler circuits tree, dijkstra’s algorithm
Example Example
The minimum spanning tree of a weighted graph is a set of edges of minimum total weight
which form a spanning tree of the graph.
24. What are the methods are used to implement minimum spanning tree?
Prim’s algorithm
Kruskal’s algorithm
78
Appendix A – Two Mark Question Bank
A circuit is a path that starts and ends at the same vertex. An Euler circuits exists if it is possible
to travel over every edge of a graph exactly once and return to the starting vertex.
33. What is P?
P is the set of all decision problems which can be solved in polynomial time by a deterministic
Turing machine. Since it can solve in polynomial time, it can also be verified in polynomial time.
Therefore P is a subset of NP.
79
Appendix A – Two Mark Question Bank
1. Define sorting.
Sorting is the process of arranging the elements in ascending or descending order.
property is satisfied in the tree which was rooted at (i). Step III: Remove maximum element: The
program removes the largest element of the heap (the root) by swapping it with the last element.
Step IV: The program executes Heapify(new root) so that the resulting tree satisfies the heap
property.
Step V: Goto step III till heap is empty
82
Appendix A – Two Mark Question Bank
Greedy method is an approach to find the optimized solutions for the given problem. The
solutions are constructed through a sequence of steps, each step expanding a partially constructed
solution so far, until a complete solution to the problem is reached.
83
Appendix A – Two Mark Question Bank
10. Write down the formula for finding the time complexity using divide and conquer.
T(n)=a(n/b)+f(n)
Where, T(n) is the running time of the given algorithm
A is the number of sub problems
B is the sub problem size
F(n) is the time to combine the solutions of sub problems
84
Appendix A – Two Mark Question Bank
Solution states are that problem states for which the path from the root to s defines a tuple in the
solution space. Solution space is partitioned into disjoint sub-solution space at each internal node
21. What are the differences between exhaustive search method and state-space
algorithms?
State-space algorithms make it possible to solve some larger instances of difficult combinatorial
problems. Unlike exhaustive search, state-space algorithms generate candidate solutions one
component at a time and evaluate the partially constructed solutions. If no potential values of the
remaining components can lead to a solution, the remaining components are not generated at all.
24. What are the reasons for terminating search path at current node in the state-space
tree?
· The value of the nodes bound is not better than the value of the best solution seen so far.
· The node represents no feasible solutions, because the constraints of the problem are already
violated.
· The subset of feasible solutions represented by the node consists of a single point – here we
compare the value of the objective function for this feasible solution with that of the best solution
seen so far and update the latter with the former, if the new solution is better.
25. What is a subset sum problem? Find the subset from the set S={1,2,3,4}, for the sum
d=7 using backtracking.
86
Appendix A – Two Mark Question Bank
A subset sum problem finds a subset of a given set S={s1,s2,..sn}of n positive integers, whose
sum is equal to a given positive integer d.
Draw the backtracking tree to find the subset.
Result: {1,2,4}, {3,4}.
It is used for getting optimal solutions. It is used for getting the solutions to the given
problem that may or may not be optimal.
A set of feasible solutions and picks up the No special set of feasible solutions
optimal solution
Solution is generated without revising It considers the possible sequences in order to
previously generated solutions obtain the solution
Example: Minimum Spanning Tree, Finding Example: N-queen problem, subset sum
shortest path problem
87
Appendix A – Two Mark Question Bank
30. What is travelling salesman problem? How it could be solved using branch-and-bound
technique?
The travelling salesman problem is to find the shortest tour through a given set of n cities that
visits each city exactly once before returning to the city where it started. Travelling salesman
problem as it finds the shortest tour, it computes the lower bound. To compute lower bound,
Find the sum Si of the distances from city i to the nearest cities. Compute sum S of these n
numbers. Divide S by 2 to find lower bound. Set a constraint such that any city should be visited
before another. This reduces more work in generating all-pairs of permutations.
88
Appendix A – Two Mark Question Bank
A function t(n) is said to be in O(g(n)), denote t(n) € O(g(n)), if t(n) is bounded above by some
constant multiple of g(n) for all large n, i.e., if there exists some positive constant c and some
nonnegative integer n0 such that
t(n) ≤ c.g(n) for all n ≥ n0.
89
Appendix A – Two Mark Question Bank
90