0% found this document useful (0 votes)
61 views

Pseudocode Practice Solutions

The document contains practice problems for IBDP Computer Science SL/HL Paper 1, focusing on pseudocode solutions for various tasks. It includes searching for an element in an array, sorting an array using selection sort, counting passed students, finding the highest and lowest scores, and combining sorting and searching. Each problem is accompanied by input and output specifications along with example pseudocode solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Pseudocode Practice Solutions

The document contains practice problems for IBDP Computer Science SL/HL Paper 1, focusing on pseudocode solutions for various tasks. It includes searching for an element in an array, sorting an array using selection sort, counting passed students, finding the highest and lowest scores, and combining sorting and searching. Each problem is accompanied by input and output specifications along with example pseudocode solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

IBDP Computer Science SL/HL - Paper 1 practice

Solve the following questions:

1. Searching for an Element in an Array

Write a pseudocode to check if a specific number exists in an array of student IDs.

Input:

● Array STUDENT_IDS = [101, 203, 315, 432, 509]


● A student ID to search for.

Output:

● Print "Student ID X is found" if the ID is in the array.


● Print "Student ID X is not found" if the ID is not in the array.

Solution example:

FindStudent(studentID)
STUDENT_IDS = [101, 203, 315, 432, 509]

FOR i FROM 0 TO LENGTH(STUDENT_IDS) - 1


IF STUDENT_IDS[i] = studentID THEN
OUTPUT "Student ID " & studentID & " is found"
RETURN
END IF
END FOR
OUTPUT "Student ID " & studentID & " is not found"
END FindStudents
STUDENT_IDS = [101, 203, 315, 432, 509]

STUD_ID = 0

input STUD_ID

function FIND_STUD(FIND_ID)

loop i from 0 to 4

if STUDENT_IDS[i] = FIND_ID

output "Student ID X is found"

return 0

end if

end loop

output "Student ID X is not found"

return 0

end function

FIND_STUD(STUD_ID)

The above Only works on deep jain

2. Sorting an Array (Selection Sort)

Write a pseudocode to sort the STUDENT_IDS array in ascending order using selection
sort.

Input:

● Array STUDENT_IDS = [203, 432, 315, 509, 101]


Output:

● Sorted array: [101, 203, 315, 432, 509]

PROCEDURE SortStudents()
DECLARE STUDENT_IDS AS ARRAY ← [203, 432, 315, 509, 101]
DECLARE n ← LENGTH(STUDENT_IDS)

FOR i FROM 0 TO n - 2 DO
minIndex = i
FOR j FROM i + 1 TO n - 1
IF STUDENT_IDS[j] < STUDENT_IDS[minIndex] THEN
minIndex = j
END IF
END FOR
IF minIndex ≠ i THEN
DECLARE temp = STUDENT_IDS[i]
STUDENT_IDS[i] = STUDENT_IDS[minIndex]
STUDENT_IDS[minIndex] = temp
END IF
END FOR

OUTPUT STUDENT_IDS
END PROCEDURE

3. Counting Passed Students

Write a pseudocode to count how many students have passed a test. Passing scores
are stored in the SCORES array.

Input:

● Array SCORES = [45, 78, 62, 55, 90]


● Pass mark: 50

Output:

● The number of students who have passed.

CountPassedStudents()
SCORES = [45, 78, 62, 55, 90]
passMark = 50
count = 0

FOR i FROM 0 TO LENGTH(SCORES) - 1


IF SCORES[i] >= passMark THEN
count = count + 1
END IF
END FOR

OUTPUT "Number of students who passed: " & count


END CountPassedStudents

4. Finding the Highest Score

Write a pseudocode to find the highest score in the SCORES array.

Input:

● Array SCORES = [45, 78, 62, 55, 90]

Output:

● The highest score: 90

FindMaxScore()
SCORES = [45, 78, 62, 55, 90]
DECLARE max = SCORES[0]

FOR i FROM 1 TO LENGTH(SCORES) - 1 DO


IF SCORES[i] > max THEN
max = SCORES[i]
END IF
END FOR

OUTPUT "The highest score is: " & max


END FindMaxScore

5. Finding the Lowest Score

Write a pseudocode to find the lowest score in the SCORES array.

Input:

● Array SCORES = [45, 78, 62, 55, 90]

Output:

● The lowest score: 45

PROCEDURE FindMinScore()
SCORES = [45, 78, 62, 55, 90]
min = SCORES[0]

FOR i FROM 1 TO LENGTH(SCORES) - 1


IF SCORES[i] < min THEN
min = SCORES[i]
END IF
END FOR

OUTPUT "The lowest score is: " & min


END PROCEDURE

6. Combining Sorting and Searching

Problem:

First, sort the SCORES array in ascending order using selection sort. Then, write a
pseudocode function to check if a specific score exists in the array.
Input:

● Array SCORES = [45, 78, 62, 55, 90]


● A score to search for (e.g., 55).

Output:

● Print "Score X is found" or "Score X is not found".

PROCEDURE SortAndSearch(score)
SCORES = [45, 78, 62, 55, 90]
n = LENGTH(SCORES)

// Sorting using selection sort


FOR i FROM 0 TO n - 2
minIndex = i
FOR j FROM i + 1 TO n - 1
IF SCORES[j] < SCORES[minIndex] THEN
minIndex ← j
END IF
END FOR
IF minIndex ≠ i THEN
temp = SCORES[i]
SCORES[i] = SCORES[minIndex]
SCORES[minIndex] = temp
END IF
END FOR

// Searching for the score


FOR i FROM 0 TO LENGTH(SCORES) - 1
IF SCORES[i] = score THEN
OUTPUT "Score " & score & " is found"
RETURN
END IF
END FOR

OUTPUT "Score " & score & " is not found"


END PROCEDURE

*********************

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy