-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselection.html
129 lines (105 loc) · 4.37 KB
/
selection.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!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.0">
<title>Sorting Visualizer</title>
<link rel="stylesheet" href="selectionSort.css">
</head>
<header class="header">
<h1 class ="center">Selection Sort Visualizer</h1>
</header>
<body>
<div id="array-cont">
<div id="bars" class="flex-container"></div>
</div>
<div class="row">
<div id="newArray">
<button type="button" id="clickme" class="btn btn-outline-success btn-dark newArray">New Array</button>
</div>
<div class="col" id="input">
<span id="size">Size
<input id="arr_sz" type="range" min="5" max="100" step=1 value=60>
</span>
<span id="speed">Speed
<input id="speed_input" type="range" min="20" max="300" stepDown=10 value=60>
</span>
</div>
<div class="button-2">
<button type="button" id="clickme"class="btn btn-outline-primary btn-dark selectionSort">Selection Sort</button>
</div>
</div>
</div>
<div id="selectionSortExplain">
<h1>How Selection Sort Works?</h1>
<p> Consider the following depicted array as an example. <br>
<!-- -->
For the first position in the sorted list, the whole list is scanned sequentially. <br>
The first position where 14 is stored presently, we search the whole list and find that 10 is the lowest value.</p>
<!-- -->
<p>
So we replace 14 with 10. After one iteration 10, which happens to be the minimum value in the list, appears in the first position of the sorted list.</p>
<!-- -->
<p>
For the second position, where 33 is residing, we start scanning the rest of the list in a linear manner.</p>
<!-- -->
<p>
We find that 14 is the second lowest value in the list and it should appear at the second place. We swap these values.</p>
<p>
After two iterations, two least values are positioned at the beginning in a sorted manner. <br>
<!-- -->
The same process is applied to the rest of the items in the array. <br>
Following is a pictorial depiction of the entire sorting process − </p>
<!-- -->
<div id="img-div">
<img src="selectionSortimg.jpg" alt="">
</div>
<p> Now, let us learn some programming aspects of selection sort.</p>
<h1> Algorithm :</h1>
<p>
Step 1 − Set MIN to location 0 <br>
Step 2 − Search the minimum element in the list <br>
Step 3 − Swap with value at location MIN <br>
Step 4 − Increment MIN to point to next element <br>
Step 5 − Repeat until list is sorted <br>
</p>
<h1>Pseudocode :</h1>
<p>
procedure selection sort <br>
list : array of items <br>
n : size of list <br>
<br>
for i = 1 to n - 1
/* set current element as minimum*/ <br>
min = i <br>
<br>
/* check the element to be minimum */ <br>
for j = i+1 to n <br>
if list[j] < list[min] then <br>
min = j; <br>
end if <br>
end for <br>
/* swap the minimum element with the current element*/ <br>
if indexMin != i then <br>
swap list[min] and list[i] <br>
end if <br>
end for <br>
end procedure <br>
</p> <br>
</div>
<div id="img-div">
<button type="button" id="clickme1">
<a href="homepage.html">Home page</a>
</button>
</div>
<div class="header">
<h1 class ="center">Thank you</h1>
</div>
<div id="lastdiv">
<p>@Shashwat shukla</p>
</div>
<script src="sorting.js"></script>
<script src="selectionSort.js"></script>
</body>
</html>