Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb7807c

Browse files
Implemented merge sort (#10 IP)
1 parent f4dcea9 commit fb7807c

File tree

5 files changed

+371
-6
lines changed

5 files changed

+371
-6
lines changed

‎Algorithms/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
- [X] Recursion
55
- [ ] Dynamic Programming
66
- [ ] Comparison Sorting
7-
- [] *Merge Sort*
7+
- [X] *Merge Sort*
88
- [ ] *Quick Sort*
9-
- [] Bubble Sort
10-
- [] Selection Sort
11-
- [] Insertion Sort
9+
- [X] Bubble Sort
10+
- [X] Selection Sort
11+
- [X] Insertion Sort
1212
- [ ] Searching
1313
- [ ] Linear Search
1414
- [ ] Binary Search
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
export const plant_families = {
2+
short_list: [
3+
"Loranthaceae",
4+
"Clusiaceae",
5+
"Aristolochiaceae",
6+
"Myrtaceae",
7+
"Araliaceae",
8+
"Ericaceae",
9+
"Dryopteridaceae",
10+
"Boraginaceae",
11+
"Juncaceae",
12+
"Pottiaceae",
13+
"Amaranthaceae",
14+
"Polemoniaceae",
15+
"Pteridaceae",
16+
"Arthopyreniaceae",
17+
"Campanulaceae",
18+
"Brachytheciaceae",
19+
"Caryophyllaceae",
20+
"Acanthaceae",
21+
"Sematophyllaceae",
22+
"Lamiaceae",
23+
"Lecanoraceae",
24+
"Brassicaceae",
25+
"Rosaceae",
26+
"Orchidaceae",
27+
"Sapotaceae",
28+
"Oleaceae",
29+
"Sapindaceae",
30+
"Amblystegiaceae",
31+
"Droseraceae",
32+
"Lecideaceae",
33+
"Gentianaceae",
34+
"Fabaceae",
35+
"Combretaceae",
36+
"Aspleniaceae",
37+
"Cyperaceae",
38+
"Arthoniaceae",
39+
"Chenopodiaceae",
40+
"Saxifragaceae",
41+
"Euphorbiaceae",
42+
"Passifloraceae",
43+
"Parmeliaceae",
44+
"Celastraceae",
45+
"Myristicaceae",
46+
"Andreaeaceae",
47+
"Poaceae",
48+
"Crassulaceae",
49+
"Asteraceae",
50+
"Stereocaulaceae",
51+
"Onagraceae",
52+
"Verrucariaceae",
53+
"Apiaceae",
54+
"Liliaceae",
55+
"Polygonaceae",
56+
"Convolvulaceae",
57+
"Scrophulariaceae",
58+
"Malvaceae",
59+
],
60+
medium_list: [
61+
"Burseraceae",
62+
"Buxbaumiaceae",
63+
"Encalyptaceae",
64+
"Hymeneliaceae",
65+
"Roccellaceae",
66+
"Peltigeraceae",
67+
"Ephedraceae",
68+
"Grammitidaceae",
69+
"Santalaceae",
70+
"Pyrolaceae",
71+
"Aristolochiaceae",
72+
"Placynthiaceae",
73+
"Marantaceae",
74+
"Ochnaceae",
75+
"Thelotremataceae",
76+
"Staphyleaceae",
77+
"Calycanthaceae",
78+
"Pleuroziopsidaceae",
79+
"Zingiberaceae",
80+
"Disceliaceae",
81+
"Proteaceae",
82+
"Selaginellaceae",
83+
"Sphagnaceae",
84+
"Theophrastaceae",
85+
"Malpighiaceae",
86+
"Limnanthaceae",
87+
"Viscaceae",
88+
"Gyalectaceae",
89+
"Cladoniaceae",
90+
"Graphidaceae",
91+
"Pyrenulaceae",
92+
"Geraniaceae",
93+
"Micareaceae",
94+
"Hippuridaceae",
95+
"Dryopteridaceae",
96+
"Dicranaceae",
97+
"Commelinaceae",
98+
"Krameriaceae",
99+
"Ruppiaceae",
100+
"Fumariaceae",
101+
"Thelenellaceae",
102+
"Splachnaceae",
103+
"Thymelaeaceae",
104+
"Najadaceae",
105+
"Simaroubaceae",
106+
"Araliaceae",
107+
"Vitaceae",
108+
"Corticiaceae",
109+
"Sarraceniaceae",
110+
"Zamiaceae",
111+
"Fontinalaceae",
112+
"Trypetheliaceae",
113+
"Lobariaceae",
114+
"Polytrichaceae",
115+
"Gentianaceae",
116+
"Acarosporaceae",
117+
"Equisetaceae",
118+
"Mniaceae",
119+
"Sapindaceae",
120+
"Cornaceae",
121+
"Ditrichaceae",
122+
"Catillariaceae",
123+
"Portulacaceae",
124+
"Cabombaceae",
125+
"Bryaceae",
126+
"Loasaceae",
127+
"Cistaceae",
128+
"Hypnaceae",
129+
"Dipsacaceae",
130+
"Crassulaceae",
131+
"Arecaceae",
132+
"Lecideaceae",
133+
"Pinaceae",
134+
"Plantaginaceae",
135+
"Juglandaceae",
136+
"Flacourtiaceae",
137+
"Combretaceae",
138+
"Melastomataceae",
139+
"Uncertain",
140+
"Ascomycota",
141+
"Family",
142+
"Monoblastiaceae",
143+
"Capparaceae",
144+
"Peltulaceae",
145+
"Pontederiaceae",
146+
"Araceae",
147+
"Rhamnaceae",
148+
"Amblystegiaceae",
149+
"Celastraceae",
150+
"Anacardiaceae",
151+
"Sapotaceae",
152+
"Piperaceae",
153+
"Hydrocharitaceae",
154+
"Sematophyllaceae",
155+
"Loranthaceae",
156+
"Primulaceae",
157+
"Potamogetonaceae",
158+
"Teloschistaceae",
159+
"Cuscutaceae",
160+
"Brachytheciaceae",
161+
"Opegraphaceae",
162+
"Bignoniaceae",
163+
"Melaspileaceae",
164+
"Dennstaedtiaceae",
165+
"Verrucariaceae",
166+
"Papaveraceae",
167+
"Isoetaceae",
168+
"Saururaceae",
169+
"Onagraceae",
170+
"Polygalaceae",
171+
"Pteridaceae",
172+
"Leskeaceae",
173+
"Pertusariaceae",
174+
"Nymphaeaceae",
175+
"Apocynaceae",
176+
"Nyctaginaceae",
177+
"Valerianaceae",
178+
"Rutaceae",
179+
"Rubiaceae",
180+
"Alectoriaceae",
181+
"Juncaceae",
182+
"Moraceae",
183+
"Orchidaceae",
184+
"Acanthaceae",
185+
"Solanaceae",
186+
"Urticaceae",
187+
"Myrtaceae",
188+
"Pottiaceae",
189+
"Parmeliaceae",
190+
"Aspleniaceae",
191+
"Cucurbitaceae",
192+
"Thelypteridaceae",
193+
"Linaceae",
194+
"Lecanoraceae",
195+
"Smilacaceae",
196+
"Stereocaulaceae",
197+
"Chrysobalanaceae",
198+
"Amaranthaceae",
199+
"Violaceae",
200+
"Styracaceae",
201+
"Cupressaceae",
202+
"Hydrangeaceae",
203+
"Hippocastanaceae",
204+
"Lauraceae",
205+
"Asclepiadaceae",
206+
"Tamaricaceae",
207+
"Aizoaceae",
208+
"Calymperaceae",
209+
"Porpidiaceae",
210+
"Andreaeaceae",
211+
"Cactaceae",
212+
"Bromeliaceae",
213+
"Mycoblastaceae",
214+
"Crossosomataceae",
215+
"Rhytidiaceae",
216+
"Orthotrichaceae",
217+
"Ericaceae",
218+
"Convolvulaceae",
219+
"Campanulaceae",
220+
"Magnoliaceae",
221+
"Euphorbiaceae",
222+
"Polemoniaceae",
223+
"Iridaceae",
224+
"Zygophyllaceae",
225+
"Orobanchaceae",
226+
"Saxifragaceae",
227+
"Caryophyllaceae",
228+
"Fagaceae",
229+
"Meteoriaceae",
230+
"Lamiaceae",
231+
"Neckeraceae",
232+
"Caprifoliaceae",
233+
"Malvaceae",
234+
"Lythraceae",
235+
"Aquifoliaceae",
236+
"Ranunculaceae",
237+
"Alismataceae",
238+
"Chenopodiaceae",
239+
"Physciaceae",
240+
"Hymenophyllaceae",
241+
"Theaceae",
242+
"Liliaceae",
243+
"Salicaceae",
244+
"Fabaceae",
245+
"Apiaceae",
246+
"Gesneriaceae",
247+
"Hydrophyllaceae",
248+
"Fissidentaceae",
249+
"Rosaceae",
250+
"Brassicaceae",
251+
"Verbenaceae",
252+
"Marcgraviaceae",
253+
"Boraginaceae",
254+
"Cyperaceae",
255+
"Agavaceae",
256+
"Lycopodiaceae",
257+
"Myrsinaceae",
258+
"Loganiaceae",
259+
"Scrophulariaceae",
260+
"Asteraceae",
261+
"Sterculiaceae",
262+
"Poaceae",
263+
"Polygonaceae",
264+
"Aceraceae",
265+
],
266+
};

‎Algorithms/Sorting/InsertionSort.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import LinkedList from '../../Data-Structures/Linked-Lists/LinkedList.ts';
2+
import { plant_families } from './Data/PlantFamilies.ts';
23

34

45
function insertionSort(inputArr: number[] | string[]): Array<any> {
@@ -33,6 +34,13 @@ function insertionSort(inputArr: number[] | string[]): Array<any> {
3334
return sorted.toArray();
3435
}
3536

37+
function executionTime(method: any): string {
38+
const t0 = performance.now();
39+
method(plant_families.medium_list);
40+
const t1 = performance.now();
41+
return (t1-t0) + 'ms';
42+
}
43+
3644

3745
//---------------------------------------------------------------------
3846
// ---------- MAIN PROGRAM ----------
@@ -43,14 +51,43 @@ if (import.meta.main) {
4351
const numbers2 = [99, 44, 6, 2, 1, 5, 63, 87, 283, 4, 0];
4452
const colors = ["white", "black", "green", "blue", "orange"];
4553

54+
console.log('\n------------------ Insertion Sort ------------------');
4655
console.log(insertionSort(numbers1));
4756
console.log(insertionSort(numbers2));
4857
console.log(insertionSort(colors));
4958

59+
console.log('\n---------------- Algorithm Benchmarks ----------------');
60+
61+
const a1 = Object.create({});
62+
a1.run_1 = executionTime(insertionSort);
63+
a1.run_2 = executionTime(insertionSort);
64+
a1.run_3 = executionTime(insertionSort);
65+
66+
// const a2 = Object.create({});
67+
// a2.run_1 = executionTime(insertionSortModified);
68+
// a2.run_2 = executionTime(insertionSortModified);
69+
// a2.run_3 = executionTime(insertionSortModified);
70+
71+
console.table([a1]);
72+
5073
// RUN: deno run Algorithms/Sorting/InsertionSort.ts
5174
}
5275

5376
// --------------------------- Terminal Output: ---------------------------
77+
//
78+
// ------------------ Insertion Sort ------------------
79+
// [
80+
// 1, 2, 3, 4, 5,
81+
// 6, 7, 8, 9
82+
// ]
83+
// [
84+
// 0, 1, 2, 4, 5,
85+
// 6, 44, 63, 87, 99,
86+
// 283
87+
// ]
88+
// [ "black", "blue", "green", "orange", "white" ]
89+
//
90+
// --------- Insertion Sort w/ Traveling Node ---------
5491
// [
5592
// 1, 2, 3, 4, 5,
5693
// 6, 7, 8, 9
@@ -60,4 +97,12 @@ if (import.meta.main) {
6097
// 6, 44, 63, 87, 99,
6198
// 283
6299
// ]
63-
// [ "black", "blue", "green", "orange", "white" ]
100+
// [ "black", "blue", "green", "orange", "white" ]
101+
//
102+
// ---------------- Algorithm Benchmarks ----------------
103+
// ┌───────┬────────┬────────┬───────┐
104+
// │ (idx) │ run_1 │ run_2 │ run_3 │
105+
// ├───────┼────────┼────────┼───────┤
106+
// │ 0 │ "32ms" │ "34ms" │ "2ms" │
107+
// │ 1 │ "10ms" │ "12ms" │ "4ms" │
108+
// └───────┴────────┴────────┴───────┘

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /