Assignment Overview
In this assignment, you will build an Array Operations Toolkit consisting of multiple C programs that demonstrate mastery of arrays. This comprehensive project requires you to apply ALL concepts from Module 4: array basics, sorting algorithms, searching algorithms, multi-dimensional arrays, and string processing.
Arrays (4.1)
Declaration, initialization, traversal, element access
Multi-dimensional (4.2)
2D arrays, matrices, row-column operations
Strings (4.3)
Character arrays, string functions, processing
The Scenario
DataCrunch Analytics
You have been hired as a Junior Software Developer at DataCrunch Analytics, a company that builds data processing tools. Your team lead has assigned you this project:
"We need a collection of utility programs that demonstrate fundamental array algorithms. These will serve as reference implementations for our interns. Create programs for statistical analysis, sorting, searching, matrix operations, and string processing. Make sure to show how each algorithm works step by step!"
Your Task
Create a collection of C programs that implement classic array algorithms. Each program must
compile without warnings using gcc -Wall -Wextra, demonstrate the algorithm's
operation clearly, and follow good coding practices with proper comments.
Requirements
Your toolkit must include ALL of the following programs. Each program is mandatory and will be tested individually.
Array Statistics (array_stats.c)
Create a program that performs statistical analysis on an integer array:
- Take array size (n) and n elements from user input
- Calculate and display: sum, average, minimum, maximum
- Find and display the second largest and second smallest elements
- Count and display the number of even and odd elements
- Find the frequency of each unique element
// Example function signatures
void input_array(int arr[], int size);
int calculate_sum(int arr[], int size);
double calculate_average(int arr[], int size);
int find_min(int arr[], int size);
int find_max(int arr[], int size);
int find_second_largest(int arr[], int size);
void count_even_odd(int arr[], int size, int *even, int *odd);
Sorting Algorithms (sorting.c)
Implement three classic sorting algorithms with visualization:
void bubble_sort(int arr[], int n)- Bubble Sortvoid selection_sort(int arr[], int n)- Selection Sortvoid insertion_sort(int arr[], int n)- Insertion Sort- Display the array after each pass to show sorting progress
- Count and display total number of swaps for each algorithm
- Allow user to choose which algorithm to run
// Display after each pass
void bubble_sort(int arr[], int n) {
int swaps = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
swap(&arr[j], &arr[j + 1]);
swaps++;
}
}
printf("Pass %d: ", i + 1);
print_array(arr, n);
}
printf("Total swaps: %d\n", swaps);
}
Searching Algorithms (searching.c)
Implement searching algorithms with comparison counting:
int linear_search(int arr[], int n, int key, int *comparisons)- Linear Searchint binary_search(int arr[], int n, int key, int *comparisons)- Binary Search- Display number of comparisons made for each search
- For binary search, sort the array first and show the sorted array
- Display the index where element was found, or -1 if not found
- Compare efficiency: search same element with both algorithms
// Binary search with comparison count
int binary_search(int arr[], int n, int key, int *comparisons) {
int low = 0, high = n - 1;
*comparisons = 0;
while (low <= high) {
int mid = (low + high) / 2;
(*comparisons)++;
if (arr[mid] == key) return mid;
else if (arr[mid] < key) low = mid + 1;
else high = mid - 1;
}
return -1;
}
Matrix Operations (matrix.c)
Create a program that performs various matrix operations:
void input_matrix(int mat[][MAX], int rows, int cols)- Input matrixvoid print_matrix(int mat[][MAX], int rows, int cols)- Display matrixvoid add_matrices(int a[][MAX], int b[][MAX], int result[][MAX], int r, int c)- Additionvoid multiply_matrices(...)- Matrix multiplication (check dimensions)void transpose_matrix(int mat[][MAX], int trans[][MAX], int r, int c)- Transpose- Display results in proper matrix format with aligned columns
#define MAX 10
void print_matrix(int mat[][MAX], int rows, int cols) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%4d ", mat[i][j]);
}
printf("\n");
}
}
String Array Processing (string_array.c)
Create a program that processes an array of strings:
- Take an array of 5 names from user input
- Sort names alphabetically using bubble sort (with strcmp)
- Search for a name (case-insensitive comparison)
- Find and display the longest and shortest name
- Reverse each name in place and display
- Count total characters across all names
#define MAX_NAMES 5
#define MAX_LEN 50
void sort_names(char names[][MAX_LEN], int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (strcmp(names[j], names[j + 1]) > 0) {
char temp[MAX_LEN];
strcpy(temp, names[j]);
strcpy(names[j], names[j + 1]);
strcpy(names[j + 1], temp);
}
}
}
}
Array Rotation (rotation.c)
Create a program demonstrating array rotation operations:
void rotate_left(int arr[], int n, int k)- Rotate left by k positionsvoid rotate_right(int arr[], int n, int k)- Rotate right by k positions- Handle cases where k is greater than n
- Display array before and after rotation
- Implement using reversal algorithm for O(n) efficiency
// Efficient rotation using reversal
void reverse(int arr[], int start, int end) {
while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
void rotate_left(int arr[], int n, int k) {
k = k % n; // Handle k > n
reverse(arr, 0, k - 1);
reverse(arr, k, n - 1);
reverse(arr, 0, n - 1);
}
Submission
Create a public GitHub repository with the exact name shown below:
Required Repository Name
array-manipulation-toolkit
Required Files
array-manipulation-toolkit/
├── array_stats.c # Program 1: Statistical analysis
├── sorting.c # Program 2: Sorting algorithms
├── searching.c # Program 3: Searching algorithms
├── matrix.c # Program 4: Matrix operations
├── string_array.c # Program 5: String processing
├── rotation.c # Program 6: Array rotation
├── Makefile # Build all programs with: make all
└── README.md # Documentation (see requirements below)
README.md Must Include:
- Your full name and submission date
- Brief description of each program
- Compilation and usage instructions
- Sample output from at least 3 programs
- Time complexity analysis for sorting/searching algorithms
Makefile Required:
CC = gcc
CFLAGS = -Wall -Wextra -std=c11
all: array_stats sorting searching matrix string_array rotation
array_stats: array_stats.c
$(CC) $(CFLAGS) -o array_stats array_stats.c
# ... similar rules for other programs
clean:
rm -f array_stats sorting searching matrix string_array rotation
Do Include
- All 6 programs implemented and working
- Comments explaining algorithm logic
- Step-by-step output for sorting algorithms
- Comparison counts for searching algorithms
- Proper input validation
- Makefile for easy compilation
- README.md with all required sections
Do Not Include
- Compiled binaries or object files
- Hardcoded array values (must use user input)
- Sorting without showing passes
- Searching without counting comparisons
- Code that does not compile with -Wall -Wextra
- Missing boundary checks for arrays
Enter your GitHub username - we will verify your repository automatically
Grading Rubric
Your assignment will be graded on the following criteria:
| Criteria | Points | Description |
|---|---|---|
| Array Statistics | 20 | All calculations correct, handles edge cases, clean output |
| Sorting Algorithms | 25 | All three algorithms work, shows passes, counts swaps |
| Searching Algorithms | 20 | Both algorithms work, counts comparisons, handles not found |
| Matrix Operations | 20 | All operations work, checks dimensions, proper display format |
| String Array Processing | 15 | Sorting, searching, finding longest/shortest all work |
| Array Rotation | 10 | Both rotations work, handles k > n, efficient implementation |
| Code Quality and Documentation | 10 | Clean code, comments, Makefile, README, no compiler warnings |
| Total | 120 |
Ready to Submit?
Make sure you have completed all requirements and reviewed the grading rubric above.
Submit Your AssignmentWhat You Will Practice
Array Fundamentals (4.1)
Declaration, initialization, traversal, passing arrays to functions
Sorting Algorithms
Bubble Sort, Selection Sort, Insertion Sort, algorithm visualization
Searching Algorithms
Linear Search, Binary Search, complexity analysis, comparison counting
Multi-dimensional Arrays (4.2)
2D arrays, matrix operations, transpose, multiplication
Pro Tips
Sorting Tips
- Bubble Sort: Compare adjacent elements, swap if needed
- Selection Sort: Find minimum, swap with current position
- Insertion Sort: Insert each element into sorted portion
- All three have O(n^2) time complexity
Searching Tips
- Linear Search: O(n) - works on unsorted arrays
- Binary Search: O(log n) - requires sorted array
- Always check if element exists before returning index
- Count comparisons to show algorithm efficiency
Matrix Tips
- For multiplication: A[m x n] * B[n x p] = C[m x p]
- Check dimensions before multiplying
- Transpose: rows become columns, columns become rows
- Use proper formatting for matrix display
Common Mistakes
- Array index out of bounds (0 to n-1)
- Forgetting to sort before binary search
- Not handling empty arrays or single elements
- String comparison with == instead of strcmp