Skip to content

Commit 3a9d193

Browse files
committed
feat:<Insertion sort> insertion sort content
1 parent 99bf989 commit 3a9d193

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
<h1 class="text-center"> Coming soon</h1>
1+
<h1 class="text-center">Insertion Sort</h1>
2+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.defination"></div>
3+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.explainImage"></div>
4+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.properties"></div>
5+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.flowChart"></div>
6+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.workingProcedure"></div>
7+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.applications"></div>
8+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.other"></div>
9+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.advantage"></div>
10+
<div class="mt-md-4 mt-3" [innerHtml]="insertionSortMetaData.disadvantage"></div>

src/app/components/Algorithms/sorting/insertion-sort/insertion-sort.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { insertionSortMetaData } from 'src/app/core/algorithms/sorting-meta-data';
23

34
@Component({
45
selector: 'app-insertion-sort',
56
templateUrl: './insertion-sort.component.html',
67
styleUrls: ['./insertion-sort.component.css']
78
})
89
export class InsertionSortComponent implements OnInit {
9-
10+
insertionSortMetaData = insertionSortMetaData;
1011
constructor() { }
1112

1213
ngOnInit(): void {

src/app/components/Algorithms/sorting/selection-sort/selection-sort.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 class="text-center">Selection Sort Algorithm</h1>
1+
<h1 class="text-center">Selection Sort</h1>
22
<div class="mt-md-4 mt-3" [innerHtml]="selectionSortMetaData.defination"></div>
33
<div class="mt-md-4 mt-3" [innerHtml]="selectionSortMetaData.explainImage"></div>
44
<div class="mt-md-4 mt-3" [innerHtml]="selectionSortMetaData.properties"></div>

src/app/core/algorithms/sorting-meta-data.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const sortingMetaData = {
5050
example: Helper.setExampleImage("Complexity and Stability of Sorting Algorithms", sortData.example),
5151
}
5252

53-
// ------------------------------------------ Selection Sort Meta Data ------------------------------------------//
53+
// ------------------------------- Selection Sort Meta Data ----------------------------------------------//
5454

5555
const selectionSortData = {
5656
defination: `Selection sort is a simple sorting algorithm. This sorting algorithm is an in-place comparison-based
@@ -97,4 +97,67 @@ export const selectionSortMetaData: Algorithms = {
9797
disadvantage: Helper.setListwithTitleHtml('Selection Sort Disadvantages',selectionSortData.disadvantages),
9898
applications: Helper.setListwithTitleHtml('Selection Sort Applications',selectionSortData.applications),
9999
workingProcedure: Helper.setListwithTitleHtml('Follow the below steps to solve the problem',selectionSortData.workingProcedure),
100-
}
100+
}
101+
102+
// ------------------------------------- End ----------------------------------------------------------------//
103+
104+
// --------------------------------- Insertion Sort ---------------------------------------------------------//
105+
106+
const insertionSortData = {
107+
defination: `Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards
108+
in your hands. The array is virtually split into a sorted and an unsorted part. Values from the unsorted part
109+
are picked and placed at the correct position in the sorted part`,
110+
flowChart:"assets/ds-image/DSA1.jpg",
111+
explainImage:"assets/ds-image/DSA1.jpg",
112+
workingProcedure:[
113+
'Iterate from arr[1] to arr[N] over the array',
114+
'Compare the current element (key) to its predecessor',
115+
`If the key element is smaller than its predecessor, compare it to the elements before.
116+
Move the greater elements one position up to make space for the swapped element`
117+
],
118+
properties:[
119+
'This algorithm is one of the simplest algorithm with simple implementation',
120+
'Basically, Insertion sort is efficient for small data values',
121+
'Insertion sort is adaptive in nature, i.e. it is appropriate for data sets which are already partially sorted',
122+
'Insertion sort is an in-place algorithm, meaning it requires no extra space',
123+
'Maintains relative order of the input data in case of two equal values (stable)',
124+
`the bubble sort performs poorly compared to the insertion sort. Due to the high number of swaps,
125+
it's expected to generate twice as many write operations and twice as many cache misses`,
126+
`Insertion sort's advantage is that it only scans as many elements as it needs in order to place the k+1st element,
127+
while selection sort must scan all remaining elements to find the k+1st element. Experiments show that insertion
128+
sort usually performs about half as many comparisons as selection sort`
129+
],
130+
applications:[
131+
`One more real-world example of insertion sort is how tailors arrange shirts in a cupboard, they always keep them in sorted
132+
order of size and thus insert new shirts at the right position very quickly by moving other shirts forward to keep the right
133+
place for a new shirt`
134+
],
135+
advantages: [
136+
`The main advantage of the insertion sort is its simplicity. It also exhibits a good performance when dealing with a small list.
137+
The insertion sort is an in-place sorting algorithm so the space requirement is minimal`
138+
],
139+
disadvantages: [
140+
`The disadvantage of the insertion sort is that it does not perform as well as other, better sorting algorithms.
141+
With n-squared steps required for every n element to be sorted, the insertion sort does not deal well with a huge list.
142+
Therefore, the insertion sort is particularly useful only when sorting a list of few items`
143+
],
144+
performance:[
145+
'Worst-case performance of insertion sort is O(n²) comparisons and swaps',
146+
'Best-case performance is O(n) comparisons and O(1) swaps',
147+
'Average-case performance is O(n²) comparisons and swaps'
148+
]
149+
}
150+
151+
export const insertionSortMetaData: Algorithms = {
152+
defination: Helper.setHeader(insertionSortData.defination),
153+
properties: Helper.setListwithTitleHtml('Insertion Sort Properties', insertionSortData.properties),
154+
explainImage: Helper.setExampleImage('Insertion Sort Explain Image', insertionSortData.explainImage),
155+
flowChart: Helper.setExampleImage('Insertion Sort Flowchart',insertionSortData.flowChart),
156+
advantage: Helper.setListwithTitleHtml('Insertion Sort Advantages',insertionSortData.advantages),
157+
disadvantage: Helper.setListwithTitleHtml('Insertion Sort Disadvantages',insertionSortData.disadvantages),
158+
applications: Helper.setListwithTitleHtml('Insertion Sort Applications',insertionSortData.applications),
159+
other: Helper.setListwithTitleHtml('Insertion Sort Performance',insertionSortData.performance),
160+
workingProcedure: Helper.setListwithTitleHtml('Follow the below steps to solve the problem',insertionSortData.workingProcedure),
161+
}
162+
163+
// ------------------------------------- End ----------------------------------------------------------------//

0 commit comments

Comments
 (0)