daa two mark - vidyarthiplus

22
DAA TWO MARK QUESTION AND ANSWER 1 UNIT 1 1. Define Algorithm. An algorithm is a sequence of unambiguous instructions for solving a problem, which means to obtain a required output for any legitimate input in a finite amount of time. 2. What are the characteristics of an algorithm? Simplicity Generality Definiteness Finiteness Effectiveness 3. What are three parts of algorithm? Pre Condition Body of Algorithm Post Condition 4. What are the criteria used to identify the best algorithm? Order Of Growth Time Complexity Space Complexity 5. Define time and space complexity. Time Complexity indicates how fast an algorithm runs. T(P)=Compile Time+ Run Time .(Tp) Where Tp is no of add, sub, mul... Space Complexity indicates how much extra memory the algorithm needs. Basically it has three components. They are instruction space, data space and environment space. 6. Difference between Compile and Running Time. Compile Time Running Time 1)"Compile time" can also refer to the amount of time required for compilation. 2) The operations performed at compile time usually include syntax analysis, various kinds of semantic analysis and code generation 3) Compile time occurs before link time (when the output of one or more compiled files are joined together) and runtime 1)“Running Time” can refer to the time required for executing the program 2)Type checking, storage allocation, and even code generation and code optimization may be done at compile-time or upon a run-time, depending on the language and compiler. 3) Running time occurs after compile time. TechReg-Edu

Upload: others

Post on 28-Apr-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 1

UNIT 1

1. Define Algorithm.

An algorithm is a sequence of unambiguous instructions for solving a problem,

which means to obtain a required output for any legitimate input in a finite amount of

time.

2. What are the characteristics of an algorithm?

• Simplicity

• Generality

• Definiteness

• Finiteness

• Effectiveness

3. What are three parts of algorithm?

• Pre Condition

• Body of Algorithm

• Post Condition

4. What are the criteria used to identify the best algorithm?

• Order Of Growth

• Time Complexity

• Space Complexity

5. Define time and space complexity.

Time Complexity indicates how fast an algorithm runs.

T(P)=Compile Time+ Run Time .(Tp)

Where Tp is no of add, sub, mul...

Space Complexity indicates how much extra memory the algorithm needs. Basically

it has three components. They are instruction space, data space and environment

space.

6. Difference between Compile and Running Time.

Compile Time Running Time

1)"Compile time" can also refer to the

amount of time required for compilation.

2) The operations performed at compile

time usually include syntax analysis,

various kinds of semantic analysis and

code generation

3) Compile time occurs before link time

(when the output of one or more compiled

files are joined together) and runtime

1)“Running Time” can refer to the time

required for executing the program

2)Type checking, storage allocation, and

even code generation and code

optimization may be done at compile-time

or upon a run-time, depending on the

language and compiler.

3) Running time occurs after compile

time.

TechR

eg-E

du

Page 2: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 2

7. Find the time complexity for summation of N numbers.

The time complexity for summation of N numbers is O (N).

8. What are the various types of time complexity of an algorithm?

• Big Oh

• Big Omega

• Big Theta

• Little Oh

• Little Omega

9. Difference between Best Case and Worst Case Complexities.

The best case complexity of an algorithm is its efficiency for the best case input of

size N, which is an input of size N for which the algorithm runs fastest among all

possible inputs of that size.

The worst case complexity of an algorithm is its efficiency for the worst case input

of size N, which is an input of size N for which the algorithm runs longest among all

possible inputs of that size.

10. What is the Space Complexity for the following algorithm?

Void N()

Int P,A,B,C; P=A+B-C; Printf(“%D”,P);

Space Complexity = Space Needed For P,A,B,C = 8 11. Define asymptotic notation. The efficiency analysis framework concentrates on the order of growth of an algorithm’s basic operation count as the principle indicator of the algorithm’s Efficiency. To compare and rank such orders of growth scientists’ use three notations (Big Oh, Big Omega, and Big Theta, which is called as asymptotic notation. 12. What are the 3 standard notations? a) Big Oh(O) b) Big Omega(Ω)

