MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Examples of O(1) algorithms are ____
A
Multiplying two numbers.
B
assigning some value to a variable
C
displaying some integer on console
D
All of the above
Explanation: 

Detailed explanation-1: -Constant time algorithms will always take same amount of time to be executed. The execution time of these algorithm is independent of the size of the input. A good example of O(1) time is accessing a value with an array index. Other examples include: push() and pop() operations on an array.

Detailed explanation-2: -Constant Complexity-O(1) An algorithm has constant time complexity if it takes the same time regardless of the number of inputs. ( Reading time: under 1 minute) If an algorithm’s time complexity is constant, it means that it will always run in the same amount of time, no matter the input size.

Detailed explanation-3: -O(log N) is a common runtime complexity. Examples include binary searches, finding the smallest or largest value in a binary search tree, and certain divide and conquer algorithms. If an algorithm is dividing the elements being considered by 2 each iteration, then it likely has a runtime complexity of O(log N).

Detailed explanation-4: -So, if computing 10 elements take 1 second, computing 100 elements takes 2 seconds, 1000 elements take 3 seconds, and so on. When using divide and conquer algorithms, such as binary search, the time complexity is O(log n).

There is 1 question to complete.