You are on page 1of 2

BAHRIA UNIVERSITY,

(Karachi Campus)
Department of Software Engineering
Assignment # 02 – Spring 2022

COURSE TITLE: Discrete Structures COURSE CODE: CSC - 115


CLASS: BSE – 2A & 2B SHIFT: Morning
INSTRUCTOR: ENGR. AMMARAH KHALID DATE: 26TH MAY 2022
MAX. MARKS: 5 Marks DUE DATE: 3RD JUNE 2022

STUDENT NAME: Rizwan Akram Enrollment No. # : 02-131212-026

ASSIGNMENT # 02 (CLO – 3)

Task # 01: Write Insertion Sort Algorithm and apply it on the list {80,50,22,34,33,45,75,10}

Task # 02: Identify the BIG O notation of Bubble sort and Insertion Sort Algorithm. Explain
your answer.

Answer: The Big O notation of Bubble Sort Algorithm is O(n²) in the average and worst case,
whereas in the best case the time complexity of Bubble Sort Algorithm in O(n).

Explanation: Foreach element in the array of size “n” bubble sort does n-1 comparison. So, the
total no. of comparisons and total no. of possible swaps can be written as:

1+2+3+4+5+….+ n - 1 = n( n-1 ) / 2 = O(n²)

The Big O notation of Insertion Sort Algorithm is also O(n²) in the average and worst case,
whereas in the best case the time complexity of Insertion Sort Algorithm in O(n).

Explanation: Foreach element in the array of size “n” insertion sort does n-1 comparison. So,
the total no. of comparisons and total no. of possible swaps can be written as:

1+2+3+4+5+….+ n - 1 = n( n-1 ) / 2 = O(n²)

Task # 03: Write program in java to generate pseudorandom number using linear congruential
generator. xn+1 = (3xn + 2) mod 13 with seed x0 = 1

Task # 04: Write program that will use hash function to provide the memory location (without
collision) on giving Enrollment no and memory address as input.
Task # 05: Write program that takes a message and a positive integer k less than 26, encrypt
this message using the shift cipher with key k; and given a message encrypted using a shift
cipher with key k, decrypt this message.

You might also like