Академический Документы
Профессиональный Документы
Культура Документы
Identify three real life scenarios where bubble sort, insertion sort and selection sort can be applied separately. Give reasons for your answer. Categorise widely used sorting algorithms based on time complexities. Write pseudo code algorithms to sort the data set A=[3, 7, 1,4,9,5] using a). b). c). Bubble sort Selection sort Insertion sort
. 1.4
Implement each of the algorithms in Java programming language for the data set given in question 1.3.
Q2 2.1
Write down an iterative algorithm in pseudo code that returns true if the array is sorted and false otherwise.
Page 1 of 3
2.2
Implement the pseudo code algorithm written in 2.1 in Java programming language. Consider the below given algorithm int unknownAlgorithm(int a[], int k, int n){ int i,j, mini,tmp; for(i=0; i< k; i++){ mini = i; for(j= i+1; j < n; j++) if(a[j] < a[mini]) mini=j; tmp = a[i]; a[i]=a[mini]; a[mini]=tmp; } return a[k-1]; } a) Using your own data set explain how the above algorithm works. b) Implement the above algorithm in Java programming language.
2.3
Q3 Quicksort can be described as a recursive in-place sorting algorithm that performs a partition() operation on the given array and then invokes itself twice on two distinct subranges of the array. 3.1 3.2 3.2 Describe the purpose, I/O parameters and effect of the partition() procedure and explain what the pivot is. Pseudocode is not required. Write the pseudo code algorithm for Quick sort. Implement the quicksort algorithm for the following list of unsorted integers using Java programming language. Assume that the pivot node is always the one on the left hand side of the list. 87, 36, 22, 15, 56, 85, 48, 90, 72, 6 Q4 4.1 4.2 4.3 Using a data set explain how Radix sort works. Write the pseudo code algorithm for radix sort. Implement the radix sort in Java and show how it works for the following list of 5 digit numbers considering the least significant digit. 17725; 82358; 12347; 45902; 93; 83976; 23789
List the searching techniques known to you along with respective time and storage complexities. Write the pseudo code algorithms for a) Sequential search
Page 2 of 3
b) Binary Search 5.3 Q6 The Fibonacci sequence is the sequence of integers 0,1,1,2,3,5,8,13,21,34 Each element in this sequence is the sum of the two preceding elements. For example, 0 + 1= 1, 1 + 1=2, 1 +2=3, 2+3=5 Fibonacci sequence can be defined as fib(n) = n if n=0 or n=1 fib(n) = fib(n-2) + fib(n-1) if n>=2 6.1 6.2 Write a pseudo code algorithm to calculate the Fibonacci sequence. Implement the above algorithm in java. Implement the above algorithms in Java. You should demonstrate the working of your algorithms using a suitable data set.
Q7. This will be a Moodle activity and will be uploaded to Moodle in due course.
Page 3 of 3