You are on page 1of 37

Appendix A – Two Mark Question Bank

TWO MARK QUESTION BANK


Chapter 1 - Introduction to Data Structures

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 data structures.


Data structure is defines as the way of organizing the data that considers not only the items
stored and also the relationships to each other.

3. What are the types of data structures?


 Linear data structures(Eg: linked list, stack, queue)
 Nonlinear data structures(Eg: trees, graphs)
Chapter 2 - Linear Structures

1. What do you mean by abstract data type? Give its operations.


An ADT is a set of operation. A useful tool for specifying the logical properties of a data type is
the abstract data type. ADT refers to the basic mathematical concept that defines the data type.
Eg. Objects such as list, set and graph along their operations can be viewed as ADT's. Union,
Intersection, size, complement and find are the various operations of ADT.

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.

3. What are the operations can be performed in List ADT?


 Creating a list
 Traversing the list
 Inserting an item in the list
 Deleting an item from the list
54
Appendix A – Two Mark Question Bank

 Concatenating two lists into one

4. What are the methods are used to implement list?


 Arrays
 Linked List
 Cursors

5. Define arrays. What are the drawbacks of array?


Array is defined as collection of items of similar data type. The drawbacks are:
 Insertion and deletion are expensive. For example, inserting at position 0 (a new first
element) requires first pushing the entire array down one spot to make room, whereas
deleting the first element requires shifting all the elements in the list up one, so the worst
case of these operations is O(n).
 Even if the array is dynamically allocated, an estimate of the maximum size of the list is
required. Usually this requires a high over-estimate, which wastes considerable space.
This could be a serious limitation, if there are many lists of unknown size.
 Simple arrays are generally not used to implement lists. Because the running time for
insertion and deletion is so slow and the list size must be known in advance.

6. Define linked list.


A Linked list is a chain of structs or records called Nodes. Each node has at least two members,
one of which points to the next Node in the list and the other holds the data. These are defined as
Single Linked Lists because they can only point to the next Node in the list but not to the
previous.

7. What are the types of linked list?


 Singly Linked List
 Doubly Linked List
 Circular Linked List
8. Compare arrays and linked list.

55
Appendix A – Two Mark Question Bank

Arrays Linked List


Array is defined as collection of A Linked list is a chain of structs or records called
items of similar data type Nodes. Each node has at least two members, one of
which points to the next Node in the list and the other
holds the data
Static memory allocation Dynamic memory allocation
Wastage of memory space No wastage of memory
Insertion and delete takes more time Insertion and deletion takes less time

9. What is the need for the header?


Header of the linked list is the first element in the list and it stores the number of elements in the
list. It points to the first data element of the list.

10. Define doubly linked list.


A doubly linked list is a linked data structure that consists of a set of sequentially linked records
called nodes. Each node contains two fields, called links, that are references to the previous and
to the next node in the sequence of nodes.

11. Define circular linked list.


A circular linked list is a linked list where the last node in the list points to the first node in the
list. A circular list does not contain NULL pointers.

12. What are the Applications of List?


 The Polynomial ADT
 Radix Sort
 Multilists

13. Write short notes on radix sort.


Radix sort is one of the linear sorting algorithms for integers. It functions by sorting the input
numbers on each digit, for each of the digits in the numbers. However, the process adopted by
56
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.

14. What is the principle of radix sort?


 Radix sort or bucket sort consists of 10 buckets numbered 0 to 9.
 First step of bucket sort is to sort by least significant digit.
 The next pass includes sorting the next least significant digit
 The pass continues till it scans the most significant digit.

15. Define cursor space. What is the use of cursor?


Cursor space is a list of free cells that are not in any list. When linked has to be used and there is
no pointers available, then an alternative implementation called cursor implementation is used.
Chapter 3 - Stack

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)

2. What are the methods are used to implement stack?


 Linked List Implementation of Stacks
 Array Implementation of Stacks

3. What are the Applications of stack?


 Infix to postfix conversion
 Evaluating postfix expression
 Function calls
 Balancing Symbols
4. Give the procedure for converting infix to postfix.
 Scan the expression character by character.
 When an operand is read, immediately place it onto the output.

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.

5. Explain the usage of stack in recursive algorithm implementation?


In recursive algorithms, stack data structures is used to store the return address when a recursive
call is encountered and also to store the values of all the parameters essential to the current state
of the procedure.

6. What are the exceptional conditions for stack?


 Insertion or pushing a data on to the stack when stack is full is not possible.
 Deletion or popping a data when the stack is empty is not possible.

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.

2. Define circular queue.


Circular queue is a linear data structure. It follows FIFO principle.
 In circular queue the last node is connected back to the first node to make a circle.
 Circular linked list fallow the First In First Out principle
 Elements are added at the rear end and the elements are deleted at front end of the queue
 Both the front and the rear pointers points to the beginning of the array.
 It is also called as “Ring buffer”.
 Items can inserted and deleted from a queue in O(1) time.

