website_test/src/blog/educational/CE4703/bubblesort.html
Eoghan Conlon 99e1b00a8e
All checks were successful
On_Push / deploy (push) Successful in 12s
Feat. Adding my own website to this repo
2024-09-26 09:18:51 +01:00

71 lines
3.1 KiB
HTML

<!DOCTYPE html>
<html lang="en-ie">
<head>
<title>CE4703 2019 exam paper Q4</title>
<link rel="stylesheet" href="../../Blogs.css" />
<meta charset="UTF-8" />
</head>
<body>
<h1 id="q4-bubblesort">2019 Q4 (Bubblesort)</h1>
<p>As before these may not get 100% due to them being answers that I would give in the exam should it come up.</p>
<h2 id="a-explain-in-plain-english-the-bubblesort-algorithm">a) Explain in plain English the Bubblesort algorithm</h2>
<p>In Bubblesort you select two elements that are beside eachother and compare them, if the one that is further to the right
is smaller than the one further to the left, we swap them round and then repeat till you reach the end of the list. You
then repeat until you are able to move through the list without swapping any numbers around.</p>
<h2 id="b-provide-a-pseudo-code-representation-of-the-bubblesort-algorithm">b) Provide a pseudo-code representation of the Bubblesort algorithm</h2>
<p>As before this is closer to C then english but that is the way that I work through things for the most part.</p>
<pre><code>bubbleSort(int set[], int size){
int temp;
int check = 1;
while(check){
check = 0;
for(int i = 0, j = 1; j &lt; size; i++, j++){
if(set[i] &gt; set[j]){
check = 1;
temp = set[i];
set[i] = set[j];
set[j] = temp;
}
}
}
}
</code></pre>
<h2 id="c-provide-an-implementation-of-your-bubblesort-algorithm-in-the-c-programming-language">c) Provide an implementation of your Bubblesort algorithm in the C programming language</h2>
<pre><code class="language-C">void bubblesort(int set[], int size){
int temp;
int check = 1;
while(check){
check = 0;
for(int i = 0, j = 1; j &lt; size; i++, j++){
if(set[i] &gt; set[j]){
check = 1;
temp = set[i];
set[i] = set[j];
set[j] = temp;
}
}
}
}
</code></pre>
<h2 id="d-compare-the-efficiency-of-bubblesort-and-merge-sort-for-a-random-array-a-sorted-array-with-a-single-appended-element">d) Compare the efficiency of Bubblesort and merge sort for a random array &amp; a sorted array with a single appended element</h2>
<p>Bubblesort, in the best case scenario where you only have to wap one or two numbers it can be more efficient but it can be
the least efficient if you need to move an awful lot of numbers. To bring this back to the question, Bubblesort can be more
efficient with the sorted array with one appended element in a best case scenario but otherwise Mergesort is more efficient.</p>
<footer>
<p>
2022-<span id="year">2022</span> | Eoghan Conlon | Email:
<a href = "mailto:hello@eoghanconlon.ie">hello@eoghanconlon.ie
</a>
| Discord: eoghanconlon74#1132 | Gitlab:
<a href = "https://gitlab.com/eoghanconlon73">
@eoghanconlon73
</a>
</p>
</footer>
<script>
/* I am a lazy fucker */
document.getElementById('year').textContent = new Date().getFullYear().toString()
</script>
</body>
</html>