-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89c7f34
commit 97d0d4a
Showing
11 changed files
with
1,243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: clean | ||
clean: | ||
rm -rf _site .jekyll-cache | ||
|
||
.PHONY: push | ||
push: | ||
git commit -am "coding ..." && \ | ||
git push origin `git branch | grep \* | cut -d ' ' -f2` | ||
|
||
.PHONY: build | ||
build: | ||
jekyll build | ||
cp -r _site/* ../docs/algorithms/ | ||
rm ../docs/algorithms/Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
layout: post | ||
title: "Quicksort" | ||
date: 2023-11-20 20:46:37 +0200 | ||
categories: algorithm | ||
--- | ||
|
||
# Introduction | ||
|
||
Quicksort was developed by British computer scientist Tony Hoare in 1959. It is one of the most widely used sorting algorithms and is commonly used in computer science and engineering applications. | ||
|
||
Quicksort is particularly useful when sorting large datasets because it has an average time complexity of O(n log n), which is faster than many other sorting algorithms. It is also an in-place sorting algorithm, meaning that it does not require any additional memory beyond the input array. | ||
|
||
Quicksort is used in a variety of applications, including sorting large databases, sorting elements in computer graphics and image processing, and in network routing algorithms. It is also used in many programming languages as a built-in sorting function, such as Python's `sorted()` function and C++'s `std::sort()` function. | ||
|
||
# Implementation | ||
|
||
``` | ||
let rec quicksort = function | ||
| [] -> [] | ||
| pivot::tail -> | ||
let lesser, greater = List.partition (fun x -> x < pivot) tail in | ||
quicksort lesser @ [pivot] @ quicksort greater | ||
``` | ||
|
||
This implementation uses a functional programming style and takes advantage of pattern matching to handle the two cases of the input list: the empty list, which is already sorted, and a non-empty list, which is partitioned into two sub-lists based on a pivot element (in this case, the first element of the list). | ||
|
||
The `List.partition` function is used to split the tail of the input list into two sub-lists: `lesser`, which contains all elements that are strictly less than the pivot, and `greater`, which contains all elements that are greater than or equal to the pivot. The `@` operator is used to concatenate the sorted `lesser` sub-list, the pivot element, and the sorted `greater` sub-list into a single sorted list. | ||
|
||
Here's an example usage of the `quicksort` function: | ||
|
||
``` | ||
let unsorted = [5; 1; 3; 9; 2] | ||
let sorted = quicksort unsorted | ||
``` | ||
|
||
After running this code, the `sorted` variable should contain the list `[1; 2; 3; 5; 9]`, which is the sorted version of the `unsorted` list. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.8.0 --> | ||
<title>Your awesome title | Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.</title> | ||
<meta name="generator" content="Jekyll v4.3.2" /> | ||
<meta property="og:title" content="Your awesome title" /> | ||
<meta property="og:locale" content="en_US" /> | ||
<meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description." /> | ||
<meta property="og:description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description." /> | ||
<link rel="canonical" href="/404.html" /> | ||
<meta property="og:url" content="/404.html" /> | ||
<meta property="og:site_name" content="Your awesome title" /> | ||
<meta property="og:type" content="website" /> | ||
<meta name="twitter:card" content="summary" /> | ||
<meta property="twitter:title" content="Your awesome title" /> | ||
<script type="application/ld+json"> | ||
{"@context":"https://schema.org","@type":"WebPage","description":"Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.","headline":"Your awesome title","url":"/404.html"}</script> | ||
<!-- End Jekyll SEO tag --> | ||
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="/feed.xml" title="Your awesome title" /></head> | ||
<body><header class="site-header" role="banner"> | ||
|
||
<div class="wrapper"><a class="site-title" rel="author" href="/">Your awesome title</a><nav class="site-nav"> | ||
<input type="checkbox" id="nav-trigger" class="nav-trigger" /> | ||
<label for="nav-trigger"> | ||
<span class="menu-icon"> | ||
<svg viewBox="0 0 18 15" width="18px" height="15px"> | ||
<path d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.032C17.335,0,18,0.665,18,1.484L18,1.484z M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.032C17.335,6.031,18,6.696,18,7.516L18,7.516z M18,13.516C18,14.335,17.335,15,16.516,15H1.484 C0.665,15,0,14.335,0,13.516l0,0c0-0.82,0.665-1.483,1.484-1.483h15.032C17.335,12.031,18,12.695,18,13.516L18,13.516z"/> | ||
</svg> | ||
</span> | ||
</label> | ||
|
||
<div class="trigger"><a class="page-link" href="/about/">About</a></div> | ||
</nav></div> | ||
</header> | ||
<main class="page-content" aria-label="Content"> | ||
<div class="wrapper"> | ||
<style type="text/css" media="screen"> | ||
.container { | ||
margin: 10px auto; | ||
max-width: 600px; | ||
text-align: center; | ||
} | ||
h1 { | ||
margin: 30px 0; | ||
font-size: 4em; | ||
line-height: 1; | ||
letter-spacing: -1px; | ||
} | ||
</style> | ||
|
||
<div class="container"> | ||
<h1>404</h1> | ||
|
||
<p><strong>Page not found :(</strong></p> | ||
<p>The requested page could not be found.</p> | ||
</div> | ||
|
||
</div> | ||
</main><footer class="site-footer h-card"> | ||
<data class="u-url" href="/"></data> | ||
|
||
<div class="wrapper"> | ||
|
||
<h2 class="footer-heading">Your awesome title</h2> | ||
|
||
<div class="footer-col-wrapper"> | ||
<div class="footer-col footer-col-1"> | ||
<ul class="contact-list"> | ||
<li class="p-name">Your awesome title</li><li><a class="u-email" href="mailto:your-email@example.com">your-email@example.com</a></li></ul> | ||
</div> | ||
|
||
<div class="footer-col footer-col-2"><ul class="social-media-list"><li><a href="https://github.com/jekyll"><svg class="svg-icon"><use xlink:href="/assets/minima-social-icons.svg#github"></use></svg> <span class="username">jekyll</span></a></li><li><a href="https://www.twitter.com/jekyllrb"><svg class="svg-icon"><use xlink:href="/assets/minima-social-icons.svg#twitter"></use></svg> <span class="username">jekyllrb</span></a></li></ul> | ||
</div> | ||
|
||
<div class="footer-col footer-col-3"> | ||
<p>Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.</p> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
</footer> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.8.0 --> | ||
<title>About | Your awesome title</title> | ||
<meta name="generator" content="Jekyll v4.3.2" /> | ||
<meta property="og:title" content="About" /> | ||
<meta property="og:locale" content="en_US" /> | ||
<meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description." /> | ||
<meta property="og:description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description." /> | ||
<link rel="canonical" href="/about/" /> | ||
<meta property="og:url" content="/about/" /> | ||
<meta property="og:site_name" content="Your awesome title" /> | ||
<meta property="og:type" content="website" /> | ||
<meta name="twitter:card" content="summary" /> | ||
<meta property="twitter:title" content="About" /> | ||
<script type="application/ld+json"> | ||
{"@context":"https://schema.org","@type":"WebSite","description":"Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.","headline":"About","name":"Your awesome title","url":"/about/"}</script> | ||
<!-- End Jekyll SEO tag --> | ||
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="/feed.xml" title="Your awesome title" /></head> | ||
<body><header class="site-header" role="banner"> | ||
|
||
<div class="wrapper"><a class="site-title" rel="author" href="/">Your awesome title</a><nav class="site-nav"> | ||
<input type="checkbox" id="nav-trigger" class="nav-trigger" /> | ||
<label for="nav-trigger"> | ||
<span class="menu-icon"> | ||
<svg viewBox="0 0 18 15" width="18px" height="15px"> | ||
<path d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.032C17.335,0,18,0.665,18,1.484L18,1.484z M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.032C17.335,6.031,18,6.696,18,7.516L18,7.516z M18,13.516C18,14.335,17.335,15,16.516,15H1.484 C0.665,15,0,14.335,0,13.516l0,0c0-0.82,0.665-1.483,1.484-1.483h15.032C17.335,12.031,18,12.695,18,13.516L18,13.516z"/> | ||
</svg> | ||
</span> | ||
</label> | ||
|
||
<div class="trigger"><a class="page-link" href="/about/">About</a></div> | ||
</nav></div> | ||
</header> | ||
<main class="page-content" aria-label="Content"> | ||
<div class="wrapper"> | ||
<article class="post"> | ||
|
||
<header class="post-header"> | ||
<h1 class="post-title">About</h1> | ||
</header> | ||
|
||
<div class="post-content"> | ||
<p>This is the base Jekyll theme. You can find out more info about customizing your Jekyll theme, as well as basic Jekyll usage documentation at <a href="https://jekyllrb.com/">jekyllrb.com</a></p> | ||
|
||
<p>You can find the source code for Minima at GitHub: | ||
<a href="https://github.com/jekyll">jekyll</a> / | ||
<a href="https://github.com/jekyll/minima">minima</a></p> | ||
|
||
<p>You can find the source code for Jekyll at GitHub: | ||
<a href="https://github.com/jekyll">jekyll</a> / | ||
<a href="https://github.com/jekyll/jekyll">jekyll</a></p> | ||
|
||
|
||
</div> | ||
|
||
</article> | ||
|
||
</div> | ||
</main><footer class="site-footer h-card"> | ||
<data class="u-url" href="/"></data> | ||
|
||
<div class="wrapper"> | ||
|
||
<h2 class="footer-heading">Your awesome title</h2> | ||
|
||
<div class="footer-col-wrapper"> | ||
<div class="footer-col footer-col-1"> | ||
<ul class="contact-list"> | ||
<li class="p-name">Your awesome title</li><li><a class="u-email" href="mailto:your-email@example.com">your-email@example.com</a></li></ul> | ||
</div> | ||
|
||
<div class="footer-col footer-col-2"><ul class="social-media-list"><li><a href="https://github.com/jekyll"><svg class="svg-icon"><use xlink:href="/assets/minima-social-icons.svg#github"></use></svg> <span class="username">jekyll</span></a></li><li><a href="https://www.twitter.com/jekyllrb"><svg class="svg-icon"><use xlink:href="/assets/minima-social-icons.svg#twitter"></use></svg> <span class="username">jekyllrb</span></a></li></ul> | ||
</div> | ||
|
||
<div class="footer-col footer-col-3"> | ||
<p>Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.</p> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
</footer> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.8.0 --> | ||
<title>Quicksort | Your awesome title</title> | ||
<meta name="generator" content="Jekyll v4.3.2" /> | ||
<meta property="og:title" content="Quicksort" /> | ||
<meta property="og:locale" content="en_US" /> | ||
<meta name="description" content="Introduction" /> | ||
<meta property="og:description" content="Introduction" /> | ||
<link rel="canonical" href="/algorithm/2023/11/20/quicksort.html" /> | ||
<meta property="og:url" content="/algorithm/2023/11/20/quicksort.html" /> | ||
<meta property="og:site_name" content="Your awesome title" /> | ||
<meta property="og:type" content="article" /> | ||
<meta property="article:published_time" content="2023-11-20T20:46:37+02:00" /> | ||
<meta name="twitter:card" content="summary" /> | ||
<meta property="twitter:title" content="Quicksort" /> | ||
<script type="application/ld+json"> | ||
{"@context":"https://schema.org","@type":"BlogPosting","dateModified":"2023-11-20T20:46:37+02:00","datePublished":"2023-11-20T20:46:37+02:00","description":"Introduction","headline":"Quicksort","mainEntityOfPage":{"@type":"WebPage","@id":"/algorithm/2023/11/20/quicksort.html"},"url":"/algorithm/2023/11/20/quicksort.html"}</script> | ||
<!-- End Jekyll SEO tag --> | ||
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="/feed.xml" title="Your awesome title" /></head> | ||
<body><header class="site-header" role="banner"> | ||
|
||
<div class="wrapper"><a class="site-title" rel="author" href="/">Your awesome title</a><nav class="site-nav"> | ||
<input type="checkbox" id="nav-trigger" class="nav-trigger" /> | ||
<label for="nav-trigger"> | ||
<span class="menu-icon"> | ||
<svg viewBox="0 0 18 15" width="18px" height="15px"> | ||
<path d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.032C17.335,0,18,0.665,18,1.484L18,1.484z M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.032C17.335,6.031,18,6.696,18,7.516L18,7.516z M18,13.516C18,14.335,17.335,15,16.516,15H1.484 C0.665,15,0,14.335,0,13.516l0,0c0-0.82,0.665-1.483,1.484-1.483h15.032C17.335,12.031,18,12.695,18,13.516L18,13.516z"/> | ||
</svg> | ||
</span> | ||
</label> | ||
|
||
<div class="trigger"><a class="page-link" href="/about/">About</a></div> | ||
</nav></div> | ||
</header> | ||
<main class="page-content" aria-label="Content"> | ||
<div class="wrapper"> | ||
<article class="post h-entry" itemscope itemtype="http://schema.org/BlogPosting"> | ||
|
||
<header class="post-header"> | ||
<h1 class="post-title p-name" itemprop="name headline">Quicksort</h1> | ||
<p class="post-meta"> | ||
<time class="dt-published" datetime="2023-11-20T20:46:37+02:00" itemprop="datePublished">Nov 20, 2023 | ||
</time></p> | ||
</header> | ||
|
||
<div class="post-content e-content" itemprop="articleBody"> | ||
<h1 id="introduction">Introduction</h1> | ||
|
||
<p>Quicksort was developed by British computer scientist Tony Hoare in 1959. It is one of the most widely used sorting algorithms and is commonly used in computer science and engineering applications.</p> | ||
|
||
<p>Quicksort is particularly useful when sorting large datasets because it has an average time complexity of O(n log n), which is faster than many other sorting algorithms. It is also an in-place sorting algorithm, meaning that it does not require any additional memory beyond the input array.</p> | ||
|
||
<p>Quicksort is used in a variety of applications, including sorting large databases, sorting elements in computer graphics and image processing, and in network routing algorithms. It is also used in many programming languages as a built-in sorting function, such as Python’s <code class="language-plaintext highlighter-rouge">sorted()</code> function and C++’s <code class="language-plaintext highlighter-rouge">std::sort()</code> function.</p> | ||
|
||
<h1 id="implementation">Implementation</h1> | ||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>let rec quicksort = function | ||
| [] -> [] | ||
| pivot::tail -> | ||
let lesser, greater = List.partition (fun x -> x < pivot) tail in | ||
quicksort lesser @ [pivot] @ quicksort greater | ||
</code></pre></div></div> | ||
|
||
<p>This implementation uses a functional programming style and takes advantage of pattern matching to handle the two cases of the input list: the empty list, which is already sorted, and a non-empty list, which is partitioned into two sub-lists based on a pivot element (in this case, the first element of the list).</p> | ||
|
||
<p>The <code class="language-plaintext highlighter-rouge">List.partition</code> function is used to split the tail of the input list into two sub-lists: <code class="language-plaintext highlighter-rouge">lesser</code>, which contains all elements that are strictly less than the pivot, and <code class="language-plaintext highlighter-rouge">greater</code>, which contains all elements that are greater than or equal to the pivot. The <code class="language-plaintext highlighter-rouge">@</code> operator is used to concatenate the sorted <code class="language-plaintext highlighter-rouge">lesser</code> sub-list, the pivot element, and the sorted <code class="language-plaintext highlighter-rouge">greater</code> sub-list into a single sorted list.</p> | ||
|
||
<p>Here’s an example usage of the <code class="language-plaintext highlighter-rouge">quicksort</code> function:</p> | ||
|
||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>let unsorted = [5; 1; 3; 9; 2] | ||
let sorted = quicksort unsorted | ||
</code></pre></div></div> | ||
|
||
<p>After running this code, the <code class="language-plaintext highlighter-rouge">sorted</code> variable should contain the list <code class="language-plaintext highlighter-rouge">[1; 2; 3; 5; 9]</code>, which is the sorted version of the <code class="language-plaintext highlighter-rouge">unsorted</code> list.</p> | ||
|
||
</div><a class="u-url" href="/algorithm/2023/11/20/quicksort.html" hidden></a> | ||
</article> | ||
|
||
</div> | ||
</main><footer class="site-footer h-card"> | ||
<data class="u-url" href="/"></data> | ||
|
||
<div class="wrapper"> | ||
|
||
<h2 class="footer-heading">Your awesome title</h2> | ||
|
||
<div class="footer-col-wrapper"> | ||
<div class="footer-col footer-col-1"> | ||
<ul class="contact-list"> | ||
<li class="p-name">Your awesome title</li><li><a class="u-email" href="mailto:your-email@example.com">your-email@example.com</a></li></ul> | ||
</div> | ||
|
||
<div class="footer-col footer-col-2"><ul class="social-media-list"><li><a href="https://github.com/jekyll"><svg class="svg-icon"><use xlink:href="/assets/minima-social-icons.svg#github"></use></svg> <span class="username">jekyll</span></a></li><li><a href="https://www.twitter.com/jekyllrb"><svg class="svg-icon"><use xlink:href="/assets/minima-social-icons.svg#twitter"></use></svg> <span class="username">jekyllrb</span></a></li></ul> | ||
</div> | ||
|
||
<div class="footer-col footer-col-3"> | ||
<p>Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.</p> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
</footer> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.