Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e22313b
2.3 Prepared
ikesnowy Jul 5, 2018
4d88405
修改 README,增加 2.3 的链接
ikesnowy Jul 6, 2018
bfd734b
添加 QuickSort 类库
ikesnowy Jul 6, 2018
ff64c52
2.3.1 Finished
ikesnowy Jul 6, 2018
36bc40b
2.3.2 Finished
ikesnowy Jul 6, 2018
2187e3c
2.3.3 Finished
ikesnowy Jul 8, 2018
76f8d31
2.3.4 Finished
ikesnowy Jul 8, 2018
b5e8d0b
2.3.5 Finished
ikesnowy Jul 8, 2018
4923f77
fix bug in 2.3.5
ikesnowy Jul 9, 2018
817674f
清除不必要的 using
ikesnowy Jul 9, 2018
cfd40e9
2.3.6 Finished
ikesnowy Jul 9, 2018
27b9ee0
2.3.7 Finihed
ikesnowy Jul 10, 2018
f8d7445
删除不必要的 using
ikesnowy Jul 10, 2018
f1f89c9
2.3.8 Finished
ikesnowy Jul 10, 2018
16f80a3
删除不必要的using
ikesnowy Jul 10, 2018
e88d46b
增加 QuickSortAnalyze 类,减少冗余。
ikesnowy Jul 11, 2018
e5bbe39
2.3.9 Finished
ikesnowy Jul 11, 2018
b3cd25e
2.3.10 Finished
ikesnowy Jul 11, 2018
3ea95d1
2.3.11 Finished
ikesnowy Jul 11, 2018
5cc2e5d
2.3.12 Finished
ikesnowy Jul 11, 2018
2b51284
2.3.13 Finished
ikesnowy Jul 12, 2018
e23d499
2.3.14
ikesnowy Jul 14, 2018
d92b5d2
2.3.15 Finished
ikesnowy Jul 15, 2018
1c10426
移除不必要的引用
ikesnowy Jul 15, 2018
6e3255f
2.3.16 Finished
ikesnowy Jul 19, 2018
085ead0
2.3.17 Finished
ikesnowy Jul 22, 2018
aec3ec8
typo fix
ikesnowy Jul 22, 2018
79308c4
2.3.18 Finished
ikesnowy Jul 24, 2018
af2fa68
Implement QuickSortMedian
ikesnowy Jul 26, 2018
742985b
Fix Median Bug
ikesnowy Jul 27, 2018
e96af8e
update README
ikesnowy Jul 27, 2018
2fc7884
Optimize QuickSortMedian3
ikesnowy Jul 27, 2018
26f8c85
2.3.19 Finished
ikesnowy Jul 28, 2018
d172075
2.3.20 Finished
ikesnowy Jul 29, 2018
fda6084
2.3.21 Finished
ikesnowy Jul 31, 2018
ad3973d
2.3.22 Finished
ikesnowy Aug 1, 2018
4d24ff2
remove left side check
ikesnowy Aug 2, 2018
a6f6f98
2.3.23 Finished
ikesnowy Aug 4, 2018
1838087
Update README.md
ikesnowy Aug 5, 2018
464ef1d
2.3.24 Finished
ikesnowy Aug 5, 2018
2db30c4
Merge branch 'dev' of https://github.com/ikesnowy/Algorithms-4th-Edit…
ikesnowy Aug 5, 2018
c09b578
change the sample array size to 2^k - 1
ikesnowy Aug 5, 2018
77e2ece
change test case in 2.3.24
ikesnowy Aug 6, 2018
db080e9
2.3.25 Finished
ikesnowy Aug 6, 2018
59e9578
add comments for 2.3.25
ikesnowy Aug 6, 2018
248cc48
2.3.26 Finished
ikesnowy Aug 6, 2018
54d2789
2.3.27 Finished
ikesnowy Aug 6, 2018
2dc2dee
2.3.38 Finished
ikesnowy Aug 6, 2018
9c3be4b
2.3.29 Finished
ikesnowy Aug 6, 2018
a443007
2.3.30 Finished
ikesnowy Aug 6, 2018
36df1b0
2.3.31 Finished
ikesnowy Aug 7, 2018
5fb692a
Build solution 2.3
ikesnowy Aug 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 Sorting/2.1/2.1.18/Form3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class Form3 : Form
double[] randomDoubles;
int sortI;
int sortJ;
int n = 0;

