Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

FacultyofEngineering

DepartmentofElectricalEngineeringandInformationTechnology
InstituteforComputerEngineeringProf.Dr.A.Hunger
AdvancedComputerArchitecture
Solution#7June18,2008

Solution#7

Example:PrimeNumberRecognition
Pseudocode!

Boolean function prim( n ) {


prim = true
i = 2
if (n < 2) {
return false
}
while (prim && i<n) {
if ( (n modulo i) == 0) {
prim = false
}
i++
}
return prim
}

F(n)=7n10
F(n)O(n)

Contact:KevinMoheb,M.Sc.

Page1

FacultyofEngineering
DepartmentofElectricalEngineeringandInformationTechnology
InstituteforComputerEngineeringProf.Dr.A.Hunger
AdvancedComputerArchitecture
Solution#7June18,2008

ComplexityforRecursiveProblems
Integer function rsearch(keyw, v, first, last)
{
if (last < first) {
return 0
}
mid = (first+last)/2
*/

/* truncate to integer

if (keyw == v[mid]) {
return mid
}
if (keyw < v[mid]) {
return rsearch (keyw, v, first, mid-1)
}
return rsearch (keyw, v, mid+1, last)
}

F(n)=F(n/2)+7
F(n)O(logn)

Contact:KevinMoheb,M.Sc.

Page2

FacultyofEngineering
DepartmentofElectricalEngineeringandInformationTechnology
InstituteforComputerEngineeringProf.Dr.A.Hunger
AdvancedComputerArchitecture
Solution#7June18,2008

ComplexityforSelectionSort
void selectionSort(int numbers[], int
array_size)
{
int i, j;
int min, temp;
for (i = 0; i < array_size-1; i++)
{
min = i;
for (j = i+1; j < array_size; j++)
{
if (numbers[j] < numbers[min])
min = j;
}
temp = numbers[i];
numbers[i] = numbers[min];
numbers[min] = temp;
}
}

F(n)=n(n1)/2+n1
F(n)O(n2)

Contact:KevinMoheb,M.Sc.

Page3

FacultyofEngineering
DepartmentofElectricalEngineeringandInformationTechnology
InstituteforComputerEngineeringProf.Dr.A.Hunger
AdvancedComputerArchitecture
Solution#7June18,2008

ComplexityforInsertionSort
void insertionSort(int numbers[], int
array_size)
{
int i, j, index;
for (i=1; i < array_size; i++)
{
index = numbers[i];
j = i;
while ((j > 0) && (numbers[j-1] >
index))
{
numbers[j] = numbers[j-1];
j = j - 1;
}
numbers[j] = index;
}
}

Homework
Sendyouranswerstill28.06.2008toKevin.moheb@unidue.de.

Contact:KevinMoheb,M.Sc.

Page4

FacultyofEngineering
DepartmentofElectricalEngineeringandInformationTechnology
InstituteforComputerEngineeringProf.Dr.A.Hunger
AdvancedComputerArchitecture
Solution#7June18,2008

1.Workloaddrivenevaluationofparallelsystems,memory
constrainedscaling:matrixfactorizationwithcomplexityntakes5
minutesfora1000by1000matrixononeprocessor.Whichtime
woulditneedon100processors(idealspeedup)?

1. 5minutes
2. 50minutes
3. 500minutes
4. 5000minutes

2.Workloaddrivenevaluationofparallelsystems,timeconstrained
scaling:Whichshouldbethenumberofrowsforamatrixmatrix
multiplicationon27processorsifitis1000on1processor(assuming
idealspeedup)?

1. 27000
2. 9000
3. 3000
4. 1000

Contact:KevinMoheb,M.Sc.

Page5

You might also like