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

Module Code & Module Title

CC4002NA Information Systems

Assessment Weightage & Type


20% Individual Coursework

Year and Semester


2018-19 Autumn

Student Name: Saphal Shrestha


London Met ID:
College ID:NP01NT4A180135
Assignment Due Date:2018/12/21
Assignment Submission Date:2018/12/21

I confirm that I understand my coursework needs to be submitted online via Google Classroom under the
relevant module page before the deadline in order for my assignment to be accepted and marked. I am
fully aware that late submissions will be treated as non-submission and a marks of zero will be awarded.
Table of Contents
The bubble sort algorithm................................................................................................ 1
1. Bubble sort ......................................................................................................... 1
2. Working of bubble sort ....................................................................................... 2
3. Algorithm of bubble sorting ................................................................................ 4
Graphic representation of algorithm ................................................................................ 5
1. Flow chart........................................................................................................... 5
Data structures ................................................................................................................ 6
1. Lists .................................................................................................................... 6
2. Tuples ................................................................................................................ 8
3. Dictionary ........................................................................................................... 9
4. Set.................................................................................................................... 11
Learning reflection ......................................................................................................... 13
Bibliography .................................................................................................................. 14
List of Figures
Figure 1: Bubble sort (w3resource, 2018) ....................................................................... 1
Figure 2: Flow chart of bubble sorting ............................................................................. 5

List of table
Table 1: Books data……………………………………………………………………….......12
CC4002NA INFORMATION SYSTEMS

The bubble sort algorithm


1. Bubble sort
Bubble sort is the simple algorithm to arrange the list of data in order by simply
swapping the variables if they are not arranged. The process continues until the list is
properly sorted.
If the unarranged list of variables is given to us. It compares the pair of variables
sidewise. If it is arranged properly, it leaves the variables as it is but if variables are not
in order it swaps the variables and makes it sorted. The process of comparing the
variables continues and completes the pass. After the succession of one pass it goes
again to compare as another pass. The process continues until the pass in which no
swapping takes place. By this the list of unarranged list of variables are arranged.
(S.Adamchik, 2018)

Figure 1: Bubble sort (Anon., 2018)

SAPHAL SHRESTHA Page 1


CC4002NA INFORMATION SYSTEMS

2. Working of bubble sort

(4, 5, 1, 3, 2)
First pass:
(4, 5, 1, 3, 2) - (4, 5, 1, 3, 2) Compares the 1st and 2nd numbers which are 4 and 5.
They are in order so leave them as it is.
(4, 5, 1, 3, 2) - (4, 1, 5, 3, 2) Compares the 2nd and 3rd numbers which are 5 and 1.
Since 5>1 swap them.
(4, 1, 5, 3, 2) – (4, 1, 3, 5, 2) Compares the 3rd and 4th numbers which are 3 and 5.
Since 5>3 swap them.
(4, 1, 3, 5, 2) – (4, 1, 3, 2, 5) Compares the 4th and 5th numbers which are 2 and 5.
Since 5>2 swap them.
The algorithm runs again and checks if it is arranged. It arranges until the list is sorted.
Second pass:
(4, 1, 3, 2, 5) - (1, 4, 3, 2, 5) Compares the 1st and 2nd numbers which are 4 and 1.
Since 4>1. Swap them.
(1, 4, 3, 2, 5) - (1, 3, 4, 2, 5) Compares the 2nd and 3rd numbers which are 4 and 3.
Since 4>3. Swap them.
(1, 3, 4, 2, 5) - (1, 3, 2, 4, 5) Compares the 3rd and 4th numbers which are 4 and 3.
Since 4>2. Swap them.
(1, 3, 2, 4, 5) - (1, 3, 2, 4, 5) Compares the 4th and 5th numbers which are 4 and 5.
They are in order so leaves them as it is.
The algorithm runs again and checks if it is arranged. It arranges until the list is sorted.
Third pass:
(1, 3, 2, 4, 5) - (1, 3, 2, 4, 5) In order so doesn’t swap.
(1, 3, 2, 4, 5) - (1, 2, 3, 4, 5) Compares the 2nd and 3rd numbers which are 3 and 2.
Since 3>2. Swap them.
(1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) In order so doesn’t swap.
(1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) In order so doesn’t swap.
Since we know all the numbers are sorted but the algorithm is designed to run a whole
loop without any swapping. So it goes under a fourth pass.

SAPHAL SHRESTHA Page 2


CC4002NA INFORMATION SYSTEMS

Fourth pass:
(1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) In order so doesn’t swap.
(1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) In order so doesn’t swap.
(1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) In order so doesn’t swap.
(1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) In order so doesn’t swap.
Now the algorithm runs without swapping any number so the list is sorted.

SAPHAL SHRESTHA Page 3


CC4002NA INFORMATION SYSTEMS

3. Algorithm of bubble sorting

