Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

IB Pseudocode Practice

Installing the pseudocode interpreter

To install the pseudocode interpreter:

• Check that you have at least Python 3.12 installed on your system.

• Install the ibdp_pseudocode interpreter using

python -m pip install ibdp_classes

• To interpret pseudocode, use

python -m ibdp_classes my_file.pseudo

where my_file.pseudo is the name of the text le containing your pseudocode.

Instructions

For each of the problems, create a document that contains the following sections:

•   Problem

A description of the problem being solved (which can be copied from this document).

•   Solution

A solution to the problem you have designed using IB pseudocode.

•   Demonstration of Correctness

A demonstration that your solution produces correct results (output from the pseudocode interpreter can be helpful).

For example, the document for problem 1 (a) could be presented as follows:

Needles in Haystacks

Problem 1 (a)

Given an array called HAYSTACK of length N containing integers, and an integer called NEEDLE, design an algorithm that correctly outputs whether NEEDLE is in HAYSTACK.

Solution

procedure SOLUTION(HAYSTACK, N, NEEDLE)

FOUND = false

loop I from 0 to N - 1

if HAYSTACK[I] = NEEDLE then

FOUND = true

end if

end loop

if FOUND then

output "Needle", NEEDLE, "found!"

else

output "Needle", NEEDLE, "not found!"

end if

end procedure

Demonstration of Correctness

HAYSTACK = new Array(

5, 10, -3, 8, 12, 0,

6, -9, 12, 1, 19, 9,

0, 11, 15, 6, -3, 0

)

N = 18

// Is 15 in HAYSTACK?

SOLUTION(HAYSTACK, N, 15)

// Is 100 in HAYSTACK?

SOLUTION(HAYSTACK, N, 100)

Needle 15 found!

Needle 100 not found!

Problem Set 1: Needles In Haystacks

Given an abstract data type (ADT) called HAYSTACK containing integers, and an integer called  NEEDLE, design an algorithm that correctly outputs whether NEEDLE is in HAYSTACK, for each of the following ADTs:

For HL & SL:

(a) HAYSTACK is an Array of length N.

(b) HAYSTACK is a Collection.

For HL:

(c) HAYSTACK is a 2D Array with dimensions ROWS x COLUMNS.

(d) HAYSTACK is a Stack.

(e) HAYSTACK is a Queue.

Problem Set 2: Average Values

Given an ADT of numbers called VALUES, design an algorithm that outputs the average value of the numbers stored in VALUES, for each of the following ADTs:

For HL & SL:

(a) VALUES is an Array of length N.

(b) VALUES is a Collection.

For HL:

(c) VALUES is a 2D Array with dimensions ROWS x COLUMNS.

(d) VALUES is a Stack.

(e) VALUES is a Queue.

Problem Set 3: Storing Maxima

For HL & SL:

(a) Given an Array of Collections called COLLECTIONS of length N and an Array of numbers called MAXIMA of the same length N, design an algorithm that stores the maximum

value in each Collection in COLLECTIONS at the respective index in MAXIMA. You may assume that none of the collections contain a value less than -100.

For HL:

(b) Given a 2D Array of numbers called VALUES with dimensions ROWS x COLUMNS, an Array of length ROWS called ROW_MAXIMA, and an Array of length COLUMNS called

COLUMN_MAXIMA, design an algorithm that stores the maximum value in each row of VALUES at the respective index in ROW_MAXIMA, and the maximum value in each

column of VALUES at the respective index in COLUMN_MAXIMA. You may assume that none of the values in the array are less than -100.

Problem Set 4: Reverse

Given an ADT of student names called STUDENTS, design an algorithm that rsts outputs the names in the order in which they appear or are extracted from the ADT, and then outputs the names in the opposite order, for each of the following ADTs:

For HL & SL:

(a)  STUDENTS is an Array of length N.

For HL:

(b) STUDENTS is a Collection (of unknown length); solve the problem using a Stack.

(c) Anti-loop discrimination

STUDENTS is a Collection (of unknown length); the solution may not use loops or other ADTs. (Hint: think recursively.)

Problem Set 5: Creative Problem Solving

For HL & SL

(a) Sum of changes

Given an Array of integers called VALUES and two indices START and END, output the   sum of the changes (increases and decreases are both considered positive changes) in values starting at index START and ending at index END.

(b) Outliers

We are given a Collection of numbers called DATA and a number called THRESHOLD. Any

number greater than or equal to THRESHOLD is considered an outlier. Design an

algorithm that outputs the greatest number in DATA that is not an outlier. You may assume that DATA only contains positive numbers.

(c) Obnoxious teens

We are given a Collection of numbers called AGES. Design an algorithm that ignores any numbers in AGES that we pronounce with a "-teen" and outputs the average of the remaining numbers.

(d) Hundreds, tens and units

We are given a Collection of integers called DATA. All the integers are between 0 and

1000. Design an algorithm that loops through the data and then nally outputs three

numbers: the sum of the hundreds digits, the sum of the tens digits and the sum of the units digits.

For HL

(e) Anti-loop discrimination

Write a function that accepts a Collection of numbers called VALUES and and returns   the sum of the stored numbers. However, there's one catch: you're not allowed to use any of the loop structures (for or while) in the function.

Assessment

Each of the problems will be assessed according to agreement with the following statements:

• The pseudocode adheres to the IB Approved Notation document.

-  Keywords are in lowercase (accept upper or lowercase not, and, and or keywords).

- Variables are in uppercase.

-  Object methods are written in camel-case (e.g. hasNext).

-  loop structures are closed with end loop.

-  if structures are closed with end if.

-  If the instructions are to design an algorithm that outputs a result (most cases in an   exam), then the result is output with the output keyword; if the instructions are to    design an algorithm that returns a result, then the result is returned with the return keyword.

• The algorithm can be expected to produce correct results.

• The algorithm is well designed.

- Appropriate and descriptive names have been used for intermediary variables.

- The algorithm is succinct.

- Whitespace (indentation, line-breaks, etc.) has been effectively used to improve readability.