58
Appendix A – Two Mark Question Bank

3. What are the methods are used to implement queue?


 Linked List Implementation of queue
 Array Implementation of queue

4. List out some applications of queue.


 Queue in real world.
 Job queue in printers
 Phone calls waiting that has to be connected in a company
Chapter 5 - Trees

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

3. Define binary tree


A binary tree is a tree in which no nodes can have more than two children. A binary consists of a
root and two sub trees, TL and TR , both of which could possibly be empty.

4. Define complete binary tree.


A Complete binary tree of depth K is a binary tree of depth K having 2k – 1 nodes.

5. Define full binary tree.


A full binary tree is a special case of binary tree, in which all the levels are completely filled. A
full binary tree of height h has 2h+1 - 1 nodes. For example, the height is 3, then no. of nodes in
full binary tree is = 23+1-1= 15 nodes.

6. Comparison between general tree and binary tree.


A tree, in turn, is a directed acyclic graph with the condition that every node is accessible from a
single root. This means that every node has a "parent" node and 0 or more "child" nodes, except
for the root node which has no parent.
A binary tree is a tree with one more restriction: no node may have more than 2 children.
More specific than binary trees are balanced binary trees, and more specific than that, heaps.

7. What is meant by directed tree?


Directed tree is an acyclic diagraph which has one node called its root with indegree zero while
all other nodes have indegree 1.
8. What are the applications of tree?
 Data processing.
 File index schemes
 Hierarchical database management system

60
Appendix A – Two Mark Question Bank

 Finding duplicates in a given list of numbers


 Representation of mathematical or logical expression

9. What is meant by traversing?


Traversing a tree means processing it in such a way, that each node is visited only once.

10. What are the different types of traversing?


The different types of traversing are
a. Pre-order traversal-yields prefix form of expression.
b. In-order traversal-yields infix form of expression.
c. Post-order traversal-yields postfix form of expression.

11. Define pre-order traversal.


Pre-order traversal entails the following steps;
a. Process the root node
b. Process the left subtree
c. Process the right subtree

12. Define post-order traversal.


Post order traversal entails the following steps;
a. Process the left subtree
b. Process the right subtree
c. Process the root node

13. Define in -order traversal.


In-order traversal entails the following steps;
a. Process the left subtree
b. Process the root node
c. Process the right subtree

14. Define Strictly binary tree.


If every nonleaf node in a binary tree has nonempty left and right subtrees ,the tree is termed as a
strictly binary tree.

15. List out the representation of trees.


1. Linked list representation
2. Linear or Array representation

16. Give the advantages of linked representation.


61
Appendix A – Two Mark Question Bank

 Insertions and deletions can be made directly without data movements.


 It is best for any type of trees.
 A particular node can be placed at any location in the memory.
 It is flexible because the systems take care of allocating and freeing of nodes.

17. Give the disadvantages of linked representation.


 It is difficult to understand.
 Additional memory is needed for storing pointers.
 Accessing a particular node is not easy.

18. Give the advantages of linear representation.


 This representation is very easy to understand.
 This is the best representation for complete and full binary tree representation.
 Programming is very easy.
 It is very easy to move from a child to its parents and vice versa.

19. Give the disadvantages of linear representation.


 Lot of memory area wasted.
 Insertion and deletion of nodes needs lot of data movement.
 Execution time high.
 This is not suited for trees other than full and complete tree.

20. Define expression tree


Any expression that is going to be represented by an tree structure is called expression tree. In
the following expression tree, the leaves of an expression tree are operands, such as constants or
variable names and other node contain operators.

21. Give an example for tree traversals.

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

22. Define binary search tree.


Binary Search tree is a binary tree in which each internal node x stores an element such that the
element stored in the left sub tree of x are less than or equal to x and elements stored in the right
sub tree of x are greater than or equal to x. This is called binary-search-tree property.

23. What are the operations performed on binary search tree?


 Make Empty
 Find
 Find_min and find_max
 Insert
 Delete :
CASE 1: Node to be deleted is a leaf node (ie) No children.
CASE 2: Node with one child.
CASE 3: Node with two children
Chapter 6 – AVL Trees

63
Appendix A – Two Mark Question Bank

1. Define AVL tree.


An AVL (Adelson-Velskii and Landis) tree is a binary search tree with a balance condition. The
balance condition must be easy to maintain, and it ensures that the depth of the tree is O(log n).
The simplest idea is to require that the left and right subtrees have the same height. An AVL tree
is identical to a binary search tree, except that for every node in the tree, the height of the left and
right subtrees can differ by at most 1.

2. What is a balance factor in AVL trees?


