Data Structures & AlgorithmsEasyTCS NQT · Infosys pattern
What is the time complexity of reading the element arr[i] from an array of n elements, given i?
- A. O(1)
- B. O(n)
- C. O(log n)
- D. O(i)
Correct answer: A. O(1)
Array elements sit in contiguous memory, so the address is base + i × size and is computed in constant time. O(i) would be the cost of reaching the i-th node of a linked list, not an array.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Which data structure works on the Last In, First Out (LIFO) principle?
- What is the worst-case time complexity of binary search on a sorted array of n elements?
- Which of these sorting algorithms is stable in its standard implementation?
- What is the time complexity of inserting a new node at the head of a singly linked list of n nodes?
- With a good hash function and a bounded load factor, what is the average time to search for a key in a hash table?
- What is the postfix form of the infix expression A + B C?