0% found this document useful (0 votes)
24 views3 pages

Assignment of Discrete Mathematics: TOPIC: Algorithms

The document summarizes algorithms for finding the largest element in an array, counting the number of times a target is found in an array, and sorting arrays using bubble sort, selection sort, and insertion sort. It provides pseudocode procedures and steps for each algorithm.

Uploaded by

Tehniyat Rizwan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Assignment of Discrete Mathematics: TOPIC: Algorithms

The document summarizes algorithms for finding the largest element in an array, counting the number of times a target is found in an array, and sorting arrays using bubble sort, selection sort, and insertion sort. It provides pseudocode procedures and steps for each algorithm.

Uploaded by

Tehniyat Rizwan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment of Discrete

Mathematics

TOPIC: Algorithms

SUBMITTED TO: Ma’am Araf


SUBMITTED BY: Aiman Rizwan
ROLL NO: Info.Tech 16010
DEPARTMENT: BS IT
SEMETER: (3)
Algorithms to count how many time targets
found in array

Procedure search (a, target)


Count=0
for (i=0; i<n;i++)
if(a[]==target)or(i> max)
Count=count+1
[End loop]
if (i>max)then
Print (“target not found”)
else
Print count
[End if]
End Procedure

Algorithms largest element in array


1. max=a[0]
2. Repeat step 3 for i=0 to n by 1
3. if (a[ i ]>max) then
4. max=a[ i ];
[End if]
[End loop]
5. print max
6. Exit

Bubble Sort
1. Repeat step 2 to 4 for k=1 to n-1 by 1
2. Repeat step 3 to 4 for j=0 to n by 1
3. if a[ j ] >a[ j+1]
temp= a[ j ]
a[ j ] = a[ j+1]
a[ j+1] = temp
[End if]
[End loop]
4. End
Selection Sort
1. Repeat step 2 to 10 for i=1 to n by 1
2. Max=0
3. j=max+1
4. n=5
5. Repeat step 7 to 8 while( j < n)
6. If a[max]<a[j] then
7. Max=j
End if
8. j=j+1
[End while loop]
9. n=n-1
Temp=a[j]
a[j] =a[max]
a [max] =temp
[end for loop]
10. End

Insertion Sort
1. Repeat step 2 to 6 for c=1 to n by 1
2. Temp=a[c]
3. j=c
4. Repeat step 5 while( j>0 and temp<a[ j-1])
5. a[j]= a[j-1]
j=j-1
[End while loop]
6. a[j]= Temp
[End for loop]
7. End

You might also like