c) Big Theta( )

TechR

eg-E

du

Page 3: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 3

13. Define Big-Oh. A function T(N) is said to be in O(G(N)),denoted T(N)€ O(G(N)), If T(N) is bounded above by some constant multiple of G(N) for all large N, if there exists some positive constant C and some non negative integer N0 such that T (N) <= C.G (N) For All N>=N0

14. Define Conditional Asymptotic Notation. Let F be an eventually nonnegative sequence of real numbers and Let X be a set. The

function O(F|X) yields a non empty set of functions from N to R and is defined as follows:

O(F|X) = T; T Ranges Over Elements Of RN: Vc,N (C > 0 Vn (N ≥ N N X T(N) ≤

C* F(N) T(N) ≥ 0)).

15. Define Smoothness Rule.

Let F (N) be a nonnegative function defined on the set of natural numbers. F(N) is called Smooth If it is eventually non decreasing and F(2n) Θ (F(N)).

Let T(N) be an eventually a non decreasing function and F(N) be a smooth function. If

T(N) Θ (F(N)) For Values Of N That Are Powers Of B,

Where B>=2, Then

T (N) Θ (F(N)) For Any N.

16. What Are The Common Running Time For Big-Oh. The common running time for Big-Oh Are

• O(N) • O(Log N) • O(N Log N) • O(N^C),C>1

17. Define Recurrence Relation.

The equation defines M (N) not explicitly, ie.., is a function of n, but implicitly as a function of its value at another point, namely N-1. Such equations are called recurrence relation.

18. What are all the types of recurrence relation?

• Geometric sequence • Arithmetic sequence • Linear sequence

TechR

eg-E

du

Page 4: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 4

19. Define Linear Search. In computer science, linear search or sequential search is a method for finding a particular value in a list, which consists in checking every one of its elements, one at a time and in sequence, until the desired one is found.

20. What are the Best, Worst and Average Case complexity of Linear Search?

• Best Case – O(1) • Average Case – O(N) • Worst Case – O(N)

21. Define Little Oh and Little Omega Notations.

The relation is read as "f(x) is little-o of g(x)". Intuitively, it means that g(x) grows much faster than f(x). It assumes that f and g are both functions of one variable. Formally, it states

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))".

22. Define Substitution Method.

Substitution method is a method of solving a system of equations wherein one of the equations is solved for one variable in terms of the other variables.

23. Give Master Theorem.

Let T(n) be a monotonically increasing function that satisfies T(n) = aT(n/b ) + f(n) T(1) = c where a ≥ 1, b ≥ 2, c > 0. If f(n)ε O(n^d) where d ≥ 0, then O(n^d) if a < b^d T(n) = O(n^d log n) if a = b^d O(n^logb a) if a > b^d

24. Give the general plan for analyzing recursive algorithm.

• Decide a parameter indicating an Input’s Size. • Identify the algorithms Basic Operation • Check whether the number of times the basic operation is executed only on the

size of an input. If it also depends on some additional property, the worst case, average case, and if necessary, best case efficiencies have to be investigated separately.

• Set up a recurrence relation, with an appropriate initial condition, for the number of times basic operation is executed.

TechR

eg-E

du

Page 5: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 5

25. Give the general plan for analyzing non recursive algorithm.

• Decide a parameter indicating an Input’s Size. • Identify the algorithms Basic Operation • Check whether the number of times the basic operation is executed only on the

size of an input. If it also depends on some additional property, the worst case, average case, and if necessary, best case efficiencies have to be investigated separately.

• Using standard formulas and rules of sum manipulation either find a closed formula for the count or, at the very least, establish its order of growth.

27. Define Data Space, Instruction Space and Environment Space.

• Data Space: The space needed to store all constants and variable values.

• Instruction Space: The space needed to store the compiled version of all program instruction

• Environment Space: The environment stack is used to save information needed

to resume execution of partially completed functions. Each time a function is invoked the following data are saved the environment stack.

o The return address. o The values of all local variables.

29. What are all the methods available for solving recurrence relations?