Balance factor of a node is defined to be the difference between the height of the node's left
subtree and the height of the node's right subtree.
B.F = hL – hR
where hL and hR respectively are the heights of the left and right sub trees of T(Tree).

3. What is meant by pivot node?


The node to be inserted travel down the appropriate branch track along the way of the deepest
level node on the branch that has a balance factor of +1 or -1 is called pivot node.

4. Give the pros and cons of AVL trees.


Pros:
1. Search is O(log N) since AVL trees are always balanced.
2. Insertion and deletions are also O(logn)
3. The height balancing adds no more than a constant factor to the speed of insertion.
Cons:
1. Difficult to program & debug; more space for balance factor.
2. Asymptotically faster but rebalancing costs time.
3. Most large searches are done in database systems on disk and use other structures (e.g. B-
trees).
4. Longer running times for the insert and remove operations

5. List out the rotations of AVL tree.


1. Single Rotation
 Single Rotation with left - Left Rotation(Left of Left)
 Single Rotation with Right – Right Rotation(Right of Right)
2. Double Rotation
 Right – left Double Rotation
 Left-right Double Rotation
6. Define Single Right Rotation.

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:

7. Define Double Right Rotation.


A Double Right Rotation is used when the node that is out of balance to the left (balance factor
<= -2), and the left subtree is right heavy (balance factor = 1). The double-right rotation is a
single-left rotation of the left subtree followed by a single right rotation of the node that is out of
balance. This is sometimes called the Left-Right 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

1. Define heaps or priority queues.


A binary heap is a heap data structure created using a binary tree. It can be seen as a binary tree
with two additional constraints:
 The structure property: the tree is a complete binary tree; that is, all levels of the tree,
except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not
complete, the nodes of that level are filled from left to right.
 The heap property: each node is greater than or equal to each of its children according to
a comparison predicate defined for the data structure.

2. Give some applications of priority queues.


 The Selection Problem
 Event Simulation
 Operating system scheduling
 Graph algorithms

3. Give the implementation of a priority queue.

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

4. What are the operations performed by priority queue?


The basic Operations performed by priority queue are:
1. Insert operation
2. Delete_min operation
 Insert operation is the equivalent of queue’s Enqueue operation.
 Delete_min operation is the priority queue equivalent of the queue’s Dequeue operation.

5. Give some Basic Heap Operations.


 Insert
 Delete_min
 Decrease_key
 Increase_key
 Delete
 Build_heap

6. List out the properties of binary heap.


The efficient way of implementing priority queue is binary heap. Binary heap is merely referred
as heaps. Heaps have two properties namely;
 Structure property
 Heap order Property

7. Define structure property.


A heap is a binary tree that is completely filled, with the possible exception of the bottom level,
which is filled from left to right. Such a tree is known as a complete binary tree

8. Define heap order property.


The property that allows operations to be performed quickly is the heap order property. Since we
want to be able to find the minimum quickly, it makes sense that the smallest element should be
at the root.
In a heap, for every node X, the key in the parent of X is smaller than (or equal to) the key in X,
with the obvious exception ofChapter
the root 8(which
– B-Trees
has noand Splay Trees
parent).

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.

2. List out some B-tree characteristics.


1. In a B-tree each node may contain a large number of keys
2. B-tree is designed to branch out in a large number of directions and to contain a lot of
keys in each node so that the height of the tree is relatively small
3. Constraints that tree is always balanced
4. Space wasted by deletion, if any, never becomes excessive
5. Insert and deletions are simple processes
 Complicated only under special circumstances
 Insertion into a node that is already full or a deletion from a node makes it less
then half full

3. Give the applications of B-trees.


 Disk Accesses
 Database systems

4. List out the properties of B-trees


A B-tree of order m is a tree with the following structural properties:
 The root is either a leaf or has between 2 and m children.
 All nonleaf nodes (except the root) have between [m/2] and m children.
 All leaves are at the same depth.
 a leaf node contains no more than m – 1 keys
 The number m should always be odd

5. Draw the structure of B-trees with key 4.

6. Define Splay Trees.

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.

7. List out the advantages of splay trees.


 Simple implementation—simpler than other self-balancing binary search trees, such as
red-black trees or AVL trees.
 Comparable performance—average-case performance is as efficient as other trees.
 Small memory footprint—splay trees do not need to store any bookkeeping data.
 Possibility of creating a persistent data structure version of splay trees—which allows
access to both the previous and new versions after an update. This can be useful in
functional programming, and requires amortized O(log n) space per update.
 Working well with nodes containing identical keys—contrary to other types of self-
balancing trees. Even with identical keys, performance remains amortized O(log n). All
tree operations preserve the order of the identical nodes within the tree, which is a
property similar to stable sorting algorithms. A carefully designed find operation can
return the leftmost or rightmost node of a given key.

8. List out the disadvantages of splay trees


 Perhaps the most significant disadvantage of splay trees is that the height of a splay tree
