HW#1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Name: …………………………………………….

Student ID:………………… Due Date: 19-2-2023


Exercises
HW#1

1. _________________ indicates how fast the algorithm runs.

2. How many times is the statement 1 executed?

3. What is the exact number of comparisons of the if statement?

4. An algorithm is a sequence of ______________ instructions for solving a problem.

5. Given that f(n)=O(g(n)). Is g(n)=Ω(f(n))?

6. What is the time complexity of the following algorithm?

7. Binary Search algorithm costs _______________in the worst case while it costs __________ in the best
case.

8. For the following array, y indicates _______________________.

9. For the following array, Merging Two Sorted List algorithm requires ________ element comparisons.

10. The order of growth of the function f(n)=2n×n is lower than the function g(n)= 2n×n2. Hence, f(n)=O(g(n)).

1
11. What is the time complexity for the following algorithm?

12. Big-Oh notation expresses the upper bound which describes the __________________ scenario.

13. What is the time complexity of the following algorithm?

14. Express the time complexity of the following function in terms of the Θ-notation.

15. Express the following function in terms of Θ-notation.

16. What is the time complexity of the following algorithm?

17. What is the time complexity of the following algorithm?

18. What is the time complexity to find the smallest element in a three-dimensional array?

19. What is the time complexity of the following algorithm?

2
20. Given f(n) and g(n). Is f(n) = O(g(n))?

21. Given f(n) and g(n). Is f(n)+g(n)=Θ(min(f(n), g(n)))?

22. What is the time complexity of the following algorithm?

23. What is the time complexity of the following algorithm?

24. What is the time complexity of the following algorithm?

25. The least significant bit Radix sort algorithm is ___________ for both time and space complexities.

26. Given that f(n)=2n and g(n)=n log n. Is f(n)= Θg(n)?

27. Given that f(n)=O(g(n)). Is g(n)=O(f(n))?

28. What is the time complexity of the following algorithm?

3
29. What is the time complexity of the following algorithm?

30. What is the time complexity of the following algorithm?

31. What is the time complexity for the following algorithm?

32. Consider Merging Two Sorted List algorithm. If we want to implement this algorithm for the array
A={1,3,4,5,6,8,9,0,2,7}, what is the value of x,y, and z.
33. What is the time complexity of the following algorithm?

34. What it the time complexity of the following algorithm?

35. Given the following functions, ____________________ is the best as it has the lowest time complexity.

36. What is the time complexity of the following algorithm?

4
37. For the following algorithm, the best-case time complexity is __________ while it is ______________ in
the worst case.

38. Express the time complexity of the following function in terms of the Θ-notation.

39. Given an array A={5,4,3,2,1}. The exact number of element comparisons using selection sort is
__________.
40. What is the time complexity of the following algorithm?

41. Given that f(n)=√𝑛 and g(n)=log n2 . Is f(n)=Θg(n)?

42. We study algorithms to choose the best time-space complexity to solve a particular problem in the most
____________ way possible.

43. Linear Search algorithm requires ____________ comparison(s) if the searching element is not found in
an array A of size n.

44. The average case time complexity of the Quicksort algorithm is _____________.

45. What is the time complexity of the following algorithm?

46. Given an array A={1,3,4,6,7,9,12,15}. What is the second element to be compared when searching for 0.

47. Given that f(n)=9n+log n and g(n)=3n+100. Is f(n)=Ωg(n)?

48. ______________________ works by repeatedly swapping the adjacent elements if they are in wrong
order.

49. Consider Merging Two Sorted List algorithm. The least number of comparisons occurs when the elements
of the smaller subarray are less than all entries in the larger subarray. For the array A={1,3,4,5,6,8,9,0,2,7},
are the elements of the smaller subarray less than all entries in the larger subarray.

5
50. The most significant bit Radix sort is ________________ time complexity.

51. Given that f(n)=n/log n and g(n)=√𝑛 n. Is f(n)= Ωg(n)?

52. The worst-case performance of Binary Search algorithm is ________________.

53. The average case time complexity of the Selection sort is _________________.

54. The worst case time complexity of the Insertion sort is __________________.

55. The efficiency of Merging Two Sorted List algorithm is _____________________.

56. Given that f(n)=2n and g(n)=4n. Is f(n)=Θg(n)?

57. The best-case time complexity of the Insertion sort algorithm is _______________.

58. The following figure shows that the cubic class algorithms require fewer operations than linear class
algorithms.

59. What is the time complexity of the following algorithm?

60. What is the time complexity of the following algorithm?

61. What is the time complexity of the following algorithm?

6
62. What is the time complexity of the following algorithm?

63. One limitation of Binary Search algorithm is that the array elements must be _________________.

64. What is the time complexity of the following algorithm?

65. What is the time complexity of the following code?

66. What is the time complexity of the following code?

67. What is the time complexity of the following algorithm?

68. What is the time complexity of the following algorithm?

69. What is the time complexity of the following algorithm?


for i=1 to n
swap a[i] with smallest of a[i], …a[n]

You might also like