Professional Documents
Culture Documents
Vadakkangulam
Prepared By,
ANON K. JENIFER, Lecturer/CSE
15. What is the explicit formula for the nth Fibonacci number?
The formula for the nth Fibonacci number is given by
F(n)= 1/5(n - n)
Where
=(1+5)/2
=(1-5)/2
16. Define Data Structures
Data Structures is defined as the way of organizing all data items that consider not
only the elements stored but also stores the relationship between the elements.
17. Define Linked Lists
Linked list consists of a series of structures, which are not necessarily adjacent in
memory. Each structure contains the element and a pointer to a structure containing its
successor. We call this theNext Pointer. The last cellsNext pointer points to NULL.
18. State the different types of linked lists
The different types of linked list include singly linked list, doubly linked list and
circular linked list.
11. List the basic operations carried out in a linked list
The basic operations carried out in a linked list include:
Creation of a list
Insertion of a node
Deletion of a node
Modification of a node
Traversal of the list
19. List out the advantages of using a linked list
It is not necessary to specify the number of elements in a linked list during its
declaration
Linked list can grow and shrink in size depending upon the insertion and deletion
that occurs in the list
Insertions and deletions at any place in a list can be handled easily and efficiently
A linked list does not waste any memory space
20. List out the applications of a linked list
Some of the important applications of linked lists are manipulation of
polynomials, sparse matrices, stacks and queues.
21. State the difference between arrays and linked lists
Arrays
Linked Lists
Size of an array is fixed
Size of a list is variable
It is necessary to specify the
It is not necessary to specify the
number of elements during
number of elements during
declaration.
declaration
place X in its correct spot along a path from the root containing minimum children. This
general strategy is known as percolate down.
15. What is meant by Implicit Heaps?
A particularly simple and beautiful implementation of the heap structure is the
implicit heap. Data is simply put into an array
and the childrens of
element x[i] are defined to be the elements x[2i] and x[2i+1]. Thus the parent of the
element c can be found at c/2 (integer division).
16.What is a skew heap?
A heap data structure that is stored in a binary tree (not necessarily complete and
balanced). The insertion and deletion of elements in the tree come from merging two
skew heaps together in such a way that the heap property is preserved and the tree does
not degrade to a linear tree.
17. How to merging 2 skew heaps?
Suppose we are merging a heap containing the elements 2, 5, and 7 with a heap
containing the elements 4 and 6.
7 <- merge -> 6
/\
/
5 2
4
i. Identify the root, thus 7 becomes the new root and the left
subtree of the heap with root 7 becomes the right subtree of
the other heap:
7
2 <- merge -> 6 (to form the left subtree
\
/ of the new skew heap)
5
4
ii.
7
/\
6 5
\
4 <- merge -> 2
iii.
7
/\
6 5
/\
2 4
serves as the root of a subtree with keys between K1 & K2 and the rightmost child serves
as the root of a subtree with keys greater than K2. The last requirement of 2-3 trees is that
all its leaves must be on the same level, a 2-3 tree is always height balanced. 2-3 trees
were introduced by John Hopcroft in 1970.
14. What do you mean by 2-3-4 tree?
A B-tree of order 4 is called 2-3-4 tree. A B-tree of order 4 is a tree that is not
binary with the following structural properties:
The root is either a leaf or has between 2 and 4 children.
All non-leaf nodes (except the root) have between 2 and 4 children.
All leaves are at the same depth.
14. Define B-tree of order M.
A B-tree of order M is a tree that is not binary with the following structural
properties:
The root is either a leaf or has between 2 and M children.
All non-leaf nodes (except the root) have between M/2 and M children.
All leaves are at the same depth.
15. What are the applications of B-tree?
Database implementation
Indexing on non primary key fields
iii. Zig-Zag: If p is not the root, p is the left child and v is a right child, perform a
left-right rotation at g and bring v as an ancestor of p as well as g.
20. Define brute force string matching.
The brute force string matching has a given string of n characters called the text
and a string of m characters called the pattern, find a substring of the text that matches the
pattern. And find the index I of the leftmost character of the first matching substring in
the text.
21. What are the advantages of brute force technique?
The various advantages of brute force technique are
i. Brute force applicable to a very wide variety of problems. It is used for many
elementary but important algorithmic tasks
ii.For some important problems this approach yields reasonable algorithms of at
least some practical value with no limitation on instance size
iii.The expense to design a more efficient algorithm may be unjustifiable if only a
few instances of problems need to be solved and a brute force algorithm can solve
those instances with acceptable speed
iv. Even if inefficient in general it can still be used for solving small-size instances
of a problem
v. It can serve as a yardstick with which to judge more efficient alternatives for
solving a problem
22. What are the properties of binary heap?
i) Structure Property
ii) Heap Order Property
(ndlog n) if a=bd
(nlogba) if a>bd
The efficiency analysis of many divide-and-conquer algorithms are greatly simplified by
the use of Master theorem.
3. What is the general divide-and-conquer recurrence relation?
An instance of size n can be divided into several instances of size n/b, with a
of them needing to be solved. Assuming that size n is a power of b, to simplify the
analysis, the following recurrence for the running time is obtained: T(n) = aT(n/b)+f(n)
Where f(n) is a function that accounts for the time spent on dividing the problem into
smaller ones and on combining their solutions.
4. What is decrease and conquer approach and mention its variations?
The decrease and conquer technique based on exploiting the relationship between
a solution to a given instance of a problem and a
solution to a smaller instance of the same problem. The three major variations are
Decrease by a constant
Decrease by a constant-factor
Variable size decrease
5. What is a tree edge and back edge?
In the depth first search forest, whenever a new unvisited vertex is reached for
the first time, it is attached as a child to the vertex from which it is being reached. Such
an edge is called tree edge because the set of all such edges forms a forest. The algorithm
encounters an edge leading to a previously visited vertex other than its immediate
predecessor. Such an edge is called a back edge because it connects a vertex to its
ancestor, other than the parent, in the depth first search forest.
DFS
Backtracking is possible from a
dead end
Vertices from which exploration is
incomplete are processed in a
LIFO
Searchorder
is done in one particular
Direction
BFS
Backtracking is not possible
The vertices to be explored are
organized as a
FIFO
queue in the same level are
The vertices
maintained
parallely
tuple as its (I+1)st coordinate. If such an element does not exist, the algorithm backtracks
to consider the next value of xi, and so on.
15. Give a template for a generic backtracking algorithm.
ALGORITHM
Backtrack
(X[1..i]) //Gives a template of a generic backtracking algorithm //Input X[1..i]
specifies the first I promising components of a solution //Output All the tuples
representing the problems solution if X[1..i] is a solution write X[1..i] else for each
element x[Si+1 ]consistent with X[1..i] and the constraints do X[i+1] x
Backtrack(X[1..i+1]
16. Write a recursive algorithm for solving Tower of Hanoi problem. ALGORITHM
To move n>1 disks from peg1 to peg3, with peg2 as auxiliary, first move
recursively n-1 disks from peg1 to peg2 with peg3 as auxiliary.
Then move the largest disk directly from peg1 to peg3
Finally move recursively n-1 disks from peg2 to peg3 with peg1 as
auxiliary
If n=1 simply move the single disk from source peg to destination peg.
17. What is the basic operation in the Tower of Hanoi problem and give the
recurrence relation for the number of moves?
The moving of disks is considered the basic operation in the Tower of Hanoi
problem and the recurrence relation for the number of moves is given as M(n)=2M(n)+1
for n>1 M(1)=1
18. What is n-queens problem?
The problem is to place n queens on an n-by-n chessboard so that no two
queens attack each other by being in the same row or in the column or in the same
diagonal.
19Define the Hamiltonian circuit.
The Hamiltonian is defined as a cycle that passes through all the vertices of the
graph exactly once. It is named after the Irish mathematician Sir William Rowan
Hamilton (1805-1865).It is a sequence of n+1 adjacent vertices vi0, vi1,, vin-1, vi0
where the first vertex of the sequence is same as the last one while all the other n1 vertices are distinct.
20. What is the method used to find the solution in n-queen problem by symmetry?
The board of the n-queens problem has several symmetries so that some solutions
can be obtained by other reflections. Placements in the last n/2 columns need not be
considered, because any solution with the first queen in square (1,i), n/2in can be
obtained by reflection from a solution with the first queen in square (1,n-i+1)
21. What are the additional features required in branch-and-bound when compared
to backtracking?
Compared to backtracking, branch-and-bound requires:
i.A way to provide, for every node of a state space tree, a bound on the best value
of the objective function on any solution that can be obtained by adding further
components to the partial solution represented by the node.
ii.The value of the best solution seen so far
22. What is knapsack problem?
Given n items of known weights wi and values vi, i=1,2,,n, and a knapsack of capacity
W, find the most valuable subset of the items that fit the knapsack. It is convenient to
order the items of a given instance in descending order by their value-to-weight ratios.
Then the first item gives the best payoff per weight unit and the last one gives the worst
payoff per weight unit.
23. Give the formula used to find the upper bound for knapsack problem.
A simple way to find the upper bound ub is to add v, the total value of the
items already selected, the product of the remaining capacity of the knapsack W-w and
the best per unit payoff among the remaining items, which is v
i+1/wi+1 ub = v + (W-w)( vi+1/wi+1)
24. What is the traveling salesman problem?
The problem can be modeled as a weighted graph, with the graphs vertices
representing the cities and the edge weights specifying the distances. Then the problem
can be stated as finding the shortest Hamiltonian circuit of the graph, where the
Hamiltonian is defined as a cycle that passes through all the vertices of the graph exactly
once.
25. What are the strengths of backtracking and branch-and-bound?
The strengths are as follows
i.It is typically applied to difficult combinatorial problems for which no efficient
algorithm for finding exact solution possibly exist
ii.It holds hope for solving some instances of nontrivial sizes in an acceptable
amount of time
iii.Even if it does not eliminate any elements of a problems state space and ends
up generating all its elements, it provides a specific technique for doing so, which can be
of some value.