can be linear. For example, this will be the case after accessing all n elements in non-
decreasing order. Since the height of a tree corresponds to the worst-case access time, this
means that the actual cost of an operation can be slow. However the amortized access
cost of this worst case is logarithmic, O(log n). Also, the expected access cost can be
reduced to O(log n) by using a randomized variant.
 A splay tree can be worse than a static tree by at most a constant factor.
 Splay trees can change even when they are accessed in a 'read-only' manner (i.e. by find
operations). This complicates the use of such splay trees in a multi-threaded environment.
Specifically, extra management is needed if multiple threads are allowed to perform find
operations concurrently.

9. What are the various rotations in Splay trees?

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'.

2. What is the need for hashing?


Hashing is used to perform insertions, deletions and find in constant average time.

3. Define hash function?


Hash function takes an identifier and computes the address of that identifier in the hash table
using some function.

4. List out the different types of hashing functions?


The different types of hashing functions are,
a. The division method
b. The mid square method
c. The folding method
d. Multiplicative hashing
e. Digit analytic

5. Define division method.


An integer key x is divided by the table size m and the remainder is taken as the hash value. It
can be defined as
H(x)=x%m+1
For example, x=42 and m=13, H(42)=45%13+1=3+1=4
6. Define mid square method.

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.

7. Define folding method.


A key is broken into several parts. Each part has the same length as that of the required address
except the last part. The parts are added together, ignoring the last carry, we obtain the hash
address for key K. There are two types of folding namely:
1. Shift folding
2. Boundary folding

8. What are the problems in hashing?


 Collision
 Overflow

9. What is the use of hashing function?


A hash table similar to an array of some fixes size-containing keys. The keys specified here
might be either integer or strings, the size of the table is taken as table size or the keys are
mapped on to some number on the hash table from a range of 0 to table size

10. What are the types of hashing?


 Open addressing (closed hashing)
 Separate chaining (open hashing)

11. Define open addressing (closed hashing).


Closed hashing, also known as open addressing, is an alternative to resolving collisions with
linked lists. In a closed hashing system, if a collision occurs, alternate cells are tried until an
empty cell is found.

12. Define Open Hashing (Separate Chaining).


Separate chaining, direct chaining, or simply chaining, each slot of the bucket array is a pointer
to a linked list that contains the key-value pairs that hashed to the same location. Lookup
requires scanning the list for an entry with the given key. Three common collision resolution
strategies of Closed Hashing (Open Addressing):
 Linear Probing
 Quadratic Probing
 Double Hashing
13. Define linear probing.

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.

14. Define Quadratic Probing.


Quadratic probing is a collision resolution method that eliminates the primary clustering problem
of linear probing. Quadratic probing is what you would expect-the collision function is quadratic.

15. Define Double Hashing.


A method of open addressing for a hash table in which a collision is resolved by searching the
table for an empty place at intervals given by a different hash function, thus minimizing
clustering. It is also known as rehashing.

16. Define Primary clustering.


Primary clustering means that any key that hashes into the cluster will require several attempts to
resolve the collision, and then it will add to the cluster.

17. What is secondary clustering?


The elements that hash to the same position will probe the same alternative cells. This is known
as secondary clustering.

18. Define rehashing.


If the table gets too full, running time for operations increases and insertion fails. A solution is to
build another table that is about twice as big and scan down the entire original hash table,
computing new hash value for each element and inserting it in new hash table. This mechanism
is called rehashing.

19. List out the advantages of rehashing.


 Rehashing frees the programmer from worrying about the table size and is
important because hash tables cannot be made arbitrarily large in complex
programs.
 Simple to implement.

20. List out the advantages of extensible hashing.


This very simple strategy provides quick access times for insert and finds operations on large
databases. There are a few important details we have not considered.
First, it is possible that several directory splits will be required if the elements in a leaf agree in
more than D + 1 leading bits.
Second, there is the possibility of duplicate keys; if there are more than m duplicates, then this
algorithm does not work at all. In this case, some other arrangements need to be made.These
71
Appendix A – Two Mark Question Bank

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.

21. Give the disadvantages of separate chaining.


 It requires the implementation of a separate data structure for chains, and code to manage
it.
 The main cost of chaining is the extra space required for the linked lists.
 For some languages, creating new nodes (for linked lists) is expensive and slows down
the system.

22. Give the advantages of double hashing.


 No primary clustering and no secondary clustering
 Need one extra hash calculation

23. What are the techniques to overcome hash collision?


 Linear probing
 Quadratic probing
 Double hashing
Chapter 10 – Sets

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.

2. Define disjoint set.


It is an efficient data structure to solve the equivalence problem. Each routine requires only a few
lines of code, and a simple array can be used. The implementation is also extremely fast,
requiring constant average time per operation.

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.

4. Define path compression.