• Forward Substitution • Backward Substitution • Smoothness Rule • Master Theorem

30. Write down the problem types.

• Sorting • Searching • String Processing • Graph Problem • Combinational Problem • Geometric Problem • Numerical Problem

31. What are the types of recurrence relations?

• Homogeneous recurrence relation. • Non homogeneous recurrence relation.

34. Define Order Of Growth. An order of growth of an algorithm is a set of functions whose asymptotic growth behavior is considered equivalent to the given algorithm. For example, 2n, 100n and n + 1 belong to the same order of growth, which is written O(n) in “Big-Oh notation” and often called “linear” because every function in the set grows linearly with n.

TechR

eg-E

du

Page 6: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 6

UNIT 2

1. What is the order of an algorithm?

A standard notation used to represent the computing time of the algorithm is termed as the order of an algorithm and is denoted by O.

2. What are the objectives of sorting algorithms?

The objective of the sorting algorithm is to rearrange the records so that their keys are ordered according to some well-defined ordering rule.

3. What is meant by optimal solution?

A solution to an optimization problem which minimizes (or maximizes) the objective function is termed as an optimal solution. An optimization problem is a computational problem in which the object is to find the best of all possible solutions. More formally, find a solution in the feasible region which has the minimum (or maximum) value of the objective function.

5. Find the number of comparisons made by the sequential search in the worst case and the best case.

The number of comparisons made by the sequential search in the worst and best case are one and n key comparisons respectively.

6. Define a knapsack problem.

The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most useful items.

7. Define divide and conquer strategy.

Divide and conquer (D&C) is an important algorithm design paradigm based on multi-branched recursion. A divide and conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem.

8. Give some examples of divide and conquer method.

Some of the examples of D&C method are binary search, Euclidean algorithm, Cooley-Tukey fast Fourier transform (FFT) algorithm and merge sort algorithm.

TechR

eg-E

du

Page 7: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 7

9. Write control abstraction for D&C technique.

The control abstraction for D&C technique is as follows:

Procedure D&C (P,Q) //the data size is from p to q If size(P,Q) is small Then Solve(P,Q) Else M ¬ divide(P,Q) Combine (D&C(P,M), D&C(M+1,Q))

Sometimes, this type of algorithm is known as control abstract algorithms as they give an abstract flow. This way of breaking down the problem has found wide application in sorting, selection and searching algorithm.

10. Advantages of binary search.

Binary search is a fast way to search a sorted array. The idea is to look at the element in the middle. If the key is equal to that, the search is finished. If the key is less than the middle element, do a binary search on the first half. If it's greater, do a binary search of the second half.

11. What are all the advantages of Binary search?

The Binary search is an optimal searching algorithm using us can search the desired element effectively.

Applications:

The binary search is an efficient searching method & is used to search desired record from database.

For solving nonlinear equations with one unknown this method is used.

12. What is the time complexity of binary search?

Best Case Average Case Worst Case

O(1) O(log2n) O(log2n)

13. What is the time complexity of straight forward with D & C of finding Min-max?

• Best case occurs when the elements are in increasing order, so the number of element comparisons is n-

• Worst case occurs when the elements are in decreasing order, so the number of element comparisons is 2(n-1).

• Average case occurs when a[i] is greater than max half the time.

TechR

eg-E

du

Page 8: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 8

14. Define greedy technique:

The greedy method is the most straight forward design technique that can be applied to a wide variety of problems.

15. Define feasible solution.

A feasible solution is a solution that satisfies the constraints

16. Define optimal solution.

An optimal solution is a feasible solution that optimizes the objective/optimization function. In general, finding an optimal solution is computationally hard.

17. What is the Control abstraction of greedy technique?

• Select ()-is the function that selects an input from a [] and removes it. • Feasible ()-is a Boolean-valued function that determines whether x can be included

into the solution vector. • Union ()-is the function that combines x with the solution and updates the objective

function.

18. What is meant by Container-loading?

Container-loading problem is a problem which is used to load the ship with the maximum number of containers.

