Searching - DSA Interview Questions
Searching algorithms are fundamental in data structures and algorithms (DSA), playing a crucial role in optimizing data retrieval. Mastering these techniques will help you solve complex coding problems efficiently and improve your problem-solving skills for technical interviews.
Practice Searching DSA Coding Problems with Solutions
Learning Objectives:
Understand various searching algorithms, including linear and binary search, and their time complexities. Learn how to optimize search operations using advanced techniques like interpolation search, exponential search, and ternary search.
Exercise Instructions:
- Start with the first problem and attempt to solve it before checking the hint or solution.
- Ensure you understand the logic behind each solution, as this will help you with more complex problems.
- Use these exercises to reinforce your learning and identify areas that may require further study.
1. Linear Search
Required Input:
[10, 20, 5, 7, 15]
7Expected Output:
3
Code In Python
Run Code?
Click Run Button to view compiled output
2. Binary Search
Required Input:
[2, 4, 6, 8, 10, 12]
6Expected Output:
2
Code In Python
Run Code?
Click Run Button to view compiled output
3. First and Last Position
Required Input:
[5, 7, 7, 8, 8, 10]
8Expected Output:
[3, 4]
Code In Python
Run Code?
Click Run Button to view compiled output
4. Peak Element (Unimodal)
Required Input:
[1, 3, 8, 12, 4, 2]Expected Output:
12
Code In Python
Run Code?
Click Run Button to view compiled output
5. Square Root (Integer)
Required Input:
x = 25Expected Output:
5
Code In Python
Run Code?
Click Run Button to view compiled output
6. Insert Position
Required Input:
[1, 3, 5, 6]
2Expected Output:
1
Code In Python
Run Code?
Click Run Button to view compiled output
7. Min in Rotated Array
Required Input:
[4, 5, 6, 7, 0, 1, 2]Expected Output:
0
Code In Python
Run Code?
Click Run Button to view compiled output
8. Search in Matrix
Required Input:
[1, 4, 7, 11],
[2, 5, 8, 12],
[3, 6, 9, 16],
[10, 13, 14, 17]
5Expected Output:
True
Code In Python
Run Code?
Click Run Button to view compiled output
9. Single Non-Repeating
Required Input:
[1,1,2,2,3,3,4,8,8]Expected Output:
4
Code In Python
Run Code?
Click Run Button to view compiled output
10. Is Sorted & Rotated
Required Input:
[3, 4, 5, 1, 2]Expected Output:
True
Code In Python
Run Code?
Click Run Button to view compiled output


