Tutorial-1
Question1
Given the problem: “For the given positive integer, justify if it is a prime.”
Formally define the problem
Give some instances and corresponding outputs
3. Construct an algorithm and describe it with/without using pseudo code
- Input: a positive integer n
- Output: Yes, if n is a prime; No, Otherwise
pseudo
begin
for a =2 to |n^0.5| do
\if {$n%a=0} then
return No
end if
end for
return Yes
endAlgorithm 2 Quicksort
1:procedure Quicksort()
2:if then
3: Partition()
4:Quicksort()
5:Quicksort()
6:end if
7:end procedure
8:procedure Partition()
9:
10:
11:for to do
12:if then
13:
14:exchange with
15:end if
16:exchange with
17:end for
18:end procedure