Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Information System

CC4002NA
Coursework 1

Submitted By: Submitted To:


Dibya Shrestha Mr. Sukrit Shakya
NP01CP4A170082 Module Leader
L1C5 Information System
29 Dec 2017
INFORMATION SYSTEM(CC4002NA)

TABLE OF CONTENTS

1. BUBBLE SORT ALGORITHM..................................................................................1


1.1 Introduction.........................................................................................................1
1.2 Explanation/Working Principle............................................................................1
1.3 Example..............................................................................................................1
1.3.1 First Pass......................................................................................................1
1.3.2 Second Pass....................................................................................................2
1.3.3 Third Pass....................................................................................................3
2. GRAPHIC REPRESENTATION OF ALGORITHM..................................................4
2.1 Algorithm Bubble sort..........................................................................................4
2.2 Flowchart.............................................................................................................5
3. DATA STRUCTURES IN PYTHON..........................................................................6
3.1 Dictionaries.........................................................................................................6
3.2 List.......................................................................................................................6
3.3 Tuples.................................................................................................................7
3.4 Sets.....................................................................................................................8
4. REPORT...................................................................................................................9
5. REFERENCES.......................................................................................................11

TABLE OF FIGURES

Figure 1: First Pass.......................................................................................................2


Figure 2: Second Pass.................................................................................................2
Figure 3: Third Pass.....................................................................................................3
Figure 4: flowchart........................................................................................................5
INFORMATION SYSTEM(CC4002NA)

1. BUBBLE SORT ALGORITHM


1.1 Introduction
Bubble sort algorithm is defined as the simple sorting algorithm that follows a
series of steps, compare the adjacent elements, swap them if they are in the wrong
order to sort the given array from the lowest elements to the highest elements at the
last and is relatively easy to conceive and code. (Lambert, 2009)

1.2 Explanation/Working Principle


“It works by comparing pair of data elements as. Each time the elements in
the adjacent pair are out of order, the algorithm swaps them. This process has the
effect of bubbling the largest element to the end of the list. The process repeats from
the beginning of the list and goes to the next-to-last item and so on, until it begins
with the last item. At that point, the list is sorted.’ (Lambert, 2009)

If there are n number of elements to be sorted then the process mentioned


above should be repeated n-1 times to get required result.

1.3 Example
To sort 5 elements (5, 4, 8, 1, 2) in an array, we have to make 4
comparisons so that the largest element will bubble up in the top of the array.

1.3.1 First Pass


In fig: 1 pass comparison between 1 st element ‘5’ and 2nd element ‘4’ takes
place. Since ‘5’ is greater than ‘4’, so the number is swapped. Then 2 nd element ‘5’
and 3rd element ‘8’ is compared and do not swap its value since ‘5’ is smaller than ‘8’.
Similarly, 3rd element ‘8’ and 4 th element ‘1’ are compared and are swapped. Finally
4th element ‘8’ and 5th element ‘2’ are compared. Exchange takes place since ‘8’ is
greater than ‘2’.

1 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

First pass

5 4 8 1 2
Exchange

4 5 8 1 2
No Exchange

4 5 8 1 2 Exchange

4 5 1 8 2 Exchange

4 5 1 2 8 8 comes to last element from the 1st one

Figure 1: First Pass

1.3.2 Second Pass


Second pass

4 5 1 2 8
No Exchange

4 5 1 2 8 Exchange

4 1 5 2 8
Exchange

4 1 2 5 8
5 comes to 2nd last place of array

Figure 2: Second Pass


2 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

In fig:2 1st element’4’ and 2nd element ’5’ are compared and are not swapped since
‘4’ is smaller than ‘5’. 2nd element ‘5’ and 3rd element ‘1’ are compared and then
swapped since ‘5’ is greater than ‘1’. 3 rd element ’5’ and 4th element ‘2’ are
compared. They are swapped since ‘5’ is smaller than ‘2’.

1.3.3 Third Pass


In fig:3, the 1st element ’4’ and 2nd element ’1’ are compared and swapped
since ‘4’ is greater than ‘1’.Then, 2nd element ‘4’ and 3rd element ’2’ are compared
and swapped since ‘4’ is greater than ‘2’.The final value of this pass is 1,2,4,5,8.

Third pass

4 1 2 5 8
Exchange

1 4 2 5 8

1 2 4 5 8 4 comes to third last part of array

Figure 3: Third Pass


Since, the array had been completely arranged into ascending order, the process
stops right here.

3 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

2. GRAPHIC REPRESENTATION OF ALGORITHM

2.1 Algorithm Bubble sort


STEP 1: input [i=list()]

STEP 2: sorted=false

STEP 3: If sorted==false then go to step 4 else go to step 12

STEP 4: num_swaps=0

STEP 5:i=1

STEP 6: If i < list.length go to step 7 else goto step 10

STEP 7:If list[i-1] > list [i] then goto step 8 else goto step 9

STEP 8: tmp =list [i-1]

list [i-1] = list i

list i = tmp

Num_swaps=num_swaps+1

STEP 9:i=i+1

STEP 10:if num_swaps==0 then sorted=false else sorted=true

STEP 11:Go to step 3

STEP 12:print (i)

4 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

2.2 Flowchart

Start

Input
list list
Sorted=false

Sorted= NO
false

YES

Output list
Num_swaps=0

i=1
End

NO
i =i + 1 i<
list.length
Y

YES

NO YES
NO list [i-1] > Num_swap
list[i] s=o

YES

tmp =list [i-1]


Sorted=True Sorted=False
list [i-1] = list i

list i = tmp

Num_swaps=num_swaps+1
Figure 4: flowchart
5 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

3. DATA STRUCTURES IN PYTHON