Path compression is performed during a find operation and is independent of the strategy used to
perform unions. Suppose the operation is find(x). Then the effect of path compression is that
every node on the path from x to the root has its parent changed to the root.

5. Define Smart Union Algorithms.


The unions above were performed rather arbitrarily, by making the second tree a sub tree of the
first. A simple improvement is always to make the smaller tree a sub tree of the larger, breaking
ties by any method; we call this approach union by- size.

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.

2. Define adjacent nodes.

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.

4. What are the representations of graphs?


 Adjacency Matrix
 Adjacency list

5. Define Adjacency Matrix Representation.


An adjacency matrix of a graph G=(V,E) (let V = { v 1 , v 2 ....., v n}) is a n X n matrix A,
such that
A [i, j] = 1 if there is edge between vi and v j.
0 other wise

6. Define Adjacency List Representation


It consists of a list of vertices, which can be represented either by linked list or array. For each
vertex, adjacent vertices are represented in the form of a linked list.
An example is given below.

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.

7. What is a directed and undirected graph?


A graph in which every edge is directed is called a directed graph. A graph in which every edge
is undirected is called a directed graph.

8. What is a weighted graph?


A graph in which weights are assigned to every edge is called a weighted graph.

9. Define in degree and out degree of a graph?


In a directed graph, for any node v, the number of edges which have v as their terminal node is
called the indegree of the node v. In a directed graph, for any node v, the number of edges which
have v as their initial node is called the out degree of the node v.

10. What is a cycle or a circuit? Define acyclic graph.


A path which originates and ends in the same node is called a cycle or circuit.
A simple diagram which does not have any cycles is called an acyclic graph.

11. What is DAG?


A directed graph is acyclic if it has no cycles. A directed acyclic graph is sometimes referred to
by its abbreviation, DAG.

75
Appendix A – Two Mark Question Bank

12. What is a forest?


A forest may be defined as an acyclic graph in which every node has one or no predecessors. A
tree may be defined as a forest in which only a single node called root has no predecessors

13. Define topological sort.


• Topological sort is a method of arranging the vertices in a directed acyclic graph (DAG), as
a sequence, such that no vertex appears in the sequence before its predecessor.
• Topological sort is not unique.

14. What are the types of graph traversals?


 Depth First Search (DFS)
 Breadth First Search (BFS)

15. Define DFS.


Depth-first search (DFS) is an algorithm for traversing or searching a tree, tree structure, or
graph. Intuitively, one starts at the root (selecting some node as the root in the graph case) and
explores as far as possible along each branch before backtracking.

16. Define BFS.


Breadth-first search (BFS) is a graph search algorithm that begins at the root node and explores
all the neighboring nodes. Then for each of those nearest nodes, it explores their unexplored
neighbor nodes, and so on, until it finds the goal.

17. What are the advantages of DFS?


 The advantage of depth-first Search is that memory requirement is only linear with
respect to the search graph. This is in contrast with breadth-first search which requires
more space. The reason is that the algorithm only needs to store a stack of nodes on the
path from the root to the current node.
 The time complexity of a depth-first Search to depth d is O(b^d) since it generates the
same set of nodes as breadth-first search, but simply in a different order. Thus practically
depth-first search is time-limited rather than space-limited.
 If depth-first search finds solution without exploring much in a path then the time and
space it takes will be very less.

18. What are the disadvantages of DFS?


 The disadvantage of Depth-First Search is that there is a possibility that it may go down
the left-most path forever. Even a finite graph can generate an infinite tree. One solution
to this problem is to impose a cutoff depth on the search. Although the ideal cutoff is the

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.

19. Compare DFS and BFS.

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

20. Define connected graph.


An undirected graph is connected if there is a path from every vertex to every other vertex

21. Define strongly connected graph.


An directed graph is connected if there is a path from every vertex to every other vertex

22. Define weekly connected graph.


If a directed graph is not strongly connected but the underlying graph is connected then the graph
is said to be called weekly connected graph

23. Define minimum spanning tree.


77
Appendix A – Two Mark Question Bank

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

25. Define prim’s algorithm


Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected
weighted undirected graph. This means it finds a subset of the edges that forms a tree that
includes every vertex, where the total weight of all the edges in the tree is minimized.

26. Define kruskal’s algorithm.


Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a
connected weighted graph. This means it finds a subset of the edges that forms a tree that
includes every vertex, where the total weight of all the edges in the tree is minimized. If the
graph is not connected, then it finds a minimum spanning forest (a minimum spanning tree for
each connected component). Kruskal's algorithm is an example of a greedy algorithm.

27. Define dijkstra’s algorithm (single source shortest path problem).


Dijkstra's algorithm, is a graph search algorithm that solves the single-source shortest path
problem for a graph with nonnegative edge path costs, producing a shortest path tree.

