1.
Reverse an Array (In-Place)
Problem: Write a function that reverses an array in-place, meaning you modify the
original array without creating a new one.
● Input: [1, 2, 3, 4, 5]
● Output: [5, 4, 3, 2, 1] (the original array is now changed)
Hint: Think about swapping elements. You'll need a temporary variable to hold one
value during the swap. Use two "pointers" (indices), one starting at the beginning
and one at the end, moving towards the center.
2. Write an algorithm that iterates through an array of positive, negative,
and zero integers and calculates two separate sums: the total sum of all
positive numbers, and the total sum of all negative numbers.
3. Write an algorithm that searches for a specific target value within an
array. The program should return the index (position) of the first
occurrence of the element if found, or a message indicating it was not
found.
4. Write an algorithm that searches for a target value in a sorted array
using the highly efficient binary search algorithm. The program should
return the index of the element if found.
Binary search requires the array to be sorted. It works by repeatedly dividing
the search interval in half. Define three indices: low (start of the segment),
high (end of the segment), and mid (the middle element). Compare the
target with the value at mid:
● If target equals mid, return mid.
● If target is less than mid, set high = mid - 1.
● If target is greater than mid, set low = mid + 1.
5. Write an algorithm that takes two separate integer arrays, A and B, and
merges all their elements into a third, larger array, C. Print the resulting
merged array.