Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 1.53 KB

File metadata and controls

43 lines (30 loc) · 1.53 KB

Odd-Index Statistical Filter

This project implements a data processing algorithm in C designed to analyze specific segments of an integer array based on index parity. It calculates the statistical mean of a subset and filters data based on that metric.

📊 Algorithm Logic

The algorithm processes a dataset $S$ and performs operations on a subset defined by odd indices $I_{odd} = {1, 3, 5, \dots}$.

1. Mean Calculation (Phase I)

First, it calculates the arithmetic mean ($\mu$) of elements at odd positions:

$$\mu = \frac{1}{N} \sum_{k=0}^{N-1} S[2k+1]$$

2. Threshold Filtering (Phase II)

In the second pass, the algorithm filters and prints elements $x$ from the same odd-index subset that satisfy the condition:

$$x > \mu$$

⚙️ Technical Implementation

  • Data Structure: Static Integer Array.
  • Optimization: The loop increments by 2 (i += 2) to directly target odd indices, avoiding unnecessary modulo (%) checks for every element.
  • Precision: Uses double for the average calculation to ensure floating-point accuracy.

🚀 Usage

  1. Compile the code:
    gcc main.c -o index_filter
  2. Run the executable:
    ./index_filter

Example Data

Input Array: { 20, 60, 45, 42, 23, 24, 26, 125, 66, 55, 145, 50, 30, 40 }

  • Target Indices: 1 (60), 3 (42), 5 (24), 7 (125)...
  • Calculated Mean: ~56.57
  • Output (Values > Mean): 60 125 50 (Example approximation)

This repository demonstrates array indexing strategies and conditional filtering in C.