28. What are the applications of graph?


 Undirected graph
 Bi connectivity
 Euler circuits
 Directed graph finding strong components

29. Define euler circuits.

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.

30. Define articulation points.


Articulation points or cut vertices are vertices whose removal increases the number of connected
components in a graph.

31. Define biconnected component.


A graph is bi connected if the removal of any single vertex (and its adjacent edges) does not
disconnect it. A biconnected component of a graph is a maximal bi connected sub graph of it.
The biconnected components of a graph can be given by the partition of its edges: every edge is a
member of exactly one biconnected component. Note that this is not true for vertices: the same
vertex can be part of many biconnected components.

32. What is NP?


NP is the set of all decision problems (question with yes-or-no answer) for which the 'yes'-
answers can be verified in polynomial time where n is the problem size, and k is a constant) by a
deterministic Turing machine. Polynomial time is sometimes used as the definition of fast or
quickly.

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.

34. What is NP-Complete?


A problem x that is in NP is also in NP-Complete if and only if every other problem in NP can be
quickly (ie. in polynomial time) transformed into x. In other words:
 x is in NP, and
 Every problem in NP is reducible to x

35. What is NP-Hard?


NP-Hard are problems that are at least as hard as the hardest problems in NP. Note that NP
Complete problems are also NP-hard. However not all NP-hard problems are NP (or even a
Decision problem), despite having 'NP' as a prefix. That is the NP in NP-hard does not mean 'non
deterministic polynomial time'.
Chapter 12 – Sorting

79
Appendix A – Two Mark Question Bank

1. Define sorting.
Sorting is the process of arranging the elements in ascending or descending order.

2. What are the types of sorting?


 Internal sorting
o Insertion Sort
o Shell Sort
o Heap Sort
o Merge Sort
o Quick Sort
o Indirect Sort
o Bucket Sort
 External Sorting

3. Define Insertion Sort.


It works the way you might sort a hand of playing cards:
1. We start with an empty left hand [sorted array] and the cards face down on the table
[unsorted array].
2. Then remove one card [key] at a time from the table [unsorted array], and insert it into
the correct position in the left hand [sorted array].
3. To find the correct position for the card, we compare it with each of the cards already in
the hand, from right to left.

4. Define Shell Sort.


 Shell sort works by comparing elements that are distant rather than adjacent elements in
an array or list where adjacent elements are compared.
 Shell sort uses a sequence h1, h2, …, ht called the increment sequence. Any increment
sequence is fine as long as h1 = 1 and some other choices are better than others.
 Shell sort makes multiple passes through a list and sorts a number of equally sized sets
using the insertion sort.
 Shell sort improves on the efficiency of insertion sort by quickly shifting values to their
destination.

5. Define Heap Sort.


Step I: The user inputs the size of the heap(within a specified limit).The program generates a
corresponding binary tree with nodes having randomly generated key Values.
Step II: Build Heap Operation: Let n be the number of nodes in the tree and i be the key of a tree.
For this, the program uses operation Heapify. When Heapify is called both the left and right sub
tree of the i are Heaps. The function of Heapify is to let i settle down to a position(by swapping
itself with the larger of its children, whenever the heap property is not satisfied)till the heap
80
Appendix A – Two Mark Question Bank

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

6. Define Merge Sort.


A merge sort works as follows
1. Divide the unsorted list into n sub lists, each containing 1 element (a list of 1 element is
considered sorted).
2. Repeatedly merge sub lists to produce new sub lists until there is only 1 sub list
remaining. (This will be the sorted list.)

7. Define Quick Sort.


Quicksort is a divide and conquer algorithm. Quicksort first divides a large list into two smaller
sub-lists: the low elements and the high elements. Quicksort can then recursively sort the sub-
lists.
The steps are:
1. Pick an element, called a pivot, from the list.
2. Reorder the list so that all elements with values less than the pivot come before the pivot,
while all elements with values greater than the pivot come after it (equal values can go
either way). After this partitioning, the pivot is in its final position. This is called the
partition operation.
3. Recursively sort the sub-list of lesser elements and the sub-list of greater elements.

8. Define Indirect Sort.


 When records are large, swapping is very expensive.
 We can minimize the cost by using an indirect sort.
 One method is to create a new file whose records contain the key field of the original file,
and either a pointer to or index of the original records.
 We sort the new file, whose records are small, and then access the original file using the
pointers/indices.

9. Define Bucket Sort.


Bucket sort, or bin sort, is a sorting algorithm that works by partitioning an array into a number
of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or
by recursively applying the bucket sorting algorithm.
Bucket sort works as follows:
81
Appendix A – Two Mark Question Bank

 Set up an array of initially empty "buckets."


 Scatter: Go over the original array, putting each object in its bucket.
 Sort each non-empty bucket.
 Gather: Visit the buckets in order and put all elements back into the original array.

