DAA-Assignment-0
Question-1
For Euclidean Algorithm to find GCD
- Define the problem solved by the algorithm (6pt)
- Input: 2 positive integer A,B
- Output: A positive integer that is Greatest Common Divisor of A and B
- Give a high-level presentation of the algorithm (6pt)
- Divide the larger number by the smaller number, then remove the divisor by the remainder that occurs (the first remainder), then remove the first remainder by the remainder that occurs (the second remainder), and so on until the final remainder is zero. If you are finding the greatest common divisor of two numbers, then the final divisor is the greatest common divisor of those two numbers.
- Write the pseudo code (8pt)
pseudo
\begin{algorithm}
\caption{Euclidean Algorithm}
\begin{algorithmic}
\WHILE{$B \neq 0$}
\STATE $temp \gets B$
\STATE $B \gets a \bmod b$
\STATE $A \gets temp$
\ENDWHILE
\RETURN $A$
\end{algorithmic}
\end{algorithm}
Question-2
- Input: A task t
- Output: "Yes" or "No"
pseudo
\begin{algorithm}
\caption{Task Work Procedure}
\begin{algorithmic}
\If{\Call{atomic}{$t$}}
\State \Return \Call{accomplishable}{$t$}
\EndIf
\State $subtasks \gets$ \Call{destruct}{$t$}
\For{each $subtask$ in $subtasks$}
\If{\Call{work}{$subtask$} == ``No''}
\State \Return ``No''
\EndIf
\EndFor
\State \Return ``Yes''
\end{algorithmic}
\end{algorithm}
Question-3
- Verification:
- The array A is known to be in ascending order and the length of the array is n. When we search for the target number x, we compare it with the middle element of the array.
- If
, the target number is found; - if
, the search needs to be narrowed down, the search needs to be done in the array containing elements from to ; - if
, the search needs to be done in the array containing elements from to .
- If
Question-4
Question-5
The main goal of algorithm analysis is to understand the rate at which an algorithm's running time or space requirement grows with input size. Although multiplication has a slower running time than addition, it does not affect the overall time complexity in general.