Step 1: Start
Step 2: Enter a list.
Step 3: Make sorted=False and i=0.
Step 4: If i<len(list), go to step 6. Else to step 5.
Step 5: Else if sorted= True, go to step 3. Else to step 10.
Step 6: If list[i]>list[i+1], go to step 7.
Step 7: increase i by 1 ie. i=i+1. And go to step 4.
Step 8: temp=list[i]
list[i]=list[i+1]
list[i+1]=temp
Go to step 9.
Step 9: Increase i by 1, make sorted= True and go to step 4.
Step 10: Print list.
Step 11: End

SAPHAL SHRESTHA Page 4


CC4002NA INFORMATION SYSTEMS

Graphic representation of algorithm


1. Flow chart

Figure 2: Flow chart of bubble sorting

SAPHAL SHRESTHA Page 5


CC4002NA INFORMATION SYSTEMS

Data structures
1. Lists
List is the ordered sequence of data structure in python that is mutable. List can be
indexed. List is mutable so they can be changed and modified. List is denoted by big
brackets [ ]. (Anon., 2018)
Example
list= [10, 20, 30, 40, 50]
print(list)
Output: [10, 20, 30, 40, 50]
a. Indexing
Indexing is the process of assigning the number for every item in a list.
In a list [10, 20, 30, 40, 50]
10 is at list[0] place or at list[-5].
20 is at list[1] place or at list[-4].
30 is at list[2] place or at list[-3].
40 is at list[3] place or at list[-2].
50 is at list[4] place or at list[-1].
The index value increases form left to right and decreases from right to left.
Example
list=[10, 20, 30, 40, 50]
print (list [2])
Output= 30
b. sChanging item
If the list is: list[10, 20, 30, 40, 50]
Now if I want to change the value of 3rd item of the list to 60 then,

list[10, 20, 30, 40, 50]

SAPHAL SHRESTHA Page 6


CC4002NA INFORMATION SYSTEMS

list[2]=60
print (list)
This will modify the list and change the list to: [10, 20, 60, 40, 50]
c. Loop in a list
To print all the items in a list one by one then we can use a loop.
Example:
List=[10, 20, 30, 40, 50]
For I in list:
print(i)
Output:
10
20
30
40
50
d. Length of a list
There is a simple method to find the number of items in a list by using the len method.
Example:
List=[10, 20, 30, 40, 50]
print(len(list))
Output: 5
e. Deleting the item from the list
To delete items from the list, there are several ways to do that.
Example:
List=[10, 20, 30, 40, 50]
1. To remove single item.
List=[10, 20, 30, 40, 50]
remove.List(20)

SAPHAL SHRESTHA Page 7


CC4002NA INFORMATION SYSTEMS

print(List)
Output: [10, 30, 40, 50]
2. To remove item using index.
List=[10, 20, 30, 40, 50]
del List[3]
print(List)
Output: [10, 20, 30, 50]
3. To remove or empty whole list del or clear can be used.
List=[10, 20, 30, 40, 50]
List.clear()
print(list)

2. Tuples
Tuple is one of the collection data type which is similar to the list but immutable. The
indexing is also present here. Tuples are immutable so the values cannot be changed.
Tuples are denoted as:
T=[1, 2, 3]
Tuples are useful if the data is not changed. It is very useful for constants.
a. Indexing
Indexing is the process of assigning number to each item.
The first item has 0 index, second has 1 and so on.
Example:
T=[1, 2, 3]
print(T[0])
Output: 1

b. Loop in a tuple
To print all the item one by one, loop can be used.
Example:
T=[1, 2, 3]
For i in T:
print(i)

SAPHAL SHRESTHA Page 8


CC4002NA INFORMATION SYSTEMS

Output:
1
2
3
c. Length of a tuple
To find the length of the tuple, the len method is used.
Example:
T=[1, 2, 3]
print(len(T))
Output: 3

3. Dictionary
Dictionary is the unordered collection data type in which data are stored in key – value
pair. Dictionary is mutable which means the values can be changed and modified. Key
and value are necessary in dictionary. The key must be unique. Dictionary is kept inside
curly brackets.
Example:
Dict1 = {‘name’:’saphal’,’rollno.’:20,’class’:10}
{‘key’:’value’,’key’:’value’,’key’:’value’}
To print a value.
print(dict1[‘name’])
Output: Saphal
To change the value,
Dict1 = {‘name’:’saphal’,’rollno.’:20,’class’:10}
Dict1[“class”]=12
Output: {‘name’:’saphal’,’rollno.’:20,’class’:12}
To only print key or value,
For key in Dict1.keys
print(key)

SAPHAL SHRESTHA Page 9


CC4002NA INFORMATION SYSTEMS

Output: name
Rollno
class
for value in Dict1.values
print(value)
Output: saphal
20
10
To print both key and value
print(key,value):
Output: name saphal
Roll no 20
Class 10
a. Length of a dictionary
To find the length of a dictionary, len method can be used.
Example:
Dict1 = {‘name’:’saphal’,’rollno.’:20,’class’:10}
print(len(Dict1))
Output: 3
b. Adding items in dictionary
To add items in dictionary, index key is used and its value is given.
Example:
Dict1 = {‘name’:’saphal’,’rollno.’:20,’class’:10}
Dict1[‘section’]=’A’
print(Dict1)
Output: Dict1 = {‘name’:’saphal’,’rollno.’:20,’class’:10,’section’=’A’}
c. Deleting items from dictionary

