Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Computer science Homework

Term-2
Name: Muhammad Afaq year -11 max marks: 15

Q1 Write a pseudocode for linear search?

LinearSearch(arr, target):
for each item in arr do
if item equals target then
return true
end if
end for
return false
--------------------------------------------------------------------------------------------------------------------------------
[5]

Q2 Write a pseudocode for bubble sort ?

DECLARE n: INTEGER
DECLARE swapped : BOOLEAN
n<---- items.Length
swapped <------ True
WHILE n>0 AND swapped DO
swapped <---- False
n <--- n-1
FOR index <--- 0 TO n-1
IF items(index) > items (index +1)
THEN
swap(items [index] , items [index+1]
Swapped <---- True
ENDIF
NEXT index
ENDWHile
RETURN items
--------------------------------------------------------------------------------------------------------------------------------
[5]
Q3 Write a pseudocode to enter and display elements in 1D array ?

Declare Array[10]
Output "Enter 10 numbers:"
for i from 0 to 9 do
Input Array[i]
end for

Output "Elements in the array are :"


for i from 0 to 9 do
Print Array[i]
end for
--------------------------------------------------------------------------------------------------------------------------------
[5]

You might also like