0% found this document useful (0 votes)
11 views2 pages

Cs Past Paper

The document contains 3 questions asking for pseudocode to perform linear search, bubble sort, and enter/display elements in a 1D array. Each question is worth 5 marks for a total of 15 marks.

Uploaded by

L'loyd
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)
11 views2 pages

Cs Past Paper

The document contains 3 questions asking for pseudocode to perform linear search, bubble sort, and enter/display elements in a 1D array. Each question is worth 5 marks for a total of 15 marks.

Uploaded by

L'loyd
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/ 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