Skip to content

A C algorithm that generates alternating positive/negative integers in range [-10, 10], places them into random array indices, and identifies the contiguous subarray of size N/2 that yields the maximum sum.

License

Notifications You must be signed in to change notification settings

ShotsMan2/Random-Placement-Subarray-Optimizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Random Placement & Subarray Optimizer

This project implements a complex randomization and analysis algorithm in C. It combines Alternating Generation, Stochastic Placement, and Sliding Window Analysis.

โš™๏ธ Algorithm Logic

The process is divided into three phases:

Phase 1: Alternating Generation

Generates a stream of $N$ integers within the range $[-10, 10]$ enforcing a strict pattern:

  • Negative $\to$ Positive $\to$ Negative $\to$ ...

Phase 2: Stochastic Placement (Shuffling)

Unlike standard arrays where elements are placed linearly ($0, 1, 2...$), this algorithm places each generated number into a Random Empty Index.

  • Effectively shuffles the data during insertion.

Phase 3: Analysis (Max Subarray)

Finds the sequence of $N/2$ consecutive elements that has the highest arithmetic mean (or sum).

  • Formula: Maximize $\sum_{j=i}^{i+(N/2)} Array[j]$

๐Ÿš€ Usage

  1. Compile the code:
    gcc main.c -o optimizer
  2. Run the executable:
    ./optimizer
  3. Enter the array size ($N$).

This repository demonstrates randomized data structures and optimization algorithms in C.

About

A C algorithm that generates alternating positive/negative integers in range [-10, 10], places them into random array indices, and identifies the contiguous subarray of size N/2 that yields the maximum sum.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages