High-Frequency Pseudocode Flashcards – 9618 Paper 2

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

14 Terms

1
New cards

How do you find the maximum value in an array?

Max ← Array[1]
FOR i ← 2 TO LENGTH(Array)
  IF Array[i] > Max THEN
    Max ← Array[i]
  ENDIF
NEXT i

2
New cards

What is a CASE structure used for?

CASE Grade OF
  "A": OUTPUT "Excellent"
  "B": OUTPUT "Good"
  "C": OUTPUT "Average"
  OTHERWISE: OUTPUT "Fail"
ENDCASE

3
New cards

What is a typical trace table used for?

To track variable values and outputs during each step or loop iteration of a program.

4
New cards

How do you push to a stack if there's space?

IF Top = MaxSize THEN
  RETURN FALSE
ENDIF
Top ← Top + 1
Stack[Top] ← Value
RETURN TRUE

5
New cards

How do you loop through each element in a 2D array?

FOR i ← 1 TO Rows
  FOR j ← 1 TO Columns
    OUTPUT Array[i][j]
  NEXT j
NEXT i

6
New cards

How do you return TRUE if a string starts with a specific letter?

IF SUBSTRING(Name, 1, 1) = "A" THEN
  RETURN TRUE
ELSE
  RETURN FALSE
ENDIF

7
New cards

How do you handle unexpected input in a function?

IF NOT IS_NUM(Input) THEN
  RETURN -1
ELSE
  RETURN STR_TO_NUM(Input)
ENDIF

8
New cards

How do you compare characters in the same positions of two strings?

MatchCount ← 0
FOR i ← 1 TO LENGTH(String1)
  IF String1[i] = String2[i] THEN
    MatchCount ← MatchCount + 1
  ENDIF
NEXT i

9
New cards

How do you read data from a file into two parallel arrays?

Index ← 1
OPENFILE(FileIn, "data.txt", READ)
WHILE NOT EOF(FileIn)
  READFILE(FileIn, Array1[Index])
  READFILE(FileIn, Array2[Index])
  Index ← Index + 1
ENDWHILE
CLOSEFILE(FileIn)

10
New cards

How do you search for a record with a matching ID in an array?

FOR i ← 1 TO LENGTH(Records)
  IF Records[i].ID = SearchID THEN
    RETURN Records[i]
  ENDIF
NEXT i
RETURN NULL

11
New cards

What logic checks if all characters in a string are uppercase?

FOR i ← 1 TO LENGTH(Text)
  IF TO_UPPER(Text[i]) ≠ Text[i] THEN
    RETURN FALSE
  ENDIF
NEXT i
RETURN TRUE

12
New cards

How do you initialise all elements in a 2D array to zero?

FOR i ← 1 TO Rows
  FOR j ← 1 TO Columns
    Matrix[i][j] ← 0
  NEXT j
NEXT i

13
New cards

How do you reverse a string manually using a loop?

Reversed ← ""
FOR i ← LENGTH(Text) DOWNTO 1
  Reversed ← Reversed & Text[i]
NEXT i

14
New cards

What is the difference between a procedure and a function in pseudocode

A FUNCTION returns a value to the calling program using RETURN.
- A PROCEDURE performs actions but does not return a value.