-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubbleSort.html
181 lines (158 loc) · 8.35 KB
/
bubbleSort.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="Oliver Holland">
<title>RLO: Data Structures & Algorithms: Bubble Sort</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Style Sheet - CSS -->
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<a id="doc_top"></a>
<div class="container" id="main_container">
<!-- Top Nav-Bar -->
<header class="clearfix" role="banner">
<img src="img/essex.png" alt="University of Essex" width="144" height="59" id="university_logo"
class="pull-right">
<p class="rlo_title">Data Structures & Algorithms</p>
</header>
<nav class="nav nav-pills hidden-xs" role="navigation" id="main_nav">
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle btn-sm" data-toggle="dropdown">
Contents <span class="glyphicon glyphicon-chevron-down"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="index.html">Introduction</a></li>
<li><a href="overview.html">Data Structures & Algorithms Overview</a></li>
<li><a href="sortingAlgorithms.html">Sorting Algorithms</a></li>
<li><a href="activity.html">Activity</a></li>
<li class="active"><a href="bubbleSort.html">Bubble Sort</a></li>
<li><a href="insertionSort.html">Insertion Sort</a></li>
<li><a href="quickSort.html">Quick Sort</a></li>
<li><a href="algorithmsInAction.html">Algorithms in Action</a></li>
<li><a href="assessment.html">Assessment</a></li>
</ul>
</div>
<a href="activity.html" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-circle-arrow-left"></span>
Previous </a>
<a href="insertionSort.html" id="next_btn" class="btn btn-primary btn-sm">Next <span
class="glyphicon glyphicon-circle-arrow-right"></span></a>
</nav>
<!-- Renders drop-down menu for smaller screen resolutions -->
<div class="visible-xs-block" id="small_screen_menu_container">
<p class="rlo_title">Data Structures & Algorithms</p>
<p><a class="btn btn-primary btn-block" data-toggle="collapse" href="#collapseExample" aria-expanded="false"
aria-controls="collapseExample" id="toggle_ss_nav">
Toggle Navigation <span class="glyphicon glyphicon-remove glyphicon-menu-hamburger"
aria-hidden="true"></span></a></p>
<div class="collapse" id="collapseExample">
<ul class="btn-group btn-group-vertical center-block" role="menu" id="small_screen_menu">
<li><a href="index.html" class="btn btn-info btn-block">Introduction</a></li>
<li><a href="overview.html" class="btn btn-info btn-block">Data Structures & Algorithms Overview</a></li>
<li><a href="sortingAlgorithms.html" class="btn btn-info btn-block">Sorting Algorithms</a></li>
<li><a href="activity.html" class="btn btn-info btn-block">Activity</a></li>
<li><a href="bubbleSort.html" class="btn btn-info btn-block active">Bubble Sort</a></li>
<li><a href="insertionSort.html" class="btn btn-info btn-block">Insertion Sort</a></li>
<li><a href="quickSort.html" class="btn btn-info btn-block">Quick Sort</a></li>
<li><a href="algorithmsInAction.html" class="btn btn-info btn-block">Algorithms in Action</a></li>
<li><a href="assessment.html" class="btn btn-info btn-block">Assessment</a></li>
</ul>
</div>
</div>
<!-- Main Content Area -->
<main role="main">
<article>
<a id="content_start"></a>
<h1>Bubble Sort</h1>
<div class="row">
<div class="col-md-6" id="text-component">
<p>Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based algorithm
in which each pair of adjacent elements is compared and the elements are swapped if they are
not in order. In essence, each item “bubbles” up to the location where it belongs.
This algorithm is not suitable for large data sets as its average and worst case
complexity are of Ο(<i>n</i><sup>2</sup>) where <i>n</i> is the number of items</p>
<p>The only significant advantage that bubble sort has over most other implementations, even quicksort,
but not insertion sort, is that the ability to detect that the list is sorted efficiently is
built into the algorithm. When the list is already sorted (best-case), the complexity of
bubble sort is only O(<i>n</i>).</p>
</div>
<!-- START code column -->
<div class="col-md-6" id="code-component">
<pre><p>private static void bubbleSort(int[] l) {
int l = l.length;
int temp = 0;
for(int i=0; i < n; i++) {
for (int j = 1; j < (n - i); j++) {
if (l[j - 1] > l[j]) {
<i>//swap the elements!</i>
temp = l[j - 1];
l[j - 1] = l[j];
l[j] = temp;
}
}
}
}
</p></pre>
</div>
<!-- END code column -->
</div>
<nav class="section_nav" role="navigation">
<ul class="clearfix ">
<li class="pull-left "><a href="activity.html" class="btn btn-primary"><span
class="glyphicon glyphicon-circle-arrow-left"></span> Previous </a></li>
<li class="pull-right"><a href="insertionSort.html" class="btn btn-primary">Next <span
class="glyphicon glyphicon-circle-arrow-right"></span></a></li>
</ul>
</nav>
</article>
</main>
<!-- START doc top navigation -->
<div class="visible-xs-block" id="doc_top_btn"><a href="#doc_top" class="btn btn-info btn-block">Document Top
<span
class="glyphicon glyphicon-circle-arrow-up"></span></a></div>
<!-- END doc top navigation -->
<!-- Footer -->
<footer role="contentinfo">
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="55.5" aria-valuemin="0"
aria-valuemax="100" style="width: 55.5%">
<span class="sr">55% Complete</span>
</div>
</div>
<div class="row">
<div class="col-md-6">
<ul>
<li><b>Subject Matter:</b> Data Structure's & Algorithms</li>
<li><b>Sub-topic:</b> Sorting Algorithms</li>
<li><b>Content Author:</b> Dr Michael Sanderson</li>
<li><b>Developer:</b> Oliver Holland</li>
<li><b>Email:</b> <a href="mailto:[email protected]">[email protected]</a></li>
</ul>
</div>
<div class="col-md-6 text-right">
<p><b>Page last updated:</b> 19th March 2017</p>
</div>
</div>
</footer>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="js/bootstrap.min.js"></script>
<!-- JavaScript for Text Support Toolbar -->
<script src="js/textTools.js"></script>
</body>
</html>