Design and Analysis of Algorithms Posted on January 25, 2019February 2, 2019 by aerovijay Share this An algorithm is a set of steps of operations to solve a problem performing calculation, data processing, and automated reasoning tasks. An algorithm is an efficient method that can be expressed within finite amount of time and space. An algorithm is the best way to represent the solution of a particular problem in a very simple and efficient way. If we have an algorithm for a specific problem, then we can implement it in any programming language, meaning that the algorithm is independent from any programming languages. There are ______steps to solve the problem Seven Four Six Two ______is the first step in solving the problem Understanding the Problem Identify the Problem Evaluate the Solution None of these Following is true for understanding of a problem Knowing the knowledgebase Understanding the subject on which the problem is based Communication with the client All of the above The six-step solution for the problem can be applied to I. Problems with Algorithmic Solution II. Problems with Heuristic Solution Only I Only II Both I and II Neither I nor II ______ solution requires reasoning built on knowledge and experience Algorithmic Solution Heuristic Solution Random Solution None of these While solving the problem with computer the most difficult step is __________. describing the problem finding out the cost of the software writing the computer instructions testing the solution The correctness and appropriateness of ___________solution can be checked very easily. algorithmic solution heuristic solution random solution none of these The branch of computer that deals with heuristic types of problem is called _________________. system software real time software artificial intelligence none of these Artificial Intelligence makes use of following prominently Database Data Warehouse Knowledge base None of theseC The true and false values represent __________. logical data numeric data character data alphanumeric data Naming convention for variable is followed in company because ____________. it enhances readability it allows to work without conflicts it enhances the efficiency all of the above Following operator distinguishes equation from expression +, -, *, / < or > Logical operators Assignment Operator Following are called logical operators +, -, *, / <, >, <=, >= AND, OR, NOT \, MOD The hierarchy of operations is denoted as _____________. I. +, - II. Power III. *, / IV. \, MOD I, II, III, IV II, IV, III, I IV, I, III, II II, III, IV, I 22. An employee came in to work and clocked in at MorningIn, clocked out at NoonOut1 for lunch, clocked back in at NoonIn, and clocked out to home at NoonOut2. Set up equation to calculate the number of hours worked for the day. WorkingHrs = (12 - (MorningIn+NoonOut1) + (NoonOut2-NoonIn)) WorkingHrs = (12 – MorningIn + (NoonOut1-12.00) + (NoonOut2-NoonIn)) WorkingHrs = (12 – MorningIn) + (NoonOut1-12.00)-(NoonOut2-NoonIn)) WorkingHrs = (MorningIn+NoonIn) + (12.00-NoonOut2) The hierarchy of operations is denoted as _____________. I. +, - II. Power III. *, / IV. \, MOD I, II, III, IV II, IV, III, I IV, I, III, II II, III, IV, I Evaluate 5*(x+y)-4*y/(z+6) where x = 2, y = 3, and z = 6 1 24 5 10 Evaluate a-2>b where a=6, b = 8 False True 6 7 Evaluate for a = 5, b = 4, c = 3, d = 12 for the equation E = a*b+d/c 40 24 10 10.66 Evaluate for the equation e = 5*a\d*(b+1) where a = 5, b = 4, c = 3, d = 12 10 24 0 10 Evaluate for the following A = TRUE, B = FALSE, C = FALSE i. R = NOT ( A OR B ) AND NOT (B OR C) ii. R = B AND NOT ( A OR C ) OR NOT (B AND C) i is true and ii is true i is true and ii is false i is false and ii is true i is false and ii is false A large department store has its own charge card. The policy for a customer to charge an item is that the customer must have a valid charge card and either a balance of less than Rs.500 or a charge of less than Rs.50. ChargeCard AND (Balance < 500 OR Amount < 50) ChargeCard OR (Balance < 500 AND Amount < 50) ChargeCard OR (Balance < 500 OR Amount < 50) ChargeCard AND (Balance < 500 AND Amount < 50) The PAC stands for Program Analysis Chart Problem Algorithm Code Problem Access Code Problem Analysis Chart The IPO stands for Input Programming Option Input Programming Output Input Processing Output Input Operating Operation In interactivity chart the darkened circle indicates _______________. duplicate module loop decision no special meaning In interactivity chart the diamond indicates _______________. duplicate module loop decision no special meaning The interactivity chart is also known as __________________. IPO Chart Problem Analysis Chart flow chart structure chart The difference between /, \ and MOD operator is \ Integer Division, / Division and MOD Modulo Division / Division, \ escape sequence, MOD remainder / Division, \ not an operator, MOD is module \ Division /Integer Division, MOD is Modulo Division The help menus or user manuals are the part of ______________. Program Algorithm Internal Documentation External Documentation The main measure for efficiency algorithm are- Processor and Memory Complexity and Capacity Data and Space Time and space What does the algorithmic analysis count? The number of arithmetic and the operations that are required to run the program The number of lines required by the program The number of seconds required by the program to execute None of these Examples of O(1) algorithms are______________. Multiplying two numbers. assigning some value to a variable displaying some integer on console All of the above Examples of O(n2) algorithms are______________. Adding of two Matrices Initializing all elements of matrix by zero Both A and B Neither A nor B The complexity of three algorithms is given as: O(n), O(n2) and O(n3). Which should execute slowest for large value of n? O(n) O(n2) O(n3) All will execute in same time. There are four algorithms A1, A2, A3, A4 to solve the given problem with the order log(n), nlog(n), log(log(n))n/log(n), Which is the best algorithm. A1 A2 A3 A4 Express the formula (n-1)*(n-5) in terms of big Oh notation O(1) O(log n) O(n) O(n2) The time complexity of binary search is________. O(1) O(log n) O(n) O(n logn) The time complexity of linear search is________. O(1) O(log n) O(n) O(n logn) In quick sort, the number of partitions into which the file of size n is divided by a selected record is n n - 1 2 n/2 A sort technique is said to be stable when the original relative order of records with equal keys are retained after sorting. True False The three factors contributing to the sort efficiency considerations are the efficiency in coding, machine run time and the space requirement for running the procedure. True False How many passes are required to sort a file of size n by bubble sort method? N2 N N-1 N/2 How many number of comparisons are required in insertion sort to sort a file if the file is sorted in reverse order? N2 N N-1 N/2 How many number of comparisons are required in insertion sort to sort a file if the file is already sorted? N2 N N-1 N/2 Which of the following sorting procedures is the slowest? Quick sort Heap sort Shell sort Bubble sort The worst-case time complexity of Quick Sort is________. O(n2) O(log n) O(n) O(n logn) The worst-case time complexity of Bubble Sort is________. O(n2) O(log n) O(n) O(n logn) The worst-case time complexity of Selection Exchange Sort is________. O(n2) O(log n) O(n) O(n logn) The worst-case time complexity of Merge Sort is________. O(n2) O(log n) O(n) O(n logn) The algorithm like Quick sort does not require extra memory for carrying out the sorting procedure. This technique is called __________. in-place stable unstable in-partition Two main measures for the efficiency of an algorithm are Processor and memory Complexity and capacity Time and space Data and space The space factor when determining the efficiency of algorithm is measured by Counting the maximum memory needed by the algorithm Counting the minimum memory needed by the algorithm Counting the average memory needed by the algorithm Counting the maximum disk space needed by the algorithm The time factor when determining the efficiency of algorithm is measured by Counting microseconds Counting the number of key operations Counting the number of statements Counting the kilobytes of algorithm A list of n strings, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is O (n log n) O (n2 log n) O (n2 + log n) O (n2) Which of the following case does not exist in complexity theory? Best case Worst case Average case Null case The concept of order Big O is important because It can be used to decide the best algorithm that solves a given problem It determines the maximum size of a problem that can be solved in a given amount of time It is the lower bound of the growth rate of algorithm Both A and B The recurrence relation capturing the optimal execution time of the Towers of Hanoi problem with n discs is T(n) = 2T(n - 2) + 2 T(n) = 2T(n - 1) + n T(n) = 2T(n/2) + 1 T(n) = 2T(n - 1) + 1 Which of the following sorting methods would be most suitable for sorting a list which is almost sorted? Bubble Sort Insertion Sort Selection Sort Quick Sort Suppose we are sorting an array of eight integers using some quadratic sorting algorithm. After four iterations of the algorithm’s main loop, the array elements are ordered as shown here: 2 4 5 7 8 1 3 6 Insertion sort Selection sort Either of a and b None of the above The running time of insertion sort is O(n^2) O(n) O(log n) O(n log n) A sort which compares adjacent elements in a list and switches where necessary is ____. insertion sort heap sort quick sort bubble sort The correct order of the efficiency of the following sorting algorithms according to their overall running time comparison is Insertion>selection>bubble Insertion>bubble>selection Selection>bubble>insertion. bubble>selection>insertion Given f(n) = log_{2}^{n}, g(n) = √n which function is asymptotically faster f(n) is faster than g(n) g(n) is faster than f(n) Either f(n) or g(n) Neither f(n) nor g(n) A sort which iteratively passes through a list to exchange the first element with any element less than it and then repeats with a new first element is called insertion sort selection sort heap sort Dquick sort The number of swapping’s needed to sort the numbers 8, 22, 7, 9, 31, 19, 5, 13 in ascending order, using bubble sort is 10 9 13 14 The way a card game player arranges his cards as he picks them one by one can be compared to Quick sort Merge sort Insertion sort Bubble sort Which among the following is the best when the list is already sorted? Insertion sort Bubble sort Merge sort Selection sort As part of the maintenance work, you are entrusted with the work of rearranging the library books in a shelf in proper order, at the end of each day. The ideal choice will be Bubble sort Insertion sort Selection sort Merge sort In quick sort, the number of partitions into which the file of size n is divided by a selected record is n n - 1 2 None of the above The total number of comparisons made in quick sort for sorting a file of size n, is O(n log n) O(n2) n(log n) None of the above Quick sort efficiency can be improved by adopting non-recursive method insertion method tree search method None of the above For the improvement of efficiency of quick sort the pivot can be the first element the mean element the last element None of the above Quick sort is the fastest available method of sorting because of low over head O(n log n) comparisons low overhead and also O(n log n) comparisons None of the above Straight selection sort is basically a method of repeated interchange searching position adjustment None of the above Number of selections required to sort a file of size N by straight selection requires N - 1 log N O(N2) None of the above For sorting a file of size n by straight selection sort, the number of comparisons made in the first pass is n n - 1 n(n - 1)/2 None of the above Heap is defined to be a complete binary tree binary tree tree structure None of the above In a Max heap the largest key is at the root a leaf a node None of the above In heap sort the input is arranged in the form of a heap tree queue None of the above Heap sort is found to be very efficient with regard to storage requirement in time consumption regarding overheads involved None of the above Suppose we need to sort a list of employee records in ascending order, using the social security number (a 9-digit number) as the key (i.e., sort the records by social security number). If we need to guarantee that the running time will be no worse than n log n, which sorting methods could we use? mergesort quicksort insertion sort Either mergesort or quicksort None of these sorting algorithms guarantee a worst-case performance of n log n or better Consider the following function f: int f(int n) { int s = 0; while(n > 1) { n = n/2; s++; } return s; } What is the asymptotic complexity in terms of n? (Pick the smallest correct answer) O(nlog n) O(n) O( n) O(log n) O(n^2 ) The most important reason for including a destructor in a class is: To print a message for debugging purposes To store information about an object before it goes out of scope To free up resources allocated by that class To reset the original object’s pointer to NULL One of these code fragments calls the copy constructor for class A. Which one? (Assume that doSomething is a void function with a parameter of the appropriate type.) A a; B b; a = b; A array[20]; A a; doSomething(a); A* a; doSomething(a) What is the asymptotic runtime for traversing all nodes in a binary search tree with n nodes and printing them in order? O(n ⋅ log(n)) O(n) O(log(n)) O(n^2 ) Consider a class List that implements an unordered list. Suppose it has as its representation a dynamically expanding (resizable) array. Which of these operations might need to delete some dynamically allocated storage to avoid a memory leak? I. Default Constructor II. Copy Constructor III. Destructor IV. Assignment operator I and II II and III II and IV III and IV What is the postfix representation of this expression? (12 – a) * (b + 9) / (d * 4) 4 b * d 9 + a 12 - * / / 12 a – b 9 + d 4 * 12 – a * b + 9 / d * 4 12 a – b 9 + * d 4 * / Assuming that the hash function for a table works well, and the size of the hash table is reasonably large compared to the number of items in the table, the expected (average) time needed to find an item in a hash table containing n items is O(1) O(log n) O(nlog n) O(n) T (n) = 4T (n/2) + n then T (n) = ϴ (n2) ϴ (n3) ϴ (n4) ϴ (n) Which of the following properties are necessary for an Algorithm? Definite ness correct ness Effectiveness A and C which of the following technique is not using for solve a 0-1knapsack problem Greedy Dynamic programming branch and bound all of the above n! = O( 2n) ω(2n) A and B O(n100) T (n) = 8T (n/2) + n^{2}, T (1) = 1 then T (n) = ϴ (n2) ϴ (n3) ϴ (n4) ϴ (n) T (n) = 3T (n/4) + n then T (n) = O (n2) O (n3) O (n) O (n4) T (n) = 2T (n/2) + cn then T (n) = O (log n) O (n log n) O (n2log n) O (n2) T (n) = 9T (n/3) + n then T (n) = ϴ (n4) ϴ (n3) ϴ (n2) ϴ (n) Which of the following case does not exist in complexity theory? Best case Worst case Average case Null case The Worst case occur in linear search algorithm when Item is somewhere in the middle of the array Item is not in the array at all Item is the last element in the array Item is the last element in the array or is not there at all The complexity of Fibonacci series is O(2n) O(log n) O(n2) O(n log n) The worst case occur in quick sort when Pivot is the median of the array Pivot is the smallest element Pivot is the middle element None of the mentioned An algorithm in which we divide the problem into subproblem and then we combine the subsolutions to form solution to the original problem is known as: Brute Force Divide and Conquer GreedyAlgorithm None of the mentioned