public Form3(int N)
{
InitializeComponent();
Expand Down
5 changes: 0 additions & 5 deletions 2 Sorting/2.2/2.2.26/AuxInMergeMergeSort.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Merge;

namespace _2._2._26
Expand Down
5 changes: 0 additions & 5 deletions 2 Sorting/2.2/2.2.26/AuxInSortMergeSort.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Merge;

namespace _2._2._26
Expand Down
52 changes: 52 additions & 0 deletions 2 Sorting/2.3/2.3.1/2.3.1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0B42B539-F300-4D97-B4D0-47249CCC6F01}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>_2._3._1</RootNamespace>
<AssemblyName>2.3.1</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions 2 Sorting/2.3/2.3.1/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
</configuration>
24 changes: 24 additions & 0 deletions 2 Sorting/2.3/2.3.1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace _2._3._1
{
/*
* 2.3.1
*
* 按照 Partition() 方法的轨迹的格式给出该方法是如何切分数组
* E A S Y Q U E S T I O N 的。
*
*/
class Program
{
static void Main(string[] args)
{
// a[]
// i j 0 1 2 3 4 5 6 7 8 9 10 11
// 0 16 E A S Y Q U E S T I O N
// 1 6 E A S Y Q U E S T I O N
// 1 6 E A E Y Q U S S T I O N
// 3 2 E A E Y Q U S S T I O N
// 3 2 E A E Y Q U S S T I O N
// 2 E A E Y Q U S S T I O N
}
}
}
35 changes: 35 additions & 0 deletions 2 Sorting/2.3/2.3.1/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("2.3.1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("2.3.1")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("0b42b539-f300-4d97-b4d0-47249ccc6f01")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
52 changes: 52 additions & 0 deletions 2 Sorting/2.3/2.3.10/2.3.10.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A084203F-4C71-4A74-9D8B-F76EFD052845}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>_2._3._10</RootNamespace>
<AssemblyName>2.3.10</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions 2 Sorting/2.3/2.3.10/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
</configuration>
34 changes: 34 additions & 0 deletions 2 Sorting/2.3/2.3.10/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

namespace _2._3._10
{
/*
* 2.3.10
*
* Chebyshev 不等式表明,
* 一个随机变量的标准差距离均值大于 k 的概率小于 1/k^2 。
* 对于 N=100 万,
* 用 Chebyshev 不等式计算快速排序所使用的比较次数大于 1000 亿次的概率(0.1N^2)。
*
*/
class Program
{
static void Main(string[] args)
{
// 切比雪夫不等式(Chebyshev's inequality)
// P(|X-μ| ≥ kσ) ≤ 1/(k^2)
// 其中 μ 是期望,σ 是标准差。
// 在快速排序的比较次数中,μ=2NlnN,σ=0.65N
// (这两个结论可以见 2.3 节的命题 K 和命题 L)
// 题目中要求比较次数大于 0.1N^2,可以得到等式:
// 0.65N * k = 0.1N^2
// k = 2/13 * N
// 将 N = 1 000 000 代入
// P(|X-27 631 021| ≥ 100 000 000 000) ≤ 0.00000000004225
// P ≤ 0.000000004225 %
double N = 10000000;
double k = 0.1 * N / 0.65;
Console.WriteLine(1.0 / (k * k));//4.225x10^-13
}
}
}
35 changes: 35 additions & 0 deletions 2 Sorting/2.3/2.3.10/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("2.3.10")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("2.3.10")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("a084203f-4c71-4a74-9d8b-f76efd052845")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
52 changes: 52 additions & 0 deletions 2 Sorting/2.3/2.3.11/2.3.11.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{14D53C1D-F1DF-4826-9063-A087C55B289B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>_2._3._11</RootNamespace>
<AssemblyName>2.3.11</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions 2 Sorting/2.3/2.3.11/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
</configuration>
26 changes: 26 additions & 0 deletions 2 Sorting/2.3/2.3.11/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace _2._3._11
{
/*
* 2.3.11
*
* 假如在遇到和切分元素重复的元素时我们继续扫描数组而不是停下来,
* 证明使用这种方法的快速排序在处理只有若干种元素值的数组时运行时间是平方级别的。
*
*/
class Program
{
static void Main(string[] args)
{
// 只有若干种元素值意味着大量的连续重复。
//(由于存在打乱这一步骤,不存在连续重复的可能性是很低的)
// 接下来我们考虑这样的连续重复在修改后的快排下的性能。
// 1 1 1 1 1 1 1
// 对于这样的数组,枢轴选为 1,j 将会在 j = lo 处终止。
// 因此最后的结果将是每次只有数组的第一个元素被排序
// 已知每次切分都是 O(k - 1) 的(i 和 j 都将走完整个子数组)
// 因此这样的快速排序所需时间 = 2*(N-1 + N-2 + ... + 1) = (N-1)N
// 因此对于值相同的子数组,这样的快排运行时间是平方级别的
// 那么当数组中这样的连续重复内容越多,运行时间就越接近平方级别。
}
}
}
Loading