19. Define Complexity Analysis.

• A complexity class is a set of problems of related complexity. Simpler complexity classes are defined by the following factors:

• The type of computational problem: The most commonly used problems are decision problems. However, complexity classes can be defined based on function problems, counting problems, optimization problems, promise problems, etc.

• The model of computation: The most common model of computation is the deterministic Turing machine, but many complexity classes are based on nondeterministic Turing machines, Boolean circuits, quantum Turing machines, monotone circuits, etc.

• The resources (or resources) that are being bounded and the bounds: These two properties are usually stated together, such as "polynomial time", "logarithmic space", "constant depth", etc.

21. Application of greedy algorithm:

• Container loading. • Knapsack problem. • Topological sorting. • Bipartite cover • Single-source shortest paths • Minimum-cost spanning trees

TechR

eg-E

du

Page 9: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 9

22. How the choices are made in each step in greedy method:

• Choices of solution made at each step of problem solving in greedy approach is as follows...

• Feasible-it should the problem's constraints. • Locally optimal-among all feasible solutions the best choice is to be made

Irrevocable-once the particular choice is made then it should not get changed on subsequent steps.

23. General plan for divide & conquer algorithm:

• Divide the problem into two or smaller sub problems • Conquer the sub problems by solving them recursively • Combine the solutions to the sub problems into the solutions for the original

problem.

UNIT 3

1. What is the difference between dynamic programming and greedy algorithm?

GREEDY ALGORITHM DYNAMIC PROGRAMMING 1. GA computes the solution in bottom up technique. It computes the solution from smaller sub-routines and tries many possibilities and choices before it arrives at the optimal set of choices. 2. It does not use the principle of optimality, i.e. there is no test by which one can tell GA will lead to an optimal solution.

1. DA computes its solution by making its choices in a serial fashion (never look back-irrevocable). 2. It uses the principle of optimality.

2. What is the difference between dynamic programming and divide and conquer?

DIVIDE AND CONQUER DYNAMIC PROGRAMMING 1. Divide the given problem into many sub-problems. Find the individual solutions and combine them to get the solution for the main problem. 2. Follows top down technique. 3. Split the input only at specific points (mid point). 4. Each problem is independent.

1. Many decisions and sequences are guaranteed and all the overlapping sub-instances are considered. 2. Follows bottom up technique. 3. Split the input at every possible points rather than at a particular point. 4. Sub-problems are dependent on the main problem.

TechR

eg-E

du

Page 10: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 10

3. What is dynamic programming?

Dynamic programming is an algorithm design method, where the solution to the main

problem can be viewed as the result of a sequence of decisions. It avoids the calculation of

same stuff twice, by keeping the table of known results of sub-problems.

4. What are the basic elements of dynamic programming?

• Sub structure

• Table structure

• Bottom up computations.

5. Define sub structure, table structure and bottom up computations.

A problem is said to have optimal substructure if the globally optimal solution can be

constructed from locally optimal solutions to sub problems.

We can either build up solutions of sub-problems from small to large (bottom up) or we

can save results of solutions of sub-problems in a table (top down + memorization).This

forms the table structure.

6. What are the applications of dynamic programming?

• Fibonacci numbers

• Longest increasing sequence

• Minimum weight triangulation

• The partition problem

• Appropriate string matching

7. Define multi stage graph.

A multistage graph is a graph

o G=(V,E) with V partitioned into K >= 2 disjoint subsets such that if (a,b) is in E, then a is in Vi , and b is in Vi+1 for some subsets in the partition;

o and | V1 | = | VK | = 1.

The vertex s in V1 is called the source; the vertex t in VK is called the sink. G is usually assumed to be a weighted graph. The cost of a path from node v to node w is sum of the costs of edges in the path. The "multistage graph problem" is to find the minimum cost path from s to t. Each set Vi is called a stage in the graph.

8. Define the principle of optimality.

It states that in an optimal sequence of decisions, each sub sequence must be optimal. To use dynamic programming the problem must observe the principle of optimality that whatever the initial state is, remaining decisions must be optimal with regard the state following from the first decision.

