Computer Science & Engineering: Department of
Computer Science & Engineering: Department of
Experiment :- 1
1. Aim:
Given an array, of size, reverse it. Example: If array, arr = {1,2,3,4,5}, after reversing it, the array
should be, arr = {5,4,3,2,1}.
2. Objective:
● To learn about Array Data Structure.
● To learn different approaches to reverse the elements in Array.
3. Implementation/Code:
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int arr[n];
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
for(int i = n - 1; i >= 0; i--) {
printf("%d ", arr[i]);
}
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Output
5. Time Complexity :
Input Reading: Reading nnn elements into the array takes O(n) time.
Array Reversal: Reversing the array using a loop from n−1 to 0 also takes O(n) time.
Overall Time Complexity: The entire program operates in O(n) time complexity due to the
O(n) operations involved in input reading, array reversal, and outputting the results.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
6. Learning Outcomes:
• learn the concept of in-place modification, where the array itself is modified without
requiring additional memory space.
• Understand the time complexity of the array reversal algorithm.
• program encourages algorithmic thinking by presenting a problem (array reversal) and
guiding learners through the steps required to solve it.
• gain a deeper understanding of how array indices work and how pointers can be used
effectively to manipulate array elements.
• Demonstrates the importance of verifying program output to ensure correctness, in this
case, by printing both the original and reversed arrays.