Data structures are a way of organizing and storing data so that they can be
accessed and worked with efficiently. There are many various kinds of data
structures defined that make it easier for the data organization.
Its types are:

3.1 Dictionaries
In this data types, one-one relationship between keys and values are defined.

Data keys are case sensitive. (Pilgrim, 2004)

EG:

A [1] = ‘abc’

A [2] = ‘xyz’

{1:’abc’, 2:’xyz’}

A = {1:’abc’, 2:’xyz’}

Here 1, 2 are key and ‘abc’ and ‘xyz’ are its associated values. The whole elements
are covered in curly bracket.

Removing dictionary elements in dictionary

Del A[1] #remove value with key value 1

We can add new key/values at any time.

We can mix data types and delete items in dictionaries.

3.2 List
In python, list are used in collection of heterogeneous data. We can recognize
list by ‘[‘and ‘ ] ‘brackets.

Eg:

A= [0, 1, 2, 5, 7]

6 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

B= [apple, 0, ram]

Adding elements to the list

A= [0, 1, 2]

A.extend ([3, 4, 5])

A= [0, 1, 2, 3, 4, 5]

Len (A) 6

A= [0, 1, 2]

A.extend ([3, 4, 5])

A= [0, 1, 2, [3, 4, 5])

Searching in a list

A= [0, 1, 2, 2, 3, 1]

A.index (“2”) (2)

Deleting element in a list

A= [0, 1, 2, 3, 4]

A.remove [“2”]

A= [0, 1, 3, 4]

3.3 Tuples
Tuple in python is an immutable list. (Pilgrim, 2010)As long as you do not try
to change it, tuple acts as a list except that the elements are enclosed in
parentheses bracket instead of square brackets. Positive index count from the start
of the tuple while negative index counts from the end of tuple. (Pilgrim, 2010)

A= (“city”, “z”, “village”)

7 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

3.4 Sets
Data structure used to test for the membership for the processing of group of
names is called sets. Creating a set automatically removes any duplicate entries. It is
useful to find out what is common difference between two sets of items. (Pixel, 2010)

Eg:

A=set ([‘red’,’white’,’blue’,’black’])

Product Name Price Quantity

P001 Iphone 6 c 30

P002 Asus X556UB 1000 44

P003 Google Pixel 990 35

Dictionary data types is most suitable for the above data table. Dictionaries
uses keys and values. “The name is technically referred to as a key and any
corresponding detail is referred to as the value. The dictionary itself is a mutable
data type so we can remove and add new key/values in a dictionary” (Pixel, 2010).
As dictionaries can support tuple, strings and integers, the above data types also
contain varieties of strings and integers. We can also mix data types and delete data
types in dictionaries. Choosing the dictionary data types makes the problem more
efficient and convenience. (Pixel, 2010)

Product = {“name”:” IPhone 6”,”price”: “800”, “quantity”: “30”}

Product = {“name”:” Asus X556UB”,”price”: “1000”, “quantity”: “44”}

Product = {“name”:” Google Pixel”, “price”: “990”, “quantity”: “35”}

8 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

4. REPORT
Today the world has gone through the drastic changes through the
technologies that is introduced day by day. Information system is the study of
computer hardware and software which helps in storing, collecting and processing of
data and information. Python is a high level language which is used to create
programs. In general python provides a biggest hand in developing software and
enhancing the technologies. This module has helped me to deal with the data
systems and its use in the coding and programming.

Before starting the module, I had not gone through vast of the topic but I had
gain some information about python with my brother. Choosing the IT subject means
to become a good programmers. I expected to be familiar to the basic terms of the
module, so that it would be easier for me to deal with the difficulties that arises while
solving problems. I took the module quite easily that time, so it is difficult and I face
many difficulties while solving problems. As the module ‘information system is the
vast topic which requires a lot of focus, hardwork and time, it was difficult to
accommodate with the new course. It is a hard subject and each students must
practice more so that they can get used to the module.

Coming from a biology field, it was hard for me to be familiar with the basic
terms and technologies of information system at the beginning. It is still hard but I am
trying my best by taking help of my fellow friends and the respective teachers.
Whoever had choose this subjects, they have the motive to be familiar with the
module. So for me too, I am now familiar with the topics and going through my
regular classes, I feel the importance of information system in the developing world
and what changes can information system can bring in this world. So far till now I am
happy that I had chose this subject as I am very much interested in the respective
field.

I have a great expectations regarding this module in order to become a


successful programmer and secure my future. It is true that the course is not easy
and it is hard to achieve success in this field but I am going to give my best and
achieve my dream. Whatever the problem is I must go through it and face the
obstacles so that I can get what I want. Teachings of teachers is not enough to be
9 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

perfect in this field, we must focus and pay our full attention to the course to
overcome the obstacles. I believe that practice makes a man perfect and with that
quote in my mind I will accept whatever the future brings in my life. As I have already
taken the subject, I must not loose my confidence and focus hence to meet my
expectations from the module and thus achieve the success and the goal of my life.

10 Dibya
Shrestha
INFORMATION SYSTEM(CC4002NA)

5. REFERENCES

Lambert, K. A., 2009. Fundamentals of Python: From First Programs through Data
Structures. Boston: s.n.

Lambert, K. A., 2009. Fundamentals of Python: From First Programs through Data
Structures. illustrated ed. s.l.:Cengage Learning.

Pilgrim, M., 2004. Dive Into Python. s.l.:Apress.

Pilgrim, M., 2010. Dive Into Python 3. Apress: s.n.

Pixel, G., 2010. Python 3 for Absolute Beginners. illustrated ed. s.l.:Apress.

 Chun, W. (2001). Core Python programming. Upper Saddle River, NJ: Prentice Hall
PTR.

11 Dibya
Shrestha

You might also like