TechR

eg-E

du

Page 11: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 11

9. Give the formula for cost (i,j) of multistage graph in both forward and backward

approach.

Forward approach

Cost(i,j)=minc(i,j)+cost(i+1,l)

l Є vi+1 (vertex in next stage) , <j,l> Є E,

Since, cost (k-1,j)=c(j,t), if <j,t> ≤ E and

cost (k-1,j)= ∞, if<I,t> !Є E

Backward approach

Bcost(i,j)=minbcost(i-1,l)+c(l,j)

l Є vi-1 , <l,j>Є E

since,bcost(2,j)=c(1,j) if <1,j> Є E and

bcost(2,j)= ∞ if<1,j> !Є E

10) Derive the formula for the Floyd’s algorithm and running time of the algorithm.

for k<--1 to n do for i<--1 to n do for j<--1 to n do

D[i,j]=min[i,j],D[i,k]+D[k,j]

RUNNING TIME OF THE ALGORITHM: O(n^3) 11) Define OBST. An OBST is a BST which has minimal expected cost. Example: Key -5 1 8 7 13 21 Probabilities 1/8 1/32 1/16 1/32 1/4 The expectation-value of a search is: $ E[cost]=1.1/16+2. (1/32+1/4)+3.(1/8+1/32+1/2)

TechR

eg-E

du

Page 12: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 12

It's clear that this tree is not optimal. - It is easy to see that if the 21 is closer to the root, given its high probability, the tree will have a lower expected cost. Criterion for an optimal tree: Each optimal binary search tree is composed of a root and (at most) two optimal sub trees, the left and the right. 12) What is root table? The root table is a table which has 0 to n columns and 1 to n+ 1 row. The root value is given by R [1, n]. The k values the entries in the main table is entered into the root table. 13) What is the running time of traveling salesman problem and 0/1 knapsack problem?

TSP: 0(n^2 * 2^n) 0/1 Knapsack: 0(nw)

14) What is meant by TSP? The Traveling Salesman Problem (TSP) is a problem in combinatorial optimization studied in operations research and theoretical computer science. Given a list of cities and their pair wise distances, the task is to find a shortest possible tour that visits each city exactly once. It is one of the most intensively studied problems in optimization. 15) What are the preconditions for the Floyd’s algorithm? The precondition for the Floyd’s algorithm is that the graph should not have a cycle of negative length or cost. NOTE: Draw the graph given in class notes. 16) Write down the formula for the expected cost of the binary search tree. Refer Ellis horrowitz textbook Pg.No: 195 17) Define 0/1 Knapsack problem. The most common formulation of the problem is the 0-1 knapsack problem, which restricts the number xi of copies of each kind of item to zero or one. Mathematically the 0-1-knapsack problem can be formulated as:

TechR

eg-E

du

Page 13: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 13

18) What are the steps involved in dynamic programming?

• Develop a mathematical relation that can express any solution and sub solutions for problem.

• Prove the principle of optimality. • Develop a recurrence relation that is a solution to its sub solution using

mathematical notation in step 1. • Write an algorithm to compute the recurrence relation.

UNIT 4

1. Define exhaustive search.

Exhaustive search is simply a “brute – force” approach to combinatorial problems. It suggests generating each and every element of the problem’s domain, selecting those of them that satisfy the problem’s constraints, and then finding a desired element.

2. Difference between Backtracking & Exhaustive search. Backtracking

Exhaustive search

1. Backtracking is to build up the solution vector one component at a time and to use modified criterion function Pi(x1,..,xi) (sometimes called bounding function) to test whether the vector being formed has any chance of success.

Exhaustive search is simply a “brute – force” approach to combinatorial problems. It suggests generating each and every element of the problem’s domain, selecting those of them that satisfy the problem’s constraints, and then finding a desired element.

2. Backtracking makes it possible to solve many large instances of NP-hard problems in an acceptable amount of time.

Exhaustive search is impractical for large instances, however applicable for small instances of problems.

