Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Informatics College

Information Systems
CC4002NA
Coursework 1

Submitted By: Submitted To:


Saugat Timilsina Mr.
NP04CP4A170057 Module Leader
Group: L1C1 Information Systems
Date: 2017/12/29
Table of Contents
Information Systems .................................................................................................... 1

CC4002NA ..................................................................................................................... 1

Coursework 1 ................................................................................................................ 1

1. The Bubble sort algorithm ......................................................................................... 1


1.1 Algorithm for Bubble sort ........................................................................................... 2
2. Graphic representation of the algorithm ................................................................... 3

3. Data Structures ......................................................................................................... 4


3.1 Best data type for the given data. ............................................................................... 4
4. Conclusion ............................................................................................................ 5
Bibliography ..................................................................................................................... 6
Table of Figure

Figure 1: Flowchart..................................................................................................... 3

Table of Tables

Table 1: First Pass in Bubble sort algorithm……………………………………………...1


Table 2: Second Pass in Bubble sort algorithm………………………………………….1
Table 3: Third Pass in Bubble sort algorithm……………………………………………..1
Table 4: Fourth Pass in Bubble sort algorithm…………………………………………...1
CC4002NA Information System

1. The Bubble sort algorithm

Bubble sort algorithm is a sorting technique in which we sort the given elements
in ascending or descending order by comparing two elements at a time and
placing them in correct position. (dyclassroom.com, 2017)
Example:

First Pass
(6 1 9 3 5) (1 6 9 3 5) Algorithm swaps values because 6>1
(1 6 9 3 5) (1 6 9 3 5) Algorithm doesn’t swap values because 6<9
(1 6 9 3 5) (1 6 3 9 5) Algorithm swaps values because 9>3
(1 6 3 9 5) (1 6 3 5 9) Algorithm swaps values because 9>5
Table 1: First Pass in Bubble sort algorithm

Second Pass
(1 6 3 9 5) (1 6 3 9 5) Algorithm doesn’t swap values because 1<6
(1 6 3 9 5) (1 3 6 9 5) Algorithm swaps values because 3<6
(1 3 6 9 5) (1 3 6 9 5) Algorithm doesn’t swap values because 6<9
(1 3 6 9 5) (1 3 6 5 9) Algorithm swaps values because 9>5
Table 2: Second Pass in Bubble sort algorithm

Third Pass
(1 3 6 5 9) (1 3 6 5 9) Algorithm doesn’t swap values because 1<3
(1 3 6 5 9) (1 3 6 5 9) Algorithm doesn’t swap values because 3<6
(1 3 6 5 9) (1 3 5 6 9) Algorithm swaps values because 6 > 5
(1 3 5 6 9) (1 3 5 6 9) Algorithm doesn’t swap values because 6<9
Table 3: Third Pass in Bubble sort algorithm

Fourth Pass
(1 3 5 6 9) (1 3 5 6 9) Doesn’t Swap
(1 3 5 6 9) (1 3 5 6 9) Doesn’t Swap
(1 3 5 6 9) (1 3 5 6 9) Doesn’t Swap
(1 3 5 6 9) (1 3 5 6 9) Doesn’t Swap
Table 4: Fourth Pass in Bubble sort algorithm

Since in the fourth pass no values were swapped, all of the values are in ascending
order. This is how values are sorted by Bubble sort algorithm.

Saugat Timilsina 1
CC4002NA Information System

1.1 Algorithm for Bubble sort


Step 1: Start
Step 2: Input list
Step 3: initialize sorted = false, i=1
Step 4: if sorted == false, goto step 5 else goto Step 12
Step 5: swap = 0
Step 6: if i<=list.count-1, goto step 7 else goto Step 9
Step 7: if list[i-1]>list[i], goto step 8 else goto Step 9
Step 8: temp = list[i-1], list[i-1] = list[i], list[i] = temp, swap = swap+1
Step 9: i = i+1, goto Step6
Step 10: if swap == 0, goto step 11 else goto step 4
Step 11: initialize sorted = True and goto Step 4
Step 12: Display list
Step 13: End

Saugat Timilsina 2
CC4002NA Information System

2. Graphic representation of the algorithm

Figure 1: Flowchart of Bubble sort algorithm

Saugat Timilsina 3
CC4002NA Information System

3. Data Structures
There are four collection data types available in python. Although all of them
are collection data types, they are used for storing different types of data for
different purposes. They are:
a. List: A list is a collection data type that can contain elements of
different data types or can be empty too. For Example:
myList = {4, 5, 6, 7}
b. Tuple: Tuple is alike list but it is immutable, so we cannot replace or
delete any of their items. For Example:
tupleEx = {s, a, u, g, a, t}
c. Dictionaries: Dictionary is unordered collection of key-value that have
pair with unique keys and are mutable. For Example:
details = {‘name’ = saugat, ‘district’ = tanahun, ‘level’ = 12}
d. Set: Set is an unordered collection of elements. They are mutable but
unordered. For Example:
setEx = {‘t’, ‘i’, ‘m’, ‘i’ ,’l’, ‘s’, ‘i’, ‘n’, ‘a’}
(lecturer, 2017)

3.1 Best data type for the given data.


Both dictionary and list data type are ideal for storing the given data in Python
but in my thought best data type that could be used for storing and representing the
given data would be list data type. List data type is most suitable for storing the given
values because the data we use might have to be modified later on and data stored
on List data type can be modified and could be assigned empty values in list data
type easily. Dictionary data type also gives us the same functionality but the syntax
for set data type might seem a bit confusing and misleading for someone new.

Saugat Timilsina 4
CC4002NA Information System

4. Conclusion

I was curious about how websites, software worked and what the development
cycle is like since my high school days. So, I searched about it on the web and got
to know about website development. After that I started learning about HTML, CSS
and JS through online tutorials. I became familiar about how softwares and
computers worked through the online courses. After I saw various python projects,
I was fascinated by various Python projects. Then, I looked up about what was the
most we could get out of programming with Python. After that, I began watching
tutorials online for Python 2 and understood the concepts like variables, data types
and OOP concept. Thus, I would say my curiosity got me started and it has been
helpful when our module started.
Since, I had already been watching online tutorials and getting help from
huge online community, it was a bit exaggerating at first and I expected that it would
be hard for me to grasp all concepts at college due to the vastness of the possibility
of things we could do and make with the help of Python. I had not gone deep in the
basics of python but had made key loggers and automated email sender with the
help of Python community and various libraries. Since, I thought it would be vast
and I might not be able to grasp all the concepts, it is going smooth till now.
It has been
exciting grabbing the new concepts and vast possibility ahead and I am willing to
learn more to be able to contribute something for both the Python and social
community. I would say the journey of programming with Python until now has
been amazing and am able to manage, cope up with it. The only thing that bugs
me in programming is our module is mostly based on hard code and not on things
that our current world is shifting towards. This might be because I have seen
fascinating stuffs like python controlled smart mirror and IOT being made in vlogs
but I hope some exciting things like those should also be included in our course as
extra credit stuffs.

Saugat Timilsina 5
CC4002NA Information System

Bibliography
1) dyclassroom.com. (2017, 12 26). Bubble Sort Algorithm. Retrieved from
dyclassroom.com: dyclassroom.com/sorting-algorithm/bubble-sort
2) Unknown. (2017, 12 28). Collection data types. Lecture Slide. Lecturer .

Saugat Timilsina 6

You might also like