Skip to content

Commit 5b0ec0f

Browse files
📦 NEW: First Version
1 parent 8df3585 commit 5b0ec0f

38 files changed

+1009149
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29418.71
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BruteForceAlgorithm", "BruteForceAlgorithm\BruteForceAlgorithm.vcxproj", "{DF693D5B-7521-419D-A70B-10C0922A26CB}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{DF693D5B-7521-419D-A70B-10C0922A26CB}.Debug|x64.ActiveCfg = Debug|x64
17+
{DF693D5B-7521-419D-A70B-10C0922A26CB}.Debug|x64.Build.0 = Debug|x64
18+
{DF693D5B-7521-419D-A70B-10C0922A26CB}.Debug|x86.ActiveCfg = Debug|Win32
19+
{DF693D5B-7521-419D-A70B-10C0922A26CB}.Debug|x86.Build.0 = Debug|Win32
20+
{DF693D5B-7521-419D-A70B-10C0922A26CB}.Release|x64.ActiveCfg = Release|x64
21+
{DF693D5B-7521-419D-A70B-10C0922A26CB}.Release|x64.Build.0 = Release|x64
22+
{DF693D5B-7521-419D-A70B-10C0922A26CB}.Release|x86.ActiveCfg = Release|Win32
23+
{DF693D5B-7521-419D-A70B-10C0922A26CB}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {F7BE5877-7B83-4B21-B03F-3A6F089CC5AF}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
27808
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<ProjectGuid>{DF693D5B-7521-419D-A70B-10C0922A26CB}</ProjectGuid>
24+
<RootNamespace>BruteForceAlgorithm</RootNamespace>
25+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29+
<ConfigurationType>Application</ConfigurationType>
30+
<UseDebugLibraries>true</UseDebugLibraries>
31+
<PlatformToolset>v142</PlatformToolset>
32+
<CharacterSet>MultiByte</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
35+
<ConfigurationType>Application</ConfigurationType>
36+
<UseDebugLibraries>false</UseDebugLibraries>
37+
<PlatformToolset>v142</PlatformToolset>
38+
<WholeProgramOptimization>true</WholeProgramOptimization>
39+
<CharacterSet>MultiByte</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v142</PlatformToolset>
45+
<CharacterSet>MultiByte</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v142</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>MultiByte</CharacterSet>
53+
</PropertyGroup>
54+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55+
<ImportGroup Label="ExtensionSettings">
56+
</ImportGroup>
57+
<ImportGroup Label="Shared">
58+
</ImportGroup>
59+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<PropertyGroup Label="UserMacros" />
72+
<PropertyGroup />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<Optimization>Disabled</Optimization>
77+
<SDLCheck>true</SDLCheck>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<SubSystem>Console</SubSystem>
82+
</Link>
83+
</ItemDefinitionGroup>
84+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
85+
<ClCompile>
86+
<WarningLevel>Level3</WarningLevel>
87+
<Optimization>Disabled</Optimization>
88+
<SDLCheck>true</SDLCheck>
89+
<ConformanceMode>true</ConformanceMode>
90+
</ClCompile>
91+
<Link>
92+
<SubSystem>Console</SubSystem>
93+
</Link>
94+
</ItemDefinitionGroup>
95+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
96+
<ClCompile>
97+
<WarningLevel>Level3</WarningLevel>
98+
<Optimization>MaxSpeed</Optimization>
99+
<FunctionLevelLinking>true</FunctionLevelLinking>
100+
<IntrinsicFunctions>true</IntrinsicFunctions>
101+
<SDLCheck>true</SDLCheck>
102+
<ConformanceMode>true</ConformanceMode>
103+
</ClCompile>
104+
<Link>
105+
<SubSystem>Console</SubSystem>
106+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
107+
<OptimizeReferences>true</OptimizeReferences>
108+
</Link>
109+
</ItemDefinitionGroup>
110+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
111+
<ClCompile>
112+
<WarningLevel>Level3</WarningLevel>
113+
<Optimization>MaxSpeed</Optimization>
114+
<FunctionLevelLinking>true</FunctionLevelLinking>
115+
<IntrinsicFunctions>true</IntrinsicFunctions>
116+
<SDLCheck>true</SDLCheck>
117+
<ConformanceMode>true</ConformanceMode>
118+
</ClCompile>
119+
<Link>
120+
<SubSystem>Console</SubSystem>
121+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
122+
<OptimizeReferences>true</OptimizeReferences>
123+
</Link>
124+
</ItemDefinitionGroup>
125+
<ItemGroup>
126+
<ClCompile Include="Task1.cpp" />
127+
</ItemGroup>
128+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
129+
<ImportGroup Label="ExtensionTargets">
130+
</ImportGroup>
131+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="Task1.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//Libraries
2+
#include <iostream>
3+
#include <math.h>
4+
#include <cstdlib>
5+
#include <ctime>
6+
#include <fstream>
7+
#include <iomanip>
8+
#include <chrono>
9+
using namespace std;
10+
// We use this record to be returned by the function that finds
11+
// the maximum sub-array.
12+
struct MaxSubArrayRecord
13+
{
14+
// Holds the starting index of the sub-array.
15+
int startIndex=0;
16+
// Holds the ending index of the sub-array.
17+
int endIndex=0;
18+
// Holds the sum of all the elements within the sub-array.
19+
int maxSum=0;
20+
};
21+
//ProtoTypes of functions used in the Program
22+
void RandomArray(int array[], int size);
23+
MaxSubArrayRecord findMaxArrayBruteForce(int A[],int start, int end);
24+
25+
26+
int main() {
27+
28+
MaxSubArrayRecord obj;
29+
ofstream outputFile;
30+
int SIZE;
31+
cout << "Enter number of integers" << endl;
32+
cin >> SIZE;
33+
int* array = new int[SIZE];
34+
35+
//Generating Random integers
36+
RandomArray(array, SIZE);
37+
38+
39+
auto start = chrono::high_resolution_clock::now(); //Variable to store starting time
40+
41+
obj = findMaxArrayBruteForce(array, 0,SIZE-1);
42+
43+
auto end = chrono::high_resolution_clock::now();
44+
double time_taken = chrono::duration_cast<chrono::nanoseconds>(end - start).count();
45+
time_taken *= 1e-9;
46+
cout << "Time taken by program is : " << fixed << time_taken << setprecision(10)<<endl;
47+
48+
//Storing the sorted array in the file
49+
outputFile.open("BruteForce.csv");
50+
for (int i = 0; i < SIZE; i++) {
51+
outputFile << array[i] << endl;
52+
53+
}
54+
outputFile.close();
55+
56+
57+
58+
cout << "Start index " << obj.startIndex << endl;
59+
cout << "End index " << obj.endIndex << endl;
60+
cout << "Max Sum " << obj.maxSum<<endl;
61+
62+
//deleting the dynamically allocated array
63+
delete[] array;
64+
system("pause");
65+
return 0;
66+
}
67+
68+
69+
//Function to generate random numbers
70+
void RandomArray(int array[], int size) {
71+
srand(time(0));
72+
int var;
73+
for (int i = 0; i < size; ++i) {
74+
var = rand() % 1000000;
75+
if ((var % 2) != 0) {
76+
var = var * (-1);
77+
}
78+
array[i] = var;
79+
}
80+
}
81+
82+
//Brute force algorithm to find max sub array
83+
MaxSubArrayRecord findMaxArrayBruteForce(int A[], int start, int end)
84+
{
85+
int size = (end - start) + 1;
86+
if(size>1){ //when size of array is greater then 1
87+
int maxSum = -99999999;
88+
int low;
89+
int high;
90+
91+
for (int i = 0; i < size; i++)
92+
{
93+
int sum = 0;
94+
for (int j = i; j < size; j++)
95+
{
96+
sum = sum + A[j];
97+
if (sum > maxSum)
98+
{
99+
maxSum = sum;
100+
low = i;
101+
high = j;
102+
}
103+
}
104+
}
105+
106+
//Storing calculated values in the object we want to return
107+
MaxSubArrayRecord result;
108+
result.startIndex = low;
109+
result.endIndex = high;
110+
result.maxSum = maxSum;
111+
return result;
112+
}
113+
//Storing calculated values in the object when array contains only 1 elelment
114+
MaxSubArrayRecord obj;
115+
obj.startIndex = start;
116+
obj.endIndex = end;
117+
obj.maxSum = A[start];
118+
return obj;
119+
120+
}
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29418.71
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HybridMaxSubArray", "HybridMaxSubArray\HybridMaxSubArray.vcxproj", "{17D3BF95-B211-47DC-9BEC-4682FCD8675A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{17D3BF95-B211-47DC-9BEC-4682FCD8675A}.Debug|x64.ActiveCfg = Debug|x64
17+
{17D3BF95-B211-47DC-9BEC-4682FCD8675A}.Debug|x64.Build.0 = Debug|x64
18+
{17D3BF95-B211-47DC-9BEC-4682FCD8675A}.Debug|x86.ActiveCfg = Debug|Win32
19+
{17D3BF95-B211-47DC-9BEC-4682FCD8675A}.Debug|x86.Build.0 = Debug|Win32
20+
{17D3BF95-B211-47DC-9BEC-4682FCD8675A}.Release|x64.ActiveCfg = Release|x64
21+
{17D3BF95-B211-47DC-9BEC-4682FCD8675A}.Release|x64.Build.0 = Release|x64
22+
{17D3BF95-B211-47DC-9BEC-4682FCD8675A}.Release|x86.ActiveCfg = Release|Win32
23+
{17D3BF95-B211-47DC-9BEC-4682FCD8675A}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {3627D537-D1A5-4D52-A798-E0B8F6289411}
30+
EndGlobalSection
31+
EndGlobal

0 commit comments

Comments
 (0)