3. Define Backtracking. Backtracking is to build up the solution vector one component at a time and to use modified criterion function Pi(x1,..,xi) (sometimes called bounding function) to test whether the vector being formed has any chance of success. Desired solution expressed as an n-

tuple (x1,x2,…,xn) where xi are chosen from some set Si.

• If |Si|=mi, m=m1m2..mn candidates are possible • Yielding the same answer with far fewer than m trials • Advantage : if it is realized that the partial vector (x1,..,xi) can in no way lead to an

optimum solution, then mi+1…mn possible test vectors can be ignored entirely.”

TechR

eg-E

du

Page 14: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 14

4. Give the categories of the problem in backtracking. • Decision’s problem: - Whether there is any feasible solution. • Optimization problem: - Whether there exists any best solution. • Enumeration problem: - Finds all possible feasible solution.

5. List down the examples of backtracking.

• n-Queens problem • Hamiltonian circuit problem • Subset-Sum problem • constraint satisfaction problem

6. Define promising and non promising node.

• Promising Node: A node in a state space tree is said to be promising if it corresponds to a

partially constructed solution that may still lead to a complete solution.

• Non – Promising node: A node in a state space tree is said to be non-promising if it corresponds to

a partially constructed solution that would not be able to lead to a complete solution further.

7. What are the two types of constraints used in Backtracking?

• Explicit constraints • Implicit constraints

8. Define implicit constraint.

• Implicit constraints are rules that determine which of the tuples in the solution space of I that satisfy the criterion function.

• Implicit constraints describe the way in which the x is must relate to each other.

9. Define explicit constraint. Explicit constraints are rules that restrict each xi to take on values only from a given set.

• Explicit constraints depend on the particular instance I of problem being solved • All tuples that satisfy the explicit constraints define a possible solution space for

I • Examples of explicit constraints

xi >= 0, or Si = all nonnegative real numbers xi = 0, 1 or Si = 0, 1 li <= xi <= ui or Si = a : li ≤ a ≤ ui 10. How can you represent the solution for 2 queen’s problem? There is no solution for 2 Queen’s problem since however the queens are arranged both queens would be in same diagonal or column.

TechR

eg-E

du

Page 15: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 15

11. How can you represent the solution for 8 queen’s problem?

All solutions represented as 8-tuples (x1, x2,…, x8) where xi is the column on which

queen “i” is placed.

Constraints are,

Explicit constraints o Si=1,2,…,8

Implicit constraints o No two xi’s can be the same column or row (By this, solution space

reduced from 88 to 8!) o No two queens can be on the same diagonal

12. Define n-queens problem

Place n queens on an n × n chessboard so that no queen attacks another queen

which means no two queen’s are in same row/column or same diagonal

Solution space consists of all n! Permutations of the n-tuple (1, 2 . . . n)

13. Define sum of subsets problem?

In the Sum-of-Subsets problem, there are n positive integers (weights) wi and a positive

integer W.

The goal is to find all subsets of the integers that sum to W.

For example, n = 4, w = (11, 13, 24, 7), and m = 31, the desired subsets are (11, 13, 7)

and (24, 7)

– The solution vectors can also be represented by the indices of the numbers as (1, 2, 4)

and (3, 4)

_ All solutions are k-tuples, 1 <= k <= n

14. Define problem state?

• Problem state is each node in the depth-first search tree

15. Define state space of the problem?

• State space is the set of all paths from root node to other nodes

16. Define solution states and answer state?

Solution state:

• Solution states are the problem states s for which the path from the root node to‘s’ defines a tuple in the solution space

• In variable tuple size formulation tree, all nodes are solution states • In fixed tuple size formulation tree, only the leaf nodes are solution states

TechR

eg-E

du

Page 16: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 16

• Partitioned into disjoint sub-solution spaces at each internal node

Answer state:

• Answer states are that solution states s for which the path from root node to s defines a tuple that is a member of the set of solutions

• These states satisfy implicit constraints

17. Define state space tree?

• State space tree is the tree organization of the solution space

18. Define static tree.

