Practice 50 C# Searching and Sorting Programming Questions
Q1. Write a C# program to implement Linear Search.
Input: Array = [10, 20, 30, 40], Search = 30
Output: Element found at index 2
Q2. Write a C# program to implement Binary Search.
Input: Array = [10, 20, 30, 40, 50], Search = 40
Output: Element found at index 3
Q3. Write a C# program to implement Bubble Sort.
Input: Array = [5, 3, 8, 4, 2]
Output: Sorted Array = [2, 3, 4, 5, 8]
Q4. Write a C# program to implement Insertion Sort.
Input: Array = [12, 11, 13, 5, 6]
Output: Sorted Array = [5, 6, 11, 12, 13]
Q5. Write a C# program to implement Selection Sort.
Input: Array = [64, 25, 12, 22, 11]
Output: Sorted Array = [11, 12, 22, 25, 64]
Q6. Write a C# program to find the largest element in an array using Linear Search.
Input: Array = [10, 20, 15, 30, 25]
Output: Largest element = 30
Q7. Write a C# program to implement a recursive Binary Search.
Input: Array = [10, 20, 30, 40, 50], Search = 20
Output: Element found at index 1
Q8. Write a C# program to implement Merge Sort.
Input: Array = [38, 27, 43, 3, 9, 82, 10]
Output: Sorted Array = [3, 9, 10, 27, 38, 43, 82]
Q9. Write a C# program to implement Quick Sort.
Input: Array = [10, 80, 30, 90, 40, 50, 70]
Output: Sorted Array = [10, 30, 40, 50, 70, 80, 90]
Q10. Write a C# program to perform Binary Search on a sorted array.
Input: Array = [2, 4, 6, 8, 10], Search = 6
Output: Element found at index 2
Q11. Write a C# program to perform Linear Search in an unsorted array.
Input: Array = [4, 2, 9, 1], Search = 9
Output: Element found at index 2
Q12. Write a C# program to implement the Counting Sort algorithm.
Input: Array = [4, 2, 2, 8, 3, 3, 1]
Output: Sorted Array = [1, 2, 2, 3, 3, 4, 8]
Q13. Write a C# program to find the smallest element in an array using Linear Search.
Input: Array = [10, 20, 5, 15, 30]
Output: Smallest element = 5
Q14. Write a C# program to implement the Bubble Sort algorithm in descending order.
Input: Array = [5, 3, 8, 4, 2]
Output: Sorted Array = [8, 5, 4, 3, 2]
Q15. Write a C# program to implement the Insertion Sort algorithm in descending order.
Input: Array = [12, 11, 13, 5, 6]
Output: Sorted Array = [13, 12, 11, 6, 5]
Q16. Write a C# program to find the second largest element in an array.
Input: Array = [10, 20, 30, 40, 50]
Output: Second largest element = 40
Q17. Write a C# program to implement a binary search that returns the index of the target element or -1 if not found.
Input: Array = [1, 2, 3, 4, 5], Search = 3
Output: Element found at index 2
Q18. Write a C# program to sort an array using the Selection Sort algorithm in ascending order.
Input: Array = [29, 10, 14, 37, 13]
Output: Sorted Array = [10, 13, 14, 29, 37]
Q19. Write a C# program to find the number of occurrences of a number in an array using Linear Search.
Input: Array = [1, 2, 2, 3, 2, 4, 5], Search = 2
Output: Occurrences = 3
Q20. Write a C# program to perform Selection Sort in descending order.
Input: Array = [3, 5, 1, 4, 2]
Output: Sorted Array = [5, 4, 3, 2, 1]
Q21. Write a C# program to implement a simple search for finding a value and print its index.
Input: Array = [2, 4, 6, 8], Search = 6
Output: Element found at index 2
Q22. Write a C# program to perform Bubble Sort for an array of strings.
Input: Array = ["Banana", "Apple", "Orange", "Mango"]
Output: Sorted Array = ["Apple", "Banana", "Mango", "Orange"]
Q23. Write a C# program to implement Binary Search on an array of strings.
Input: Array = ["Apple", "Banana", "Grapes", "Orange"], Search = "Grapes"
Output: Element found at index 2
Q24. Write a C# program to find the first occurrence of an element in an array using Linear Search.
Input: Array = [10, 20, 30, 20, 40], Search = 20
Output: First occurrence found at index 1
Q25. Write a C# program to implement Merge Sort with an array of integers.
Input: Array = [12, 11, 13, 5, 6]
Output: Sorted Array = [5, 6, 11, 12, 13]
Q26. Write a C# program to sort an array using Quick Sort algorithm.
Input: Array = [10, 80, 30, 90, 40, 50, 70]
Output: Sorted Array = [10, 30, 40, 50, 70, 80, 90]
Q27. Write a C# program to perform a case-insensitive Binary Search on an array of strings.
Input: Array = ["apple", "Banana", "Orange", "grape"], Search = "banana"
Output: Element found at index 1
Q28. Write a C# program to implement the Counting Sort algorithm with a predefined range of numbers.
Input: Array = [4, 2, 2, 8, 3, 3, 1]
Output: Sorted Array = [1, 2, 2, 3, 3, 4, 8]
Q29. Write a C# program to implement Merge Sort and print the steps.
Input: Array = [38, 27, 43, 3, 9, 82, 10]
Output: Sorted Array = [3, 9, 10, 27, 38, 43, 82]
Q30. Write a C# program to find the kth smallest element in an array.
Input: Array = [12, 3, 5, 7, 19], k = 2
Output: 2nd smallest element = 5
Q31. Write a C# program to sort an array of doubles in ascending order using Bubble Sort.
Input: Array = [3.14, 1.59, 2.65, 5.35]
Output: Sorted Array = [1.59, 2.65, 3.14, 5.35]
Q32. Write a C# program to check if an array is sorted in ascending order.
Input: Array = [10, 20, 30, 40]
Output: Array is sorted in ascending order
Q33. Write a C# program to implement Binary Search on an array of floats.
Input: Array = [1.1, 2.2, 3.3, 4.4], Search = 3.3
Output: Element found at index 2
Q34. Write a C# program to implement Bubble Sort for sorting strings.
Input: Array = ["cat", "apple", "banana", "dog"]
Output: Sorted Array = ["apple", "banana", "cat", "dog"]
Q35. Write a C# program to sort an array of integers in descending order using Quick Sort.
Input: Array = [10, 80, 30, 90, 40, 50, 70]
Output: Sorted Array = [90, 80, 70, 50, 40, 30, 10]
Q36. Write a C# program to implement the Shell Sort algorithm.
Input: Array = [5, 2, 9, 1, 5, 6]
Output: Sorted Array = [1, 2, 5, 5, 6, 9]
Q37. Write a C# program to find the median of an array.
Input: Array = [1, 3, 5, 7, 9]
Output: Median = 5
Q38. Write a C# program to find the number of elements in an array greater than a given number using Linear Search.
Input: Array = [10, 20, 30, 40, 50], number = 25
Output: Count = 3
Q39. Write a C# program to perform Binary Search on a sorted array of characters.
Input: Array = ['a', 'b', 'c', 'd', 'e'], Search = 'c'
Output: Element found at index 2
Q40. Write a C# program to implement Selection Sort in ascending order.
Input: Array = [3, 1, 4, 5, 2]
Output: Sorted Array = [1, 2, 3, 4, 5]
Q41. Write a C# program to sort an array using the Heap Sort algorithm.
Input: Array = [4, 10, 3, 5, 1]
Output: Sorted Array = [1, 3, 4, 5, 10]
Q42. Write a C# program to implement Binary Search and return true if the element is found, false otherwise.
Input: Array = [1, 2, 3, 4, 5], Search = 3
Output: True
Q43. Write a C# program to find the index of the largest number in an array using Linear Search.
Input: Array = [12, 56, 34, 78, 90]
Output: Index of largest number = 4
Q44. Write a C# program to sort an array using Radix Sort.
Input: Array = [170, 45, 75, 90, 802, 24, 2, 66]
Output: Sorted Array = [2, 24, 45, 66, 75, 90, 170, 802]
Q45. Write a C# program to find the common elements in two arrays using Linear Search.
Input: Array1 = [1, 2, 3, 4], Array2 = [3, 4, 5, 6]
Output: Common elements = 3, 4
Q46. Write a C# program to find if a number exists in a sorted array using Binary Search.
Input: Array = [1, 3, 5, 7, 9], Search = 5
Output: Element found
Q47. Write a C# program to implement the Radix Sort algorithm for sorting numbers.
Input: Array = [170, 45, 75, 90, 802]
Output: Sorted Array = [45, 75, 90, 170, 802]
Q48. Write a C# program to perform a binary search on a list of strings.
Input: Array = ["apple", "banana", "cherry", "date"], Search = "banana"
Output: Element found at index 1
Q49. Write a C# program to implement Merge Sort with an array of floats.
Input: Array = [12.5, 7.3, 5.8, 9.2, 11.1]
Output: Sorted Array = [5.8, 7.3, 9.2, 11.1, 12.5]
Q50. Write a C# program to perform Bubble Sort and print the number of swaps.
Input: Array = [5, 1, 4, 2, 8]
Output: Sorted Array = [1, 2, 4, 5, 8], Swaps = 5
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!