10. What are the time complexities of various sorting method?

Sorting Best Case Average Case Worst Case


2 2 2
Bubble Sort n n n
Insertion Sort n n n2
Selection Sort n2 n2 n2
Shell Sort n n(logn)2 n(logn)2
Heap Sort nlogn nlogn nlogn
Merge Sort nlogn nlogn nlogn
Quick Sort nlogn nlogn n2
Bucket Sort O(n+k) O(n+k) O(n2)
Chapter 13 – Algorithm Design Techniques

1. What are the two factors to measure the efficiency of an algorithm?


Time efficiency-> The amount of time to take execute the algorithm’s basic operation
Space efficiency-> The amount of memory required to store the algorithm and the amount of
memory required to store the input for that algorithm.

2. How to measure the running time of an algorithm?


• Find the basic operation of the algorithm.
• Compute the time required to execute the basic operation.
• Compute how many times the basic operation is executed. The Time complexity calculated by
the following formula
T(n) = Cop * C(n) Where,
Cop – Constant (The amount of time required to execute the basic operation)
C(n) – How many times the basic operation is executed.
3. How does greedy algorithm works?
Greedy algorithm works in phases. In each phase, a decision is made that
appears to be good, without regards for future consequences. This means that some local
optimum is chosen.

4. Define greedy algorithm.

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.

5. What are the applications of greedy method?


 Scheduling Problem
 Huffman Codes
 Approximate Bin packing
 Optimal Storage on tapes
 Minimum Spanning Tree
 Finding Shortest Path

6. What are the different versions of bin packing?


 Online algorithm.
o Next fit
o First fit
o Best fit
 Offline algorithm.

7. Define next fit, first fit and best fit algorithms.


Next Fit: When processing any item, check whether it fits in the same bin as last bin. If it does,
place there; otherwise, a new bin created.
First Fit: Scan the bins in order and place the new item in the first bin that is large enough to
hold it.
Best Fit: Instead of placing a new item in the first spot that is found, it is placed in the tightest
spot among all bins.

8. What do you mean by divide and conquer?


The divide-and-conquer strategy solves a problem by:
 Breaking it into sub problems that are themselves smaller instances of the same type.
 Recursively solving these sub problems
 Appropriately combining their answers
9. Write the examples of Divide and Conquer.
 Closest points problem
 Binary Search
 Quick Sort
 Merge Sort

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

11. Differentiate divide and conquer & Greedy Algorithm.

Divide and Conquer Greedy Algorithm


It is used to obtain a solution to give problem. It is used to obtain optimum solution.
The problem is divided into small sub problems. A set of feasible solution is generated and
These problems are solved independently. optimum solution is picked up.
Finally all the solutions of sub problems are
collected together to get the solution to the
given problem.
Duplications in sub solutions are neglected, The optimum selection is without revising
which means that duplicate solutions may be previously generated solutions.
obtained.
Less efficient because of rework on solutions Greedy method is comparatively efficient but
there is no as such guarantee of getting
optimum solution.
Examples: Quick sort, binary search Example: Minimum spanning tree, finding
shortest path.

12. Define dynamic programming.


Dynamic programming is a method for efficiently solving a broad range of search and
optimization problems which exhibit the characteristics of overlapping sub problems and optimal
substructure.

13. What are the applications of dynamic programming?


 All pairs shortest path problem (Floyd’s algorithm)
 Optimal Binary Search Tree
 Multistage Graph

14. Differentiate divide and conquer & dynamic programming.

84
Appendix A – Two Mark Question Bank

Divide and Conquer Dynamic programming


The divide-and-conquer strategy solves a Dynamic programming is a method for
problem by breaking it into sub problems that efficiently solving a broad range of search and
are themselves smaller instances of the same optimization problems which exhibit the
type of problem, recursively solving these sub characteristics of overlapping sub problems
problems and appropriately combining their and optimal substructure
answers.
Top down approach Bottom up approach
Less efficient More efficient
Duplicate solutions may be obtained Duplicate solutions is avoided totally
It splits input at specific deterministic points It splits input at every possible split points
usually in the middle rather than at a particular point

15. Differentiate Greedy and dynamic programming.

Greedy method Dynamic programming


It is used for getting optimal solutions. It is also used for getting optimal solutions.
A set of feasible solutions and picks up the No special set of feasible solutions
optimal solution
Solution is generated without revising It considers all possible sequences in order to
previously generated solutions obtain the optimal solution
No guarantee of getting optimal solution Guaranteed to generate optimal solution

16. Define backtracking.


Backtracking is a process of searching the solution to the problem by searching the solution
space (the set of all feasible solutions) for the given problem. Backtracking is a process where
steps are taken towards the final solution and the details are recorded. If these steps do not lead
to a solution some or all of them may have to be retraced and the relevant details discarded.