Static trees are ones for which tree organizations are independent of the problem instance

being solved

• Fixed tuple size formulation • Tree organization is independent of the problem instance being solved

19. Define dynamic tree.

• Dynamic trees are ones for which organization is dependent on problem instance

20. Define live node.

• Live node is a generated node for which all of the children have not been generated yet

• E-node is a live node whose children are currently being generated or explored.

21. Define dead node.

Dead node is a generated node that is not to be expanded any further

• All the children of a dead node are already generated • Live nodes are killed using a bounding function to make them dead nodes

22. Define m color ability decision problem.

Let G be a graph and m be a given positive integer. The nodes of G can be colored in such

a way that no two adjacent nodes have the same color yet only m colors are used. This is

termed the m-colorability decision problem. If d is the degree of the given graph, then it

can be colored with d+ 1 color. The m-colorability optimization problem asks for the

smallest integer m for which the graph G can be colored. This integer is referred to as the

chromatic number of the graph. The color of each node is indicated next to it. If three

colors are needed to color the graph then the graphs chromatic number is 3.

TechR

eg-E

du

Page 17: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 17

23. Define Hamiltonian circuit problem.

Suppose we are given a graph G = (V,E) that is undirected. We say that a path v1, v2. . .

vn is a Hamiltonian path if every vertex of the graph occurs exactly once in this path.

Moreover, if the last vertex of the path duplicates the first one without ever repeating any

other vertex in between, then the path is called a Hamiltonian circuit

24. State the equation which is used to represent 2 queens are in same diagonal.

Let the diagonals be (i,j) and (k,l)

The equation to represent 2 queens are in same diagonal is

i+j=k+l j-l=k-I or

i-j=k-l j-l=i-k

Unit 5

1. Define graph traversal.

Searching a vertex in a graph can be solved by starting at vertex V and

systematically searching the graph G for vertices that can be reached from V.

It starts at initial vertex and visits each and every vertex exactly once and finally reaches

end vertex.

2. Mention the types of traversal.

• Breath first search traversal. • Depth first search traversal.

3. What is meant by BFS traversal?

• It starts from the arbitrary vertex. • It visits all vertices adjacent to starting vertex. • Then it visits next unvisited vertex. • This process is repeated until no more vertexes is left

4. What is the time complexity of BFS?

• If the graph is represented by adjacency matrix: O (n2 ). • If the graph is represented by adjacency List: O (|V|+ |E| ).

5. Define depth first search traversal.

• It starts from the arbitrary vertex. • The exploration of the vertex V is suspended as soon as a new vertex is reached • At this time the exploration of new vertex U begins • The new vertex is explored the exploration of V continues • The search terminates when all reached vertices have been fully explored.

TechR

eg-E

du

Page 18: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 18

6. What is the time complexity of DFS?

• If the graph is represented by adjacency matrix: O (n2 ). • If the graph is represented by adjacency List: O (|V|+ |E| ).

7. Compare DFS and BFS.

8. Define connected component.

• A graph is said to be connected if for every pair of its vertices U and V, there is path from U to V.

• A connected component is the maximal sub graph of a given graph.

9. How do identify connected component using breath first search?

• BFS can be used to determine whether G is connected • Using BFS all newly visited vertices are put on the list. • Sub graph formed by the vertices on this list make up a connected component.

10. Define spanning tree.

• A spanning tree is a minimal sub graph, G', of G such that V (G') = V (G) and G' is connected

• A minimal sub graph is one with the fewest no.., of edges • Any connected graph with n vertices must have at least n -1edges, and all

connected graphs with n -1 edges are trees • A spanning tree has n -1 edge

11. What is meant by articulation point? An articulation point is a vertex v of G such that the deletion of v, together with all edges incident on v, produces a graph, G', that has at least two connected components 12. Define bi connected graph and bi connected component.

• A bi connected graph is a connected graph that has no articulation points • A bi connected component of a connected undirected graph is a maximal bi

connected sub graph of G

DFS BFS

It uses STACK representation It uses QUEUE representation

It contains tree edge and back edge It contains tree edge and cross edge

