python quiz 10 on June 26, 2021 Get link Facebook X Pinterest Email Other Apps Q:1. In a binary search algorithm, Which is the worst case scenario:-1.O(1)2.O(log n)3.O(n)4.O(n/2)ANSWER :- (2) o(logn) is worst case scenario in pythonQ:2. Which statement is correct in case of tower of hanoi ?1.It consists of more than three rods.2.Only one disk can move at a time.3.any disk can be moved on to any one.4.None of the above.ANSWER :- (2) Only one disk can be moved at a time , only the top disk on any peg may be moved to any other peg also smaller disk can only be placed over larger disks.Q:3. How many swaps will be performed in selection sort in worst case :-1.zero2.one3.n-14.nANSWER :- (3) Here sorting algorithms makes the minimum possible number of swaps, n − 1 in the worst case.Q:4. Which of the following is true for binary search algorithm :-1.Array should be in unsorted order2.Search is performed by repetedly dividing search interval into one fourth3.If there are two numbers equals to the search item ( number to be searched ), it can pick anyone depending on the implementation4.Its best case complexity is O(log n)ANSWER :-(3) Binary search Search a sorted array by repeatedly dividing the search interval in half. The best-case time complexity would be O(1) when the central index would directly match the desired value.Q:5. Which of the following statement is true for recursion ?1.Absence of base condition can cause infinite loop.2.There is only one base case.3.Both 1 and 2.4.None of the above.ANSWER :- (1) If a recursive method does not have a base case which is necessary to meet the end of condition then an infinite loop occurs , also it can have more then one base case. Comments
Comments
Post a Comment