17. Name any four methods of backtracking.


 N-queen problem
 Subset sum problem
 Graph coloring
 Turnpike Reconstruction problem

18. What is state space tree?


The tree organization of the solution space by implementing the backtracking method for any
problem is defined as state space tree. Each node in the state space tree defines problem state.
85
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

19. Define promising and non-promising node.


A node in the state space tree is promising if it corresponds to the partials constructed solution
that may lead to the complete solution otherwise the nodes are called non-promising. Leaves of
the tree represent either the non- promising dead end or complete solution found by the
algorithm.

20. Define pruning.


The elimination of a large group of possibilities in one step is known as pruning.

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.

22. What is a Hamiltonian circuit?


A Hamiltonian circuit in a graph is the path that starts and ends at the same vertex and passes
through all the other vertices exactly once.

23. What is a feasible solution and optimal solution?


A feasible solution is a point in the problem’s state-space that satisfies all the problem’s
constraints.
An optimal solution is a feasible solution, with the best value of the objective function.

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}.

26. Comparison of Greedy algorithm and Backtracking.

Greedy method Backtracking


Greedy method is an approach to find the Backtracking is a process of searching the
optimized solutions for the given problem. The solution to the problem by searching the
solutions are constructed through a sequence of solution space (the set of all feasible solutions)
steps, each step expanding a partially for the given problem. Backtracking is a
constructed solution so far, until a complete process where steps are taken towards the final
solution to the problem is reached. solution and the details are recorded.

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

27. Define branch and bound algorithm.


A B&B algorithm searches the complete space of solutions for a given problem for the best
solution.
Ø Branch and bound is a systematic method for solving optimization problems
Ø B&B is a rather general optimization technique that applies where the greedy method and
dynamic programming fail.
Ø However, it is much slower.
Ø On the other hand, if applied carefully, it can lead to algorithms that run reasonably fast on
average.
Ø The general idea of B&B is a BFS-like search for the optimal solution, but not all nodes get
expanded (i.e., their children generated). Rather, a carefully selected criterion determines which
node to expand and when, and another criterion tells the algorithm when an optimal solution has
been found.

28. Give the examples for branch and bound algorithm.

87
Appendix A – Two Mark Question Bank

 0/1 Knapsack problem


 Traveling Salesman problem

29. What is Knapsack problem? How it could be solved by branch-and-bound problems?


There are n items of known weights w1,w2..wn and the values are v1,v2..vn. The capacity of
Knapsack is W. Find the most valuable subset of items, that fit into knapsack.
· To solve branch-and-bound problem, the steps are:
· Order the items given in descending order, by their value-to-weight ratios.
· Construct the state-space tree as binary tree. Each node on ith level indicate inclusion of item to
the set, if the node is left child, otherwise exclusion of the item.

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.

31. Comparison of Backtracking and Branch & Bound Algorithm.

Backtracking Branch and Bound


It is used to find all possible solutions available It is used to solve optimization problem.
to the problem.
It traverse tree by Depth First Search. It may traverse the tree either by DFS or BFS.
It realizes that it has made a bad choice and It realizes that it already has a better optimal
undoes the last choice by backing up. solution that the pre-solution leads to.
It search the state space tree until a solution is It completely searches the state space tree to
found. get optimal solution
It involves feasibility function. It involves bounding function

32. Name the three asymptotic Notations.


(i) Big Oh
(ii) Big Omega
(iii) Big Theta

33.. Define Big-Oh (or) O Notation.

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.

34. Define Big-Omega (or) Ω Notation.


A function t(n) is said to be in Ω (g(n)), denote t(n) € Ω (g(n)), if t(n) is bounded below 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.

35. Define Big Theta (or) θ Notation


A function t(n) is said to be in θ (g(n)), denote t(n) € θ(g(n)), if t(n) is bounded both above and
below by some constant multiple of g(n) for all large n, i.e., if there exists some positive constant
c1 and c2 and some nonnegative integer n0 such that
c2.g(n) ≤ t(n) ≥ c1.g(n) for all n ≥ n0.

89
Appendix A – Two Mark Question Bank

36. Name some basic efficiency classes.


(i) O(1) (ii)O(n) (iii) O(logn) (iv) O(n logn)
2
(v) O(n ) (vi) O(n3) (vii) O(2n)

37. Define randomized algorithm.


An algorithm takes a source of random numbers and makes random choices during execution in
addition to the input. Behavior can vary even on a fixed input.

38. Define recurrence.


A recurrence is an equation or inequality that describes a function in terms of its value on smaller
inputs. E.g.: running time of merge sort.

39. What are the various methods for solving recurrence?


 Substitution method.
 Recursion tree.
 Master method.

40. What is halting problem?


The problems that are harder to solve or impossible to solve are classified as undecidable
problems. One of the undecidable problems is the halting problem.

90

You might also like