TomoLink
TCS NQT GuideTCS NQT Coding Capability & AlgorithmsLinear Search and Binary Search Implementations

Linear Search and Binary Search Implementations

Learn core concepts, essential formulas, and attempt practice questions designed on the latest TCS NQT testing patterns.

Key Concepts & Formulas

  • 1Linear Search: Scan items sequentially. Time complexity: O(N).
  • 2Binary Search: Half search space dynamically. Target must be sorted. Time: O(log N).

TCS NQT Style Practice Questions

Practice Question 1

In what condition is Binary Search applicable?

A) Array must be sorted
B) Array must be small
C) Array must have unique elements
D) Can be run on any array

Correct Answer: A) Array must be sorted

Step-by-step Solution: Binary search relies on ordering to discard halves. It requires a sorted array.

Practice Question 2

Find middle index formula preventing integer overflow in Java/C++:

A) mid = low + (high - low) / 2
B) mid = (low + high) / 2
C) mid = high / 2
D) mid = low + high / 2

Correct Answer: A) mid = low + (high - low) / 2

Step-by-step Solution: Adding low and high directly can exceed the maximum integer bounds. (low + (high-low)/2) avoids overflow.

Study Pro-Tip

Always remember: Binary Search requires sorting first.