0% found this document useful (0 votes)
2 views

Algorithm Assignment

The document outlines a process for inserting items into a collection and demonstrates how to sort them using bubble sort. It explains the creation of two arrays, COLOR and ORDER, from a predefined RAINBOW array and provides a bubble sort algorithm for sorting the ORDER array while simultaneously swapping corresponding COLOR elements. Additionally, it compares bubble sort with algorithmic sorting, highlighting their differences in efficiency and method of operation.

Uploaded by

arcticflamex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Algorithm Assignment

The document outlines a process for inserting items into a collection and demonstrates how to sort them using bubble sort. It explains the creation of two arrays, COLOR and ORDER, from a predefined RAINBOW array and provides a bubble sort algorithm for sorting the ORDER array while simultaneously swapping corresponding COLOR elements. Additionally, it compares bubble sort with algorithmic sorting, highlighting their differences in efficiency and method of operation.

Uploaded by

arcticflamex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1)​ Insertion -> adding a new item to a collection

2)​

1)​ RAINBOW ← ["Blue", "E", "Green", "D", "Indigo", "F", "Orange", "B", "Red", "A", "Violet",
"G", "Yellow", "C"]
2)​
3)​ COLOR ← ARRAY OF SIZE (LENGTH(RAINBOW) / 2)
4)​ ORDER ← ARRAY OF SIZE (LENGTH(RAINBOW) / 2)
5)​
6)​ FOR i ← 0 TO LENGTH(RAINBOW) - 1 STEP 2 DO
7)​ COLOR[i / 2] ← RAINBOW[i]
8)​ ORDER[i / 2] ← RAINBOW[i + 1]
9)​ Print /end

3)

1)​ FOR i ← 0 TO LENGTH(ORDER) - 2 DO


2)​ FOR j ← 0 TO LENGTH(ORDER) - 2 - i DO
3)​ IF ORDER[j] > ORDER[j + 1] THEN
4)​ // Swap ORDER
5)​ TEMP ← ORDER[j]
6)​ ORDER[j] ← ORDER[j + 1]
7)​ ORDER[j + 1] ← TEMP
8)​
9)​ // Swap COLOR
10)​ TEMP ← COLOR[j]
11)​ COLOR[j] ← COLOR[j + 1]
12)​ COLOR[j + 1] ← TEMP
13)​ print /end

4) Compare and contrast bubble sort and algorithmic sorting


​ Bubble sort uses a method of repeatedly swapping the juxtaposed/adjacent elements
that are inputted into the sort system and moves them in the other of greatest to largest in order
to put the items into the specified order asked for.
Whereas algorithmic sorting performs fewer swaps without having to swap adjacent
neighboring items.
They both sort elements and are able to provide it in smallest to greatest order, however
they differ in the amount of steps the sorting process takes in order to get the job done.

You might also like