INTERNAL ASSESMENT EXAMINATIONS - I COURSE: B.Tech - IT CS6402- DESIGN AND ANALYSIS OF ALGORITHMS Answer ALL questions What are the steps involved in analysis framework? 1. Measuring the input’s size Units for measuring running time Orders of growth Worst case, best case and average case efficiencies What is worst-case efficiency? 2. Efficiency (# of times the basic operation will be executed) for the worst case input of size n. The algorithm runs the largest among all possible inputs. 3. 4. 5. In sequential search the worst case efficiency is there are no matching elements or the first matching element happens to be the last one in the list. The algorithm makes the largest number of key comparisons among all possible inputs size n. Cworst(n)=n List out the properties of algorithm. Non ambiguity Range of input Multiplicity speed Fitness Write algorithm for sum of n numbers. Read the value of n. i = 1 , SUM = 0 if ( i > n ) go to 7 S=S+i i=i+1 go to 3 Display the value of S Stop Recite closest pair and convex hull method. Closest Pair: Compute the distance between every pair of distinct points and return the indexes of the points for which the distance is the smallest. – Convex hull: Problem: 6. Find smallest convex polygon enclosing n points on the plane Convex: • A geometric figure with no indentations. • Formally, a geometric figure is convex if every line segment connecting interior points is entirely contained within the figure's interior. State brute force. A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved: – Force – Just Do It 1 PART-B 1. (a) (i) Mention the steps involved in fundamentals of analysis of algorithms. (ii) List the important problem types & explain them in detail. Sorting: – Rearranging the given items in ordered sequence . – Sorting makes searching easier: dictionaries, telephone books, class lists and so on are sorted. – Sorting algorithms: selection sort, bubble sort, merge sort, quick sort, heap sort. Searching: – To find a given value, called a search key, in a given set. – Searching algorithms Sequential search Binary search Hashing Tree-based searches String Processing: – A string is a sequence of characters from an alphabet Text strings Bit strings Gene sequences-A,C,F,T – Algorithms: Brute-force string matching Huffman code Graph Problems: – A graph is a collection of points (vertices) which are connected by lines (edges). – Real-life applications: Transportation and communication networks Scheduling projects and games Web’s diameter. – Algorithms for graph problems: Graph traversal 2 – – – – – – (b) Shortest-path problem Combinatorial Problem: Find a combinatorial object such as permutation, a combination, or a subset that satisfies certain criteria (e.g., maximize a value or minimize a cost). Examples: Traveling salesman problem Knapsack problem Assignment problem Graph coloring problem Geometric Problems: Deal with geometric objects such as points, lines, and polygons Interesting problems Closest-pair problem Convex hull Brute force Divide-and-Conquer methods Numerical Problems: Large special area of applications Solving equations and systems of equations Computing definite integrals Evaluating functions. Taylor polynomial for ex Newton’s algorithm for computing square roots Describe briefly the analysis of algorithm. • Time & Space efficiency • Cost, Power Dependence on Input encoding Critical operation of algorithm Frequency of critical operation execution Number of “things” stored in memory relative to input encoding (i) Basic Operation The operation contributing the most to total runtime Frequency of execution depends on input T(n) ¼ cop C(n) Where, Cop=execution time of algorithm C(n)= number of times this operation is run on input n T(n)= running time Order of Growth: 3 (a) Apply Mathematical analysis of recursive and non recursive analysis in detail with example General Plan for Analysis of recursive algorithm • Decide on a parameter indicating an input’s size. • Identify the algorithm’s basic operation. • Check whether the number of times the basic op. is executed may vary on different inputs of the same size. (If it may, the worst, average, and best cases must be investigated separately.) • Set up a recurrence relation with an appropriate initial condition expressing the number of times the basic op. is executed. Solve the recurrence (or, at the very least, establish its solution’s order of growth) by backward substitutions or another method. (i) 2. General Plan for Analysis of non – recursive algorithm Decide on parameter n indicating input size Identify algorithm’s basic operation Determine worst, average, and best cases for input of size n Set up a sum for the number of times the basic operation is executed Simplify the sum using standard formulas and rules. (b) (i) Illustrate asymptotic notations and its property. • Big-O f n Og n : there exist positive constants c and n0 such that 0 f n cg n for all n n0 If f(n) = O(n2), then: • f(n) can be larger than n2 sometimes, but… • I can choose some constant c and some value n0 such that for every value of n larger than n0 : f(n) < cn2 • That is, for values larger than n0, f(n) is never more than a constant multiplier greater than n2 Visualization of (g(n)) f(n) cg(n) n0 -notation f n g n : there exist positive constants c1 , c2 , and n0 such that 0 c1 g n f n c2 g n for all n n0 4 Big-O is not a tight upper bound. In other words n = O(n2) provides a tight bound Visualization of (g(n)) c2g(n) f(n) c1g(n) n0 Big Omega – Notation f n g n : there exist positive constants c and n0 such that 0 f n cg n for all n n0 n2 = (n) Let c = 1, n0 = 2 For all n 2, n2 > 1 n Visualization of (g(n)) f(n) cg(n) n0 (a) Explain closest pair algorithm in detail. b Closest pair • Problem: find the closest pair among n points in k-dimensional space • Algorithm: Compute distance between each pair of points and identify the pair resulting in the shortest distance • Basic operation: k d ( xi yi ) 2 i 1 k d 2 ( xi yi ) 2 3. i 1 Distance between two points pi=(xi,yi) & pj=(xj,yj) (i) (ii) dist((x, y), (a, b)) = √(x - a)² + (y - b)² //find two closest points in the plane by brute force //Input: A list p to n (n≥2) points p1=(X1,y1)…pn = (xn,yn) //Output: Indices index1 & index2 of the closest pair of points dmin ∞ For i1 to n-1 do for j i+1 to n do d sqrt((xi-xj)2 +(yi-yj)2) if d < dmin dmin d; index1i; index2j return index1, index2 Illustrate convex hull method in detail. • Convex hull – Problem: Find smallest convex polygon enclosing n points on the plane – Convex: • A geometric figure with no indentations. 5 • (b) (i) Formally, a geometric figure is convex if every line segment connecting interior points is entirely contained within the figure's interior. • The straight line through two points (x1, y1), (x2, y2) in the coordinate plane can be defined by the following equation ax + by = c where a = y2 – y1, b = x1 – x2, c = x1y2 - y1x2 • Such a line divides the plane into two half-planes: for all the points in one of them: ax + by > c, while for all the points in the other, ax + by < c. • Algorithm: For each pair of points p1 and p2 determine whether all other points lie to the same side of the straight line through p1 and p2, i.e. whether ax+by-c all have the same sign • Efficiency: (n3) Distinguish Exhaustive search methods with example. A brute force solution to a problem involving search for an element with a special property, usually among combinatorial objects such as permutations, combinations, or subsets of a set. Method: – generate a list of all potential solutions to the problem in a systematic manner . – evaluate potential solutions one by one, disqualifying infeasible ones and, for an optimization problem, keeping track of the best one found so far when search ends, announce the solution(s) found • Three important problems: – Travelling salesman problem – Knapsack problem – Assignment problem Travelling salesman problem: • Given n cities with known distances between each pair, find the shortest tour that passes through all the cities exactly once before returning to the starting city • Alternatively: Find shortest Hamiltonian circuit in a weighted connected graph Knapsack Problem: Given n items: – weights: w1 w2 … wn – values: v1 v2 … vn – a knapsack of capacity W Find most valuable subset of the items that fit into the knapsack Assignment problem: There are n people who need to be assigned to n jobs, one person per job. The cost of assigning person i to job j is C[i,j]. Find an assignment that minimizes the total cost. Algorithmic Plan: Generate all legitimate assignments, compute their costs, and select the cheapest one. PART-C 1. Analyze And Demonstrate Tower of Honai in detail 6 7 8
© Copyright 2026 Paperzz