0% found this document useful (0 votes)
8 views1 page

Array Manipulation Algorithms Guide

The document outlines five programming problems involving array manipulation. It includes reversing an array in-place, calculating sums of positive and negative integers, searching for a target value, implementing a binary search on a sorted array, and merging two integer arrays into a third array. Each problem provides input and expected output examples along with hints or instructions for implementation.

Uploaded by

nicolenajjar63
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Array Manipulation Algorithms Guide

The document outlines five programming problems involving array manipulation. It includes reversing an array in-place, calculating sums of positive and negative integers, searching for a target value, implementing a binary search on a sorted array, and merging two integer arrays into a third array. Each problem provides input and expected output examples along with hints or instructions for implementation.

Uploaded by

nicolenajjar63
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like