SAPHAL SHRESTHA Page 10


CC4002NA INFORMATION SYSTEMS

To delete items from a dictionary, there are several ways.


1. Using pop method
Dict1 = {‘name’:’saphal’,’rollno.’:20,’class’:10}
Dict1.pop(‘name’)
print(Dict1)
Output: {’rollno.’:20,’class’:10}
2. Using del method
Dict1 = {‘name’:’saphal’,’rollno.’:20,’class’:10}
Dict1.del(‘rollno’)
print(Dict1)
Output: {‘name’:’saphal’,’class’:10}
3. Using clear method. This method empties the dictionary.
Dict1 = {‘name’:’saphal’,’rollno.’:20,’class’:10}
Dict1.clear()
print(Dict1)
Output: {}

4. Set
Set is an unordered collection of data. Set is mutable so we can easily add and remove
items. Here is no concept of indexing. It always contains unique items and is denoted by
curly brackets.
Example:
A={1, 2, 3, a, b}
B={a, b, c, 1, 2}
We can do following things in set:
print(A.union (B))
Output: {1, 2, 3, a, b, c}
print(A.intersection(B))
Output:{a, b, 1, 2}
print(A.difference(B))
Output:{1, 2, 3}
print(B.difference(A))

SAPHAL SHRESTHA Page 11


CC4002NA INFORMATION SYSTEMS

Output:{a, b, c}
Print(A.symmetric_difference(B))
Output:{3, c}
All the elements in a set must be unique. It means the same numbers are not repeated.
If the set is: set= {1, 1, 2, 2, 2, 3, 4, 5, 5, 5}
Print(set)
Output: {1, 2, 3, 4, 5}

Book ID Name Price Quantity

B001 Harry Potter (JK Rowling) $2 30


B002 Start With Why(Simon Sinek) $1.5 10
B003 Programming With Python(John Smith) $1.5 20
Table 2: Books data

The above table provides us information about Book ID , its name, price and quantity. It
seems it is appropriate to use dictionary data type to store these data. Since keeping
records isn’t easy, new data should be added and old ones should be removed now and
then. So, in that case dictionary is mutable which helps to change and modify its data
easily and also helps to easily remove any items from the data. This helps to handle the
data easily in less amount of time with more efficiency. Hence, I choose dictionary data
type in terms of convenience, economy and efficiency.

SAPHAL SHRESTHA Page 12


CC4002NA INFORMATION SYSTEMS

Learning reflection
Before joining to Islington College, I had no idea about programming languages.
Python, java, C+, C++ were just some programming languages. I have never taken
programing classes. Last time I have learned programming is Q-BASIC when I was in
grade 10. In which too I had no clear idea about programming. I had never done any
computer courses in any institutions. But I was very eager to learn programming so I
had tried learning online through www.codeacaday.com. Learning through it was not so
effective. It was like wasting my time in vain. Even in my high school days I took
“Biology” stream and couldn’t get change to study computer.
After the completion of high school, I choose Islington College to learn something new
about computer, the mechanism how they work, the inter connection of computers, the
new programming languages and any more about computer stuffs. Before the starting
of module I had thought programming language was very difficult and I had to work very
hard to catch up the course. After I heard all the courses are designed by international
standard, I was in a fear that I couldn’t understand properly or get the full idea about all
the courses. I had no single idea about the module and the way I am going to
understand it. But I was determined and I was all ready to work hard and leave no stone
unturned.
Now, when I look back, I am able to catch up with the module. I feel quite easy to
understand the topic.
I am very much satisfied with myself, the way I’m learning slowly. I am leaving no stone
unturned in study and practice. The lectures, tutorials and lab classes help a lot in study
and understanding. The lecture helps to get the surface knowledge about the topic.
Tutorials help to get a proper understanding about the topic. And the lab classes help to
practice those in detail. Combining all at the end of the week the topic gets sorted and
gives full understanding about those topics. Besides these if I get confused in any of the
topic I google it out or watch videos in youtube to get sorted out.
I am being able to catch up all the courses so, I am not having any difficulties. But if I
ever get confused in any topic I google it out or take help from youtube, also ask to my
friends to overcome those difficulties.

SAPHAL SHRESTHA Page 13


CC4002NA INFORMATION SYSTEMS

Bibliography
Anon., 2018. The python standard libarary. [Online]
Available at:
https://docs.python.org/3/library/stdtypes.html?fbclid=IwAR2gRu7eZ2WOzsNUeXDcP9
R2-k7JviALoif7Dk5yn2GJ2_VUmWONLatRkCE
Anon., 2018. w3resource. [Online]
Available at: https://www.w3resource.com/w3r_images/bubble-short.png
S.Adamchik, V., 2018. [Online]
Available at: https://www.cs.cmu.edu/~adamchik/15-
121/lectures/Sorting%20Algorithms/sorting.html

SAPHAL SHRESTHA Page 14

You might also like