Practice 50 JavaScript Searching Algorithm Programming Questions
Q1. Write a JavaScript program to implement Linear Search to find an element in an array.
Input: [5, 3, 8, 4, 2], search element: 4
Expected Output: Index of 4: 3
Q2. Write a JavaScript program to implement Linear Search to find an element in an array.
Input: [5, 3, 8, 4, 2], search element: 10
Expected Output: Element not found
Q3. Write a JavaScript program to implement Binary Search to find an element in a sorted array.
Input: [1, 2, 3, 4, 5, 6, 7, 8], search element: 5
Expected Output: Index of 5: 4
Q4. Write a JavaScript program to implement Binary Search to find an element in a sorted array.
Input: [1, 2, 3, 4, 5, 6, 7, 8], search element: 9
Expected Output: Element not found
Q5. Write a JavaScript program to implement Linear Search to find a string element in an array.
Input: ["apple", "banana", "orange", "kiwi"], search element: "orange"
Expected Output: Index of orange: 2
Q6. Write a JavaScript program to implement Linear Search to find a string element in an array.
Input: ["apple", "banana", "orange", "kiwi"], search element: "mango"
Expected Output: Element not found
Q7. Write a JavaScript program to implement Linear Search to find a number in an array of mixed data types.
Input: [5, "apple", 8, "banana", 2], search element: 8
Expected Output: Index of 8: 2
Q8. Write a JavaScript program to implement Binary Search to find an element in a sorted array of strings.
Input: ["apple", "banana", "kiwi", "orange"], search element: "kiwi"
Expected Output: Index of kiwi: 2
Q9. Write a JavaScript program to implement Binary Search to find an element in a sorted array of strings.
Input: ["apple", "banana", "kiwi", "orange"], search element: "grape"
Expected Output: Element not found
Q10. Write a JavaScript program to find the index of the first occurrence of a number using Linear Search.
Input: [5, 3, 8, 4, 8, 2], search element: 8
Expected Output: Index of first occurrence of 8: 2
Q11. Write a JavaScript program to find the index of the last occurrence of a number using Linear Search.
Input: [5, 3, 8, 4, 8, 2], search element: 8
Expected Output: Index of last occurrence of 8: 4
Q12. Write a JavaScript program to implement Binary Search for a number in a sorted array of numbers.
Input: [1, 3, 5, 7, 9], search element: 3
Expected Output: Index of 3: 1
Q13. Write a JavaScript program to implement Linear Search to find a number greater than a given number in an array.
Input: [5, 3, 8, 4, 2], search element: 6
Expected Output: Element not found
Q14. Write a JavaScript program to implement Linear Search to check if a given string exists in an array of strings.
Input: ["apple", "banana", "orange", "kiwi"], search element: "kiwi"
Expected Output: Element found: kiwi
Q15. Write a JavaScript program to implement Binary Search on a sorted array to find the index of a string.
Input: ["apple", "banana", "kiwi", "orange"], search element: "banana"
Expected Output: Index of banana: 1
Q16. Write a JavaScript program to implement Linear Search to find the index of an element in an array.
Input: [2, 4, 6, 8, 10], search element: 6
Expected Output: Index of 6: 2
Q17. Write a JavaScript program to implement Linear Search to find the first even number in an array.
Input: [1, 3, 7, 8, 5]
Expected Output: First even number: 8
Q18. Write a JavaScript program to implement Binary Search to find the index of a number in a sorted array of numbers.
Input: [3, 6, 8, 10, 15, 18], search element: 10
Expected Output: Index of 10: 3
Q19. Write a JavaScript program to implement Binary Search to find a number in a sorted array.
Input: [10, 20, 30, 40, 50], search element: 30
Expected Output: Index of 30: 2
Q20. Write a JavaScript program to implement Linear Search to find if a number exists in an unsorted array of numbers.
Input: [3, 1, 4, 5, 2], search element: 4
Expected Output: Index of 4: 2
Q21. Write a JavaScript program to find the index of a specific string in an array using Linear Search.
Input: ["cat", "dog", "rabbit", "hamster"], search element: "dog"
Expected Output: Index of dog: 1
Q22. Write a JavaScript program to implement Linear Search to check if a number is even in an array.
Input: [3, 2, 9, 4, 6], search element: 4
Expected Output: 4 is even
Q23. Write a JavaScript program to implement Binary Search to find a number in a sorted array.
Input: [1, 2, 3, 4, 5, 6], search element: 4
Expected Output: Index of 4: 3
Q24. Write a JavaScript program to search for an element using Linear Search and return a message if found.
Input: [12, 15, 20, 25], search element: 20
Expected Output: 20 found at index 2
Q25. Write a JavaScript program to implement Binary Search for a string element in a sorted array.
Input: ["dog", "cat", "apple", "banana"], search element: "cat"
Expected Output: Index of cat: 1
Q26. Write a JavaScript program to implement Binary Search on a sorted array of numbers.
Input: [10, 20, 30, 40, 50], search element: 40
Expected Output: Index of 40: 3
Q27. Write a JavaScript program to search an element in a sorted array of strings using Binary Search.
Input: ["apple", "banana", "kiwi", "orange"], search element: "kiwi"
Expected Output: Index of kiwi: 2
Q28. Write a JavaScript program to find the index of a string element in an array using Linear Search.
Input: ["apple", "banana", "cherry"], search element: "banana"
Expected Output: Index of banana: 1
Q29. Write a JavaScript program to implement Linear Search and return the index of a number.
Input: [10, 20, 30, 40, 50], search element: 30
Expected Output: Index of 30: 2
Q30. Write a JavaScript program to implement Binary Search and find the index of a number in a sorted array.
Input: [3, 6, 8, 10, 15], search element: 15
Expected Output: Index of 15: 4
Q31. Write a JavaScript program to check if an element exists using Linear Search in a mixed array.
Input: [3, "apple", 9, "banana", 4], search element: "banana"
Expected Output: Index of banana: 3
Q32. Write a JavaScript program to implement Binary Search to find a number in a sorted array of mixed data types.
Input: [1, "apple", 5, 7, 10], search element: 5
Expected Output: Index of 5:2
Q33. Write a JavaScript program to perform Linear Search to find an element in an array of strings.
Input: ["one", "two", "three", "four"], search element: "three"
Expected Output: Index of three: 2
Q34. Write a JavaScript program to search for the first odd number in an array using Linear Search.
Input: [1, 3, 5, 7, 9]
Expected Output: First odd number: 1
Q35. Write a JavaScript program to implement Binary Search to find the index of a string in a sorted array.
Input: ["apple", "banana", "cherry"], search element: "banana"
Expected Output: Index of banana: 1
Q36. Write a JavaScript program to implement Linear Search to find an element in an array.
Input: [7, 2, 9, 4], search element: 4
Expected Output: Index of 4: 3
Q37. Write a JavaScript program to find if an element exists in an array using Linear Search.
Input: [15, 10, 20], search element: 10
Expected Output: Index of 10: 1
Q38. Write a JavaScript program to implement Binary Search to find a number in a sorted array.
Input: [5, 10, 15, 20, 25], search element: 15
Expected Output: Index of 15: 2
Q39. Write a JavaScript program to search for a string in an array using Linear Search.
Input: ["dog", "cat", "fish"], search element: "cat"
Expected Output: Index of cat: 1
Q40. Write a JavaScript program to implement Binary Search to find the index of an element in a sorted array.
Input: [3, 6, 9, 12, 15], search element: 6
Expected Output: Index of 6: 1
Q41. Write a JavaScript program to implement Linear Search to find an even number in an array.
Input: [5, 10, 7, 12], search element: 10
Expected Output: 10 is even
Q42. Write a JavaScript program to implement Binary Search to find a string element in a sorted array.
Input: ["cat", "dog", "apple", "banana"], search element: "dog"
Expected Output: Index of dog: 1
Q43. Write a JavaScript program to find an element in an array of numbers using Linear Search.
Input: [2, 4, 6, 8], search element: 4
Expected Output: Index of 4: 1
Q44. Write a JavaScript program to implement Linear Search for numbers in an array.
Input: [1, 3, 4, 6, 8], search element: 3
Expected Output: Index of 3: 1
Q45. Write a JavaScript program to implement Binary Search to find an element in a sorted array.
Input: [7, 12, 16, 20, 25], search element: 20
Expected Output: Index of 20: 3
Q46. Write a JavaScript program to search for the first even number in an array using Linear Search.
Input: [1, 2, 3, 4]
Expected Output: First even number: 2
Q47. Write a JavaScript program to implement Binary Search to find an element in a sorted array of numbers.
Input: [5, 10, 15, 20, 25], search element: 20
Expected Output: Index of 20: 3
Q48. Write a JavaScript program to implement Linear Search to find if a number is divisible by 3 in an array.
Input: [2, 4, 6, 8], search element: 6
Expected Output: 6 is divisible by 3
Q49. Write a JavaScript program to perform Binary Search to find the index of a string in a sorted array.
Input: ["apple", "banana", "kiwi", "orange"], search element: "kiwi"
Expected Output: Index of kiwi: 2
Q50. Write a JavaScript program to perform Linear Search to find the first element greater than 5 in an array.
Input: [3, 2, 7, 8, 5]
Expected Output: First number greater than 5: 7
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!