It used to identify articulation points It is used to identify minimum edge

paths

TechR

eg-E

du

Page 19: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 19

13. List down the bi connected components for the following connected graph. Connected graph is

14. What are the methods to identify the articulation point?

• Common vertex in bi connected component • Depth first spanning tree • Lowest depth first number

15. What is meant by lowest depth first number? For every vertex V in depth first spanning tree, we compute the L(u) that is reachable from V by taking zero or more edges and then possible one back edge. 16. What is tree edge and cross edge? In the breath 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. If an edge is leading to a previously visited vertex other than its immediate predecessor, that is noted as a cross edge.

TechR

eg-E

du

Page 20: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 20

16. Define branch and bound.

Branch-and-bound refers to all state space search methods in which all children of an E-

node are generated before any other live node can become the E-node.

17. Define live node, e node and dead node.

• Live node is a node that has been generated but whose children have not yet been generated.

• E-node is a live node whose children are currently being explored. In other words, an E-node is a node currently being expanded.

• Dead node is a generated node that is not to be expanded or explored any further. All children of a dead node have already been expanded.

18. What are the types search strategies in branch and bound?

• FIFO search • LIFO search • LC search

19. Compare the FIFO and LIFO search.

• BFS is an FIFO search in terms of live nodes • List of live nodes is a queue • DFS is an LIFO search in terms of live nodes • List of live nodes is a stack •

20. What is meant by Least Cost Search?

The next E-node is selected on the basis of this ranking function. Heuristic is based on the

expected additional computational effort (cost) to reach a solution from the current live

node.

21. Define intelligent function.

Let ˆg(x) be an estimate of the additional effort needed to reach an answer from node x, x

is assigned a rank using a function ˆc () such that

^c (x) = f(h(x)) + ˆg(x)

Where h(x) is the cost of reaching x from root and f () is any non decreasing function.

22. What is meant by class P (Polynomial)?

Class P consists of problems whose solutions are bounded by the polynomial of small

degree. Examples are Binary search O (log n), sorting O (n log n), and matrix

multiplication 0(n 2.81).

TechR

eg-E

du

Page 21: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 21

23. What is meant by Class NP (Non Polynomial)?

Class P consists of problems whose solutions are bounded by the non polynomial.

Examples are Traveling salesperson problem O(n22n), knapsack problem O(2n/2)

24. What are the two classes of non polynomial time problems?

• NP- hard • NP-complete

25. Differentiate between the deterministic and non deterministic algorithm.

Deterministic algorithm non deterministic algorithm

Algorithm contains whose out come are

uniquely defined.

Algorithm contain operation whose out

come are not uniquely defined but are

limited to specified set of possibilities

26. Differentiate between the decision and optimization problem.

Decision Problem Optimization Problem

Computational problem with intended

output of yes or no ie.., 1 or 0

Computational problem where we try to

maximize or minimize the objective

function.

27. State true or false.

• All NP-complete problems are NP-hard – TRUE. • All NP-hard problems are not NP-complete- TRUE.

28. Define SATISFIABILITY.

Let x1, x2, x3….,xn denotes Boolean variables.

_

Let xi denotes the relation of xi.

A literal is either a variable or its negation.

A formula in the prepositional calculus is an expression that can be constructed using

literals and the operators and Λ or v.

A clause is a formula with at least one positive literal.

The satiability problem is to determine if a formula is true for some assignment of truth

values to the variables.

TechR

eg-E

du

Page 22: DAA TWO MARK - Vidyarthiplus

DAA TWO MARK QUESTION AND ANSWER 22

29. Define COOK’S theorem.

Satisfiability is in P if and only if P = NP.

30. What is meant by NP hard and NP complete problem?

• NP-Hard Problem: A problem L is NP-hard if any only if satisfiability reduces to L.

• NP- Complete: A problem L is NP-complete if and only if L is NP-hard and L є NP. • There are NP-hard problems that are not NP-complete.

Halting problem is NP-hard decision problem, but it is not NP-complete.

TechR

eg-E

du