Computer Science 9618/33 — October/November 2024
Cambridge A-Level · Advanced Theory · worked solutions for every part, with the mark scheme
Topics Data Representation · Hardware and Virtual Machines · Communication and Internet Technologies · System Software · Further Programming · Computational Thinking and Problem-solving
Numbers are stored in a computer using binary floating-point representation with:
• 10 bits for the mantissa
• 6 bits for the exponent
• two’s complement form for both the mantissa and the exponent.
Calculate the normalised binary floating-point representation of +201.125 in this system.
Show your working.
Working .....................................................................................................................................
Working
201.125 = 11001001.001
Normalised form:
0.11001001001 × 2^8
Mantissa (10 bits) = 0110010010
Exponent +8 in 6-bit two's complement = 001000
Answer
Mantissa: 0110010010
Exponent: 001000
Mantissa 0110010010, Exponent 001000
Background Concept
In this floating-point format, the number is stored as:
- a mantissa
- an exponent
The value represented is:
mantissa × 2^exponent
Both fields use two's complement. For Cambridge-style binary floating-point questions, the binary point in the mantissa is assumed to be immediately after the sign bit. So a positive normalised mantissa begins 01... and a negative normalised mantissa begins 10....
Normalisation means shifting the binary point until the first two bits are different:
- positive numbers start
01 - negative numbers start
10
This makes the representation unique and uses the available mantissa bits efficiently.
Because the mantissa here has only 10 bits in total, that means:
- 1 sign bit
- 9 bits after the binary point
If the exact binary value needs more bits than that, the stored value must be truncated or rounded, so an exact representation may not be possible.
Understanding the Question
You are given a specific floating-point system:
- 10-bit mantissa
- 6-bit exponent
- two's complement for both
You must take the denary number +201.125, convert it into binary, normalise it, and then write the bit pattern that fits into the given mantissa and exponent boxes.
The important clues are:
- "normalised" tells you the mantissa must begin
01because the number is positive - "10 bits for the mantissa" means you may not be able to keep every binary digit
- "two's complement form for both" means the exponent also has to be written in 6-bit two's complement
Approach
The safest method is:
- Convert the whole number part and fractional part into binary.
- Combine them into one binary number.
- Shift the binary point to make a normalised mantissa.
- Count how many places the point moved: that is the exponent.
- Write the exponent in 6-bit two's complement.
- Fit the mantissa into 10 bits.
For a positive number, the mantissa should look like 0.xxxxx..., with the first fractional bit equal to 1 after normalisation.
Step-by-Step Reasoning
First convert 201 into binary.
201 = 128 + 64 + 8 + 1
So:
201 = 11001001
Now convert the fractional part 0.125 into binary.
0.125 = 1/8
So:
0.125 = 0.001
Combine them:
201.125 = 11001001.001
Now normalise it. We want the binary point immediately after the sign bit, so for a positive number we write it as:
0.11001001001 × 2^8
Why exponent 8? Because moving from 11001001.001 to 0.11001001001 means the binary point has moved 8 places to the left, so we multiply by 2^8 to preserve the value.
Now form the mantissa.
The exact normalised mantissa would be:
0.11001001001
But only 10 bits are available in total, including the sign bit. So we can store only:
- sign bit
0 - next 9 bits
110010010
This gives the 10-bit mantissa:
0110010010
Now encode the exponent. The exponent is +8.
In 6-bit two's complement, positive values are written as ordinary binary with a leading 0:
8 = 001000
So the stored floating-point representation is:
- Mantissa:
0110010010 - Exponent:
001000
A subtle point here is that the original value 201.125 does not fit exactly into a 10-bit mantissa, because the normalised form needs more than 9 fractional bits after the sign bit. So the stored mantissa is truncated to fit the field.
Key Takeaways
- Convert the denary number to binary before normalising.
- In this format, the binary point is immediately after the sign bit in the mantissa.
- A positive normalised mantissa begins
01; a negative one begins10. - The exponent is the number of places the binary point was shifted.
- Limited mantissa size can cause loss of precision.
Common Mistakes
- Writing the mantissa as if the binary point were at the far right. In this topic, it is assumed to be after the sign bit.
- Forgetting to normalise.
11001001.001is binary, but it is not yet in the required floating-point form. - Using the wrong exponent sign. If you shift the point left to make the mantissa smaller, the exponent is positive.
- Forgetting that the mantissa field includes the sign bit, so only 9 bits remain for the fractional part.
- Writing the exponent in plain binary without considering the stated bit width.
Things to Be Careful About
- Count mantissa bits exactly: 10 total, not 10 after the point.
- Count exponent bits exactly: 6 total.
- Because the number is positive, the sign bit of the mantissa is
0. - If the exact normalised mantissa is longer than the field, only the available bits can be stored.
- Do not write an unnormalised positive mantissa beginning
00or0110...without recognising where the binary point is assumed to be.
Calculate the denary value of the given normalised binary floating-point number.
Show your working.
| Mantissa | Exponent | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 |
Working .....................................................................................................................................
Answer ......................................................................................................................................
Working
Exponent: 000101 = +5
Mantissa: 1010110011 = -0.101001101
So the value is:
-0.101001101 × 2^5
= -10100.1101
= -20.8125
Answer
-20.8125
-20.8125
Background Concept
To convert a stored floating-point value back to denary, you decode both fields separately:
- the mantissa gives the signed fractional value
- the exponent tells you how far to shift the binary point
The overall value is:
mantissa × 2^exponent
In this syllabus, the mantissa is a two's complement fixed-point number with the binary point immediately after the sign bit. That means the bit weights are:
- first bit:
-1for a negative sign in two's complement - then
1/2,1/4,1/8,1/16, and so on
For a negative mantissa, you can either:
- use bit weights directly, or
- find its positive magnitude by taking the two's complement, then attach the minus sign
The exponent is also stored in two's complement, but as a normal integer.
Understanding the Question
You are given one complete floating-point value already stored in the machine:
- Mantissa:
1010110011 - Exponent:
000101
You must work out its denary value.
So this is the reverse of part (a): instead of encoding a denary number into floating point, you are decoding a floating-point value into denary.
The key detail inherited from the question stem is that both fields are in two's complement. That means you must not read the mantissa or exponent as ordinary unsigned binary.
Approach
A good method is:
- Decode the exponent first.
- Decode the mantissa second.
- Combine them as mantissa × 2^exponent.
- Convert the final binary result into denary.
For the mantissa, because the first bit is 1, it is negative. The cleanest way is to find the positive magnitude using two's complement, then write the mantissa as a negative binary fraction.
Step-by-Step Reasoning
Start with the exponent:
000101
This is a positive 6-bit two's complement number, so it is simply:
+5
Now look at the mantissa:
1010110011
Because the first bit is 1, the mantissa is negative.
Find its magnitude by taking the two's complement:
- Invert the bits:
0101001100
- Add 1:
0101001101
Now interpret that as a positive mantissa with the binary point after the sign bit:
0.101001101
So the original mantissa is:
-0.101001101
Now apply the exponent +5:
-0.101001101 × 2^5
Multiplying by 2^5 shifts the binary point 5 places to the right:
-10100.1101
Now convert 10100.1101 to denary.
Whole number part:
10100 = 16 + 4 = 20
Fractional part:
.1101 = 1/2 + 1/4 + 1/16 = 0.5 + 0.25 + 0.0625 = 0.8125
So:
10100.1101 = 20.8125
Apply the negative sign:
-20.8125
That is the denary value of the given floating-point number.
Key Takeaways
- Decode the exponent and mantissa separately.
- A two's complement mantissa with a leading
1is negative. - In this representation, the mantissa's binary point is after the sign bit.
- Multiplying by
2^nshifts the binary point right bynplaces. - After shifting, convert the whole and fractional parts of the binary number to denary.
Common Mistakes
- Treating the mantissa as an ordinary integer instead of a fixed-point fraction.
- Forgetting that the exponent is also in two's complement.
- Putting the binary point in the wrong place in the mantissa.
- Shifting the point the wrong way when the exponent is positive.
- Losing the negative sign after finding the mantissa magnitude.
Things to Be Careful About
- The mantissa
1010110011is not read as-355or any other whole-number interpretation; it is a signed fraction. - When you take two's complement to find the magnitude, remember both steps: invert and add 1.
- Keep the binary point after the sign bit before applying the exponent.
- After shifting, convert both the integer part and the fractional part carefully.
- Write the final denary answer with the correct sign:
-20.8125.
Reduced Instruction Set Computers (RISC) is a type of processor.
Identify four features of a RISC processor.
1 .......................................................................................................................................................
2 .......................................................................................................................................................
3 .......................................................................................................................................................
4 .......................................................................................................................................................
Answer
- Small set of simple instructions.
- Instructions are usually fixed length.
- Few addressing modes.
- Large number of general-purpose registers.
Small set of simple instructions; fixed-length instructions; few addressing modes; many general-purpose registers.
Background Concept
RISC stands for Reduced Instruction Set Computer. It is a processor design philosophy based on using a smaller set of simple instructions rather than a very large and complex set.
The main idea is that if instructions are simple and regular, the processor can execute them more quickly and more efficiently. This often makes features such as pipelining easier to implement, because each instruction has a similar format and takes a similar amount of work.
Typical RISC characteristics include:
- a small instruction set
- simple instructions rather than highly specialised ones
- fixed-length instructions
- few addressing modes
- a large number of registers
- often single-cycle execution for many instructions
In exam questions, you are usually being asked for these standard textbook features, not advantages such as “faster” unless that is explicitly asked.
Understanding the Question
The question asks you to identify four features of a RISC processor. That means you do not need to explain them in depth or compare them with CISC. You just need four correct characteristics.
Because the command word is identify, short precise points are best. The safest approach is to choose well-known structural features of RISC design, such as instruction-set size, instruction format, addressing modes, and register use.
Approach
A good way to answer is to think of the standard contrasts between RISC and CISC:
- RISC uses fewer, simpler instructions.
- RISC instructions are more uniform, often fixed in size.
- RISC relies more on registers.
- RISC reduces complexity such as the number of addressing modes.
Then select four separate points and write them as clear bullet points.
Step-by-Step Reasoning
The four selected features are:
-
Small set of simple instructions
This is the core meaning of “reduced instruction set”. RISC processors avoid a very large collection of complicated instructions. -
Instructions are usually fixed length
Fixed-size instructions make decoding easier and help the processor handle instructions in a regular way. -
Few addressing modes
Addressing modes are the different ways an instruction can refer to data. RISC keeps these limited to reduce complexity. -
Large number of general-purpose registers
RISC processors typically provide many registers so data can be held inside the CPU rather than accessed from main memory as often.
These are all distinct features, so they make a strong full-mark answer.
Key Takeaways
- RISC focuses on simplicity and regularity in processor design.
- Common RISC features include simple instructions, fixed-length instruction formats, few addressing modes, and many registers.
- For an identify question, short accurate points are enough.
Common Mistakes
- Giving advantages instead of features: writing “faster” or “more efficient” is not the same as identifying a feature.
- Repeating the same idea twice: for example, “small instruction set” and “reduced number of instructions” may be treated as the same point.
- Describing CISC instead: such as mentioning many complex instructions or many addressing modes.
- Being too vague: a point like “easy to use” would not be credited.
Things to Be Careful About
- Make sure the four points are distinct.
- Use standard syllabus terminology such as fixed length instructions, few addressing modes, and general-purpose registers.
- Do not spend time explaining unless asked; this question only needs identification.
- If you know more than four features, still choose the clearest four rather than giving uncertain ones.
Describe circuit switching as a method of data transmission.
...................................................................................................................................................
Answer
- A dedicated communication path is established between the sender and receiver before any data is sent.
- The connection and its bandwidth are reserved for the whole communication session, and all data travels along this same route.
- When transmission is finished, the circuit is cleared and the reserved resources are released.
A dedicated path is set up before transmission, kept reserved for the whole session, and released when communication ends.
Background Concept
Circuit switching is a transmission method in which a complete end-to-end route is created before data transfer starts. This route is dedicated to the two devices communicating. In other words, the links and switching capacity along that path are reserved for that session only.
This was the traditional method used in telephone networks. Once the circuit is set up, the data flows continuously along the same route. Because the route is fixed and reserved, the transmission is predictable, but it can also be wasteful if no data is being sent for part of the time.
The key stages are:
- setup of the circuit
- data transfer using that circuit
- clearing the circuit when communication ends
Understanding the Question
The question asks you to describe circuit switching as a method of data transmission. That means you are not being asked for advantages or disadvantages here; you are being asked how it works.
So the answer needs process points such as:
- a path is established first
- that path is dedicated/reserved
- it remains in use for the whole communication
- it is released afterwards
A good description focuses on the method, not on whether it is good or bad.
Approach
To answer a "describe" question like this, think of the life cycle of the communication:
- What happens before data is sent?
- What is true while data is being sent?
- What happens when the communication ends?
Using that structure makes it easy to include the marking points in a logical order.
Step-by-Step Reasoning
First, state that a dedicated path is created between sender and receiver before transmission begins. This is the defining feature of circuit switching. Unlike packet switching, the route is not chosen separately for each packet.
Second, explain that the connection stays in place for the whole session. The route and bandwidth are reserved, so all transmitted data uses that same route. This gives a steady flow of data and means the data arrives in sequence.
Third, state that when communication finishes, the circuit is disconnected and the reserved resources become available for other users.
These three ideas together form a complete description:
- setup before transfer
- reserved path during transfer
- release after transfer
Key Takeaways
- Circuit switching uses a dedicated end-to-end path.
- The path is established before data transmission starts.
- Resources stay reserved for the entire communication session.
- The circuit is released only when the session ends.
Common Mistakes
- Describing packet switching instead: saying data is split into packets that may take different routes is not circuit switching.
- Giving only benefits or drawbacks: this part asks how the method works, not whether it is efficient.
- Missing the setup stage: if you do not mention that the circuit is established before sending data, the answer is incomplete.
- Missing the reserved nature of the connection: a fixed path alone is not enough; the important idea is that it is dedicated for the session.
Things to Be Careful About
- Use the word dedicated or reserved for the connection/resources.
- Make clear that the path exists before data transfer begins.
- Do not confuse a session-long connection with packets independently routed across a network.
- For a 3-mark description, give multiple linked points rather than one vague sentence.
State one benefit and one drawback of circuit switching as a method of data transmission.
Benefit ......................................................................................................................................
Drawback ..................................................................................................................................
Answer
- Benefit: bandwidth is guaranteed for the connection, so there is no delay caused by competing traffic once the circuit is established.
- Drawback: the dedicated circuit remains reserved even when no data is being sent, so bandwidth is wasted.
Benefit: guaranteed bandwidth with no contention once connected. Drawback: bandwidth is wasted because the circuit stays reserved.
Background Concept
Because circuit switching reserves a complete path for one communication session, it has both strengths and weaknesses.
Its main strength is predictability. Since no other user shares that reserved path, the connection can provide steady performance.
Its main weakness is inefficiency. If the sender pauses or sends data only occasionally, the reserved path still cannot be used by anyone else.
Understanding the Question
This question asks for exactly one benefit and exactly one drawback of circuit switching.
So you should give:
- one clear advantage linked to the dedicated connection
- one clear disadvantage linked to the same feature
A strong answer avoids listing several ideas in a muddled way. One precise benefit and one precise drawback are enough.
Approach
Start from the core characteristic of circuit switching: resources are reserved for the whole session.
Then ask:
- What good thing does reservation give? Answer: guaranteed capacity / consistent transmission.
- What bad thing does reservation cause? Answer: waste / inefficiency when the line is idle.
That lets you derive both answers from the same core concept.
Step-by-Step Reasoning
For the benefit, a reserved circuit means other traffic does not compete for that bandwidth. So once the connection has been established, transmission is stable and predictable. That is why a valid answer is guaranteed bandwidth or no delay caused by contention.
For the drawback, the same reserved circuit cannot normally be reused by others during the session. If the line is idle for a moment, that capacity is still blocked out. So a valid drawback is that bandwidth is wasted or that the method is inefficient.
These are standard paired points:
- benefit: reliable, consistent transmission
- drawback: poor use of resources
Key Takeaways
- The dedicated nature of circuit switching gives predictable performance.
- The same dedicated nature can make it inefficient.
- Many networking questions test both sides of the same design choice.
Common Mistakes
- Giving two benefits or two drawbacks instead of one of each.
- Repeating how circuit switching works instead of stating an advantage or disadvantage.
- Saying "faster" without explaining why: it is better to link the benefit to guaranteed bandwidth or lack of contention.
- Giving a packet-switching drawback by mistake, such as packets arriving out of order.
Things to Be Careful About
- The question says one benefit and one drawback, so keep the answer concise.
- Make sure the benefit is actually about circuit switching, not networking in general.
- A setup delay can also be a valid drawback, but if you use that, make it clear it happens because a circuit must be established first.
- Use precise wording such as guaranteed bandwidth, reserved connection, or wasted bandwidth.
The TCP/IP protocol may be viewed as a stack that contains four layers: Application, Transport, Internet, Link.
Describe how the layers of the TCP/IP protocol stack interact with each other.
..........................................................................................................................................................
Answer
- Each layer performs a specific function and provides services to the layer above it.
- Each layer uses the services of the layer below it.
- At the sending device, data is passed down through the layers and each layer adds its own control information/header to the data.
- At the receiving device, data is passed up through the layers and each layer removes and interprets its own header; corresponding layers communicate using the same protocol.
Each layer provides services to the layer above, uses the layer below, adds its own header as data moves down the stack, and removes/interprets its header as data moves up at the receiver.
Background Concept
A protocol stack is a layered model for communication. Instead of one huge protocol doing everything, networking tasks are split into layers. In TCP/IP, the four layers are:
- Application
- Transport
- Internet
- Link
Each layer has its own job. For example, the Application layer handles services such as web or email access, the Transport layer manages end-to-end delivery, the Internet layer handles addressing and routing, and the Link layer deals with sending data across the local network medium.
The key idea of layering is:
- a layer offers services to the layer above it
- a layer uses services from the layer below it
- a layer communicates logically with the same layer on another device by following the same protocol rules
When data is sent, it moves down the stack. Each layer adds its own control information, usually as a header. This is called encapsulation.
When data is received, it moves up the stack. Each layer reads and removes the header meant for it. This is called decapsulation.
Understanding the Question
The question is not asking for the functions of each individual layer in detail. It is asking how the layers interact with each other.
So the important points are about the relationship between layers:
- upper layer and lower layer
- passing data down and up the stack
- adding and removing headers
- matching layers at sender and receiver
Because it is worth 4 marks, the expected answer is usually four clear statements covering these interactions.
Approach
A good approach is to describe the interaction in the order data travels:
- Each layer has a separate role.
- A layer depends on the one below and serves the one above.
- At the sender, data goes down the stack and headers are added.
- At the receiver, data goes up the stack and headers are removed.
That directly answers "how the layers interact" without drifting into unrelated detail about specific protocols such as HTTP or IP.
Step-by-Step Reasoning
Start with the structural relationship.
A layered stack works because each layer is designed to hide lower-level complexity from the layer above. So the first interaction is:
- a layer provides a service to the layer above it
For example, the Transport layer provides the Application layer with a way to send data end-to-end without the Application layer having to handle routing itself.
The second interaction is the reverse dependency:
- a layer uses the services of the layer below it
For example, the Internet layer uses the Link layer to actually place frames onto the network medium.
Now describe what happens during transmission.
At the sending computer, the Application layer creates the data. That data is then passed to the Transport layer, then to the Internet layer, then to the Link layer. As this happens:
- each layer adds its own control information, typically a header
This added information helps that layer do its job, such as identifying addresses, ports, error checking, or frame details. This process is encapsulation.
Finally, describe what happens at the receiver.
The Link layer receives the incoming data first, then passes it up to the Internet layer, then Transport, then Application. As it goes upward:
- each layer reads the header intended for it and removes it before passing the remaining data upward
This is decapsulation.
A final useful detail is that although data physically moves between adjacent layers on one machine, each layer is designed as though it communicates with its corresponding layer on the other machine. For example, the sender's Transport layer follows the same protocol rules as the receiver's Transport layer.
That is why the statement "corresponding layers communicate using the same protocol" is valid and often credited.
Key Takeaways
- TCP/IP is a layered protocol stack.
- Each layer serves the one above and depends on the one below.
- Sending uses downward movement through the stack with encapsulation.
- Receiving uses upward movement through the stack with decapsulation.
- Matching layers on different devices follow the same protocol rules.
Common Mistakes
- Describing only the purpose of each layer instead of explaining their interaction. The question is about how layers work together, not just what each one does.
- Forgetting to mention both directions of travel: down the stack when sending and up the stack when receiving.
- Omitting headers. Adding and removing headers is one of the main ways layers interact.
- Saying all layers communicate directly with all other layers. In the model, a layer mainly interacts with the adjacent layer above and below on the same machine.
- Mixing TCP/IP with the OSI model and listing the wrong number of layers.
Things to Be Careful About
- Use the layer names exactly as given in the question: Application, Transport, Internet, Link.
- If you mention headers, be clear that they are added as data moves down the stack and removed as it moves up.
- Do not overcomplicate the answer with examples of HTTP, TCP, IP, or Ethernet unless they help illustrate the interaction briefly.
- Keep the explanation focused on service provision, dependence on lower layers, encapsulation, and decapsulation, because those are the core examinable points here.
Explain what is meant by a hashing algorithm in the context of file access.
...................................................................................................................................................
Answer
- A hashing algorithm uses a record's key field to calculate a storage location/address.
- The calculated value is used to store or directly find the record in the file.
- This allows fast/direct access without searching through all records.
A hashing algorithm uses a key field to calculate a storage address for a record, allowing direct access to store or retrieve it.
Background Concept
A hashing algorithm is used when records in a file need to be accessed quickly. Instead of reading records one by one, the system takes a key value from the record, such as an ID number, and applies a formula to it. The result of that formula is called a hash value, and it is used as the storage location or address of the record.
This is associated with direct or random access file organisation. The goal is speed: if you know the key, you can calculate where the record should be, rather than searching the whole file.
For example, if a simple hash function is based on Key MOD 100, then key 24567 might map to location 67. The exact function can vary, but the principle is always the same: convert a key into an address.
Understanding the Question
The question asks what is meant by a hashing algorithm in file access. That means you are not being asked to describe a specific formula, but to explain the general idea:
- what input it uses
- what output it produces
- why it is useful in file access
To get full marks, the answer needs more than just "it finds a location". It should mention the key, the calculated address, and the fact that this supports direct/fast access to records.
Approach
A good way to answer is to build the explanation in three steps:
- Start with the key field from the record.
- State that an algorithm/formula is applied to generate an address or storage location.
- Explain that this is used for direct storage/retrieval, making access faster than searching sequentially.
That covers the definition and the purpose.
Step-by-Step Reasoning
A complete explanation includes the following ideas:
-
A record has a key field
In a file, each record usually contains a field that can identify it, such as a customer number or employee ID. -
The key is processed by a hash function
A hashing algorithm takes that key and performs a calculation on it. The calculation might use division, modulo, digit extraction or some other method. -
The result is a storage location/address
The output is not just another number for display; it is used as the address in the file where the record should be stored or found. -
This supports direct access
Because the address is calculated immediately from the key, the system does not need to check every earlier record first. That is why hashing is used for fast file access.
So the essential meaning is: a hashing algorithm maps a key to an address for efficient direct file access.
Key Takeaways
- Hashing uses a key field as input.
- The hash function produces a storage address/location.
- It is used to give fast direct access to records in a file.
- It avoids a full sequential search in normal use.
Common Mistakes
- Saying only "it encrypts data": hashing for file access is not the same as encryption.
- Forgetting to mention the key: the algorithm works on a record's key field, so that must be part of the definition.
- Forgetting to mention the address/location: the point of the hash value is that it identifies where the record is stored.
- Describing searching instead of hashing: hashing is about calculating the location directly, not scanning records one by one.
Things to Be Careful About
- Use wording linked to file access, not password hashing or cybersecurity hashing.
- Make clear that the algorithm calculates the location; it does not just "look it up" from nowhere.
- Include the idea of direct access or fast retrieval, because that is why hashing is used.
- Avoid saying the key is always unique in location; different keys can produce the same address, which leads to collisions and is the issue in part (b).
The use of a hashing algorithm can result in the same storage location being identified for more than one record.
Outline two methods of overcoming this issue.
1 ................................................................................................................................................
2 ................................................................................................................................................
Answer
- Linear probing / rehashing: if the calculated location is already occupied, check the next free location(s) until an empty slot is found.
- Overflow area / chaining: store the record in a separate overflow location and keep a link/pointer from the original hashed location to it.
Linear probing/rehashing and using an overflow area/chaining.
Background Concept
When two different keys produce the same hash value, a collision occurs. This means both records are trying to use the same storage location. Since only one record can occupy that exact slot directly, the system needs a collision-resolution method.
Common methods include:
- Open addressing: search for another empty location in the table.
- Linear probing: a simple form of open addressing where the next slot, then the next, and so on, is checked.
- Rehashing: apply another rule to find an alternative location.
- Overflow area: keep collided records in a separate part of storage.
- Chaining: keep multiple records associated with the same hash location, often via pointers/linked structures.
In exam answers, the important thing is to name a valid method and briefly say how it works.
Understanding the Question
The question states that more than one record may be assigned the same storage location. That tells you it is asking about collisions in hashing.
It asks for two methods of overcoming this issue, so two separate valid collision-handling techniques are needed. Since only 2 marks are available, each method only needs a short outline, not a long explanation.
Approach
Choose two standard, clearly different methods and outline each in one sentence. A safe pair is:
- Linear probing / rehashing
- Overflow area / chaining
These are widely accepted because one finds another slot in the main table, while the other stores extra collided records elsewhere.
Step-by-Step Reasoning
Here is what each method means:
-
Linear probing / rehashing
Suppose a record hashes to location20, but location20is already full. Instead of giving up, the system checks another position, often21, then22, and so on, until it finds an empty slot. This is called linear probing if the search proceeds one step at a time. -
Overflow area / chaining
If the main hashed location is already occupied, the new record is stored in a separate overflow location. The original slot then somehow indicates where the extra record is, often by a pointer or linked arrangement. This keeps all records available even though they share the same initial hash value.
Either of these solves the problem of two records mapping to one address.
If the mark scheme accepts alternatives, other correct answers could include quadratic probing or double hashing, but linear probing and overflow/chaining are the most standard and easiest to explain clearly.
Key Takeaways
- A collision happens when two keys hash to the same address.
- Collision handling is essential in hashed file access.
- Linear probing finds another free slot.
- Overflow area/chaining stores extra collided records separately or links them together.
Common Mistakes
- Only naming one method: the question explicitly asks for two.
- Repeating the same idea twice: for example, saying "probing" and then "checking the next location" as if they were two different methods.
- Explaining hashing again instead of collision handling: part (b) is specifically about what to do after a clash occurs.
- Giving vague statements like "store it somewhere else" without naming or outlining the method.
Things to Be Careful About
- Make sure each method is distinct enough to count separately.
- If you use the term rehashing, briefly indicate that another location is sought, not just that the value is recalculated.
- If you use overflow area or chaining, mention the idea of a separate storage location or link/pointer.
- Keep the answer concise: for 2 marks, one accurate sentence per method is enough.
Describe the user-defined data type set.
...................................................................................................................................................
Answer
- A set is a collection of values grouped together under one name.
- The values in a set are all of the same data type.
- Each value appears only once and the items are not stored in any particular order.
A set is an unordered collection of unique values of the same data type.
Background Concept
A user-defined data type is a type created by the programmer to model data in a way that matches the problem being solved. One example is a set.
A set stores a group of values as one collection. The important rules are:
- all members of the set are of the same type
- each member is unique
- the set is unordered
That means a set is different from an array or list. In an array, items usually have positions such as index 1, 2, 3, and duplicate values are allowed. In a set, there is no meaningful "first" or "second" item, and repeated values are not stored more than once.
Sets are useful when the main question is whether an item belongs to a collection, rather than where it is stored.
Understanding the Question
This part asks you to describe the user-defined data type set. That means the examiner is looking for the main defining features of a set, not code.
For 3 marks, you would normally need about three correct ideas. The strongest points are:
- it is a collection of values
- the values are of the same type
- the values are unique and unordered
Approach
For a "describe the data type" question, think of the features that make that type different from others.
Here, the best strategy is to state:
- what a set is in general
- what kind of values it holds
- the two key properties: no duplicates and no fixed order
That is enough for full marks without adding unnecessary detail.
Step-by-Step Reasoning
Start with the general definition:
- A set is a collection or group of values under one name.
Then add the typing rule:
- The members of the set are of the same data type.
Then give the properties that make a set special:
- members are unique, so duplicates are not allowed
- members are unordered, so they are not accessed by position like array elements
A concise exam answer combines these ideas into two or three bullet points. The important thing is that the answer clearly identifies the uniqueness and unordered nature of the collection.
Key Takeaways
- A set is a programmer-defined collection type.
- All members are of the same type.
- A set contains unique values only.
- A set is unordered, unlike an array or list.
Common Mistakes
- Saying a set is "in order" or "indexed". That describes an array more than a set.
- Forgetting to mention uniqueness. This is one of the main defining features.
- Describing it too vaguely as just "a group of data" without saying what makes it a set.
- Saying it can contain different data types mixed together. In this syllabus context, the set members should be of one type.
Things to Be Careful About
- If the question says describe, give properties, not an example only.
- Do not confuse a set with a record. A record groups different fields; a set groups multiple values of one type.
- Do not confuse a set with an array. Arrays have positions; sets are defined by membership.
- Keep the wording precise: unique and unordered are the safest key terms.
Write pseudocode statements to declare the set data type, SymbolSet, to hold the following set of mathematical operators, using the variable Operators.
+ – * / ^
Answer
TYPE SymbolSet = SET OF CHAR
ENDTYPE
DECLARE Operators : SymbolSet
Operators ← {'+', '-', '*', '/', '^'}
See completed pseudocode
Background Concept
When a question asks you to declare a user-defined data type, you usually need two separate ideas:
- define the type itself
- declare a variable that uses that type
For a set type, the definition must show what kind of values the set can hold. Here, the members are mathematical operator symbols such as + and *, so the element type is a character.
After defining the type, you declare a variable of that type. If the question also gives the values to be stored, you then initialise the variable with those set members.
A set literal contains the members of the set. Because sets contain unique values and have no meaningful order, the key thing is that all required symbols are included.
Understanding the Question
The question says:
- create a set data type called
SymbolSet - use a variable called
Operators - make it hold the operator symbols
+,-,*,/,^
So the answer must do more than just declare a variable. It must:
- define
SymbolSet - declare
Operatorsto be of typeSymbolSet - place the five operator characters into the set
Because this is Paper 3 style, the answer should be in pseudocode, not Python, Java, or VB.
Approach
A clean method is:
- define the type name and its member type
- declare the variable with that type
- assign the required set contents
Since all the items are single symbols, CHAR is the appropriate element type. The five operators are then written as individual character values inside the set.
Step-by-Step Reasoning
First, define the type:
TYPE SymbolSet = SET OF CHAR
ENDTYPE
This says that SymbolSet is a set where every member is a character.
Next, declare the variable:
DECLARE Operators : SymbolSet
This creates a variable named Operators whose type is the set type just defined.
Finally, initialise the set with the required operator symbols:
Operators ← {'+', '-', '*', '/', '^'}
Each item is written as a character. The assignment gives Operators exactly the set members listed in the question.
Why this works:
+,-,*,/,^are all single-character symbols- a set is the correct collection type because we just need membership of a group of symbols
- duplicates would not matter in a set, but none are given here anyway
A full-mark answer includes all three parts: type definition, variable declaration, and initial value.
Key Takeaways
- Defining a user-defined type and declaring a variable of that type are separate steps.
- A set type must specify the type of its members.
- Character symbols such as operators are best stored as
CHARvalues. - Initialising the set with the required members shows how the variable will actually be used.
Common Mistakes
- Declaring only
Operatorsand forgetting to defineSymbolSet. - Using
STRINGinstead ofCHARfor single-symbol members. - Writing the operators as one combined string instead of as separate set members.
- Using real-programming syntax instead of pseudocode.
- Forgetting the assignment that actually places the symbols into the set.
Things to Be Careful About
- Keep the identifier names exactly as given:
SymbolSetandOperators. - Use proper pseudocode style, including
DECLAREand the assignment arrow←. - The members are individual symbols, so they should be treated as single characters.
- Do not describe the answer in prose; the question specifically asks for pseudocode statements.
- If your course materials use slightly different set-literal brackets, the essential marks still come from clearly defining the set type, declaring the variable, and showing the five members.
The truth table for a logic circuit is shown.
| INPUT | OUTPUT | |||
|---|---|---|---|---|
| A | B | C | D | T |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 |
Write the Boolean logic expression that corresponds to the given truth table as the sum-of-products.
T = ............................................................................................................................................
Answer
T = A'B'C'D + A'B'CD + AB'C'D + AB'CD + ABC'D + ABCD
Background Concept
A sum-of-products expression is an OR of product terms. Each product term, often called a minterm in the canonical form, comes from one row of the truth table where the output is 1.
To write a minterm from a row:
- if a variable is 1 in that row, write it uncomplemented
- if a variable is 0 in that row, write it complemented
- join the literals with AND
For example, the row , , , gives the minterm .
In the canonical sum-of-products form, every minterm must contain every variable exactly once.
Understanding the Question
You are given a complete truth table for inputs , , , and output . Part (a) asks for the Boolean expression that matches the table as a sum-of-products.
That means you are not simplifying yet. You are simply translating every row where into a minterm, then ORing all those minterms together.
Approach
The safest method is:
- Find every row where .
- Convert each of those rows into a product term.
- Add the product terms together with OR.
Because this is canonical sum-of-products, do not try to combine terms yet, and do not miss out any variable from a term.
Step-by-Step Reasoning
From the truth table, in these rows:
Now convert each row into a minterm.
For :
For :
For :
For :
For :
For :
OR all six minterms together:
That is the required sum-of-products expression.
Key Takeaways
- Canonical sum-of-products uses one minterm for each truth-table row with output 1.
- Each minterm must include all variables.
- A 0 in the row means complemented; a 1 means uncomplemented.
Common Mistakes
- Using rows where . Only rows with output 1 contribute minterms.
- Missing a variable from a minterm. In canonical form, every term must contain , , and .
- Complementing the wrong variables. A variable is complemented only when its value in that row is 0.
- Simplifying too early. This part asks for the full sum-of-products, not the simplified version.
Things to Be Careful About
- Keep the variable order consistent as , , , .
- Do not confuse AND within a minterm with OR between minterms.
- Make sure repeated patterns are still written as separate minterms at this stage; combining comes later with the K-map.
Answer
| CD \ AB | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 0 | 0 | 0 | 0 |
| 01 | 1 | 0 | 1 | 1 |
| 11 | 1 | 0 | 1 | 1 |
| 10 | 0 | 0 | 0 | 0 |
See completed K-map
Background Concept
A Karnaugh map is a visual tool for simplifying Boolean expressions. It rearranges truth-table values so that adjacent cells differ by only one variable. This is why the row and column labels use Gray-code order, not normal binary order.
For a 4-variable K-map:
- one pair of variables labels the columns
- one pair labels the rows
- the order is usually , , ,
In this question, the columns are and the rows are .
Understanding the Question
You are asked to complete the K-map using the truth table given in the main question stem.
So the job is to take each truth-table combination of , , , and place the corresponding output into the correct K-map cell. The important detail is that the map uses Gray-code order:
- columns:
- rows:
Approach
A reliable way to do this is:
- Keep the K-map header order fixed.
- For each truth-table row, find the column from and the row from .
- Write the output value into that cell.
Because the truth table already gives all 16 combinations, every K-map cell will be filled exactly once.
Step-by-Step Reasoning
The rows where are:
- ,
- ,
- ,
- ,
- ,
- ,
All other cells contain 0.
Now fill the K-map in the required Gray-code order.
Columns are .
Rows are .
- Row : all outputs are 0.
- Row : outputs are 1, 0, 1, 1.
- Row : outputs are 1, 0, 1, 1.
- Row : all outputs are 0.
So the completed K-map is:
| CD \ AB | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 0 | 0 | 0 | 0 |
| 01 | 1 | 0 | 1 | 1 |
| 11 | 1 | 0 | 1 | 1 |
| 10 | 0 | 0 | 0 | 0 |
Key Takeaways
- A K-map is just a truth table rearranged into Gray-code order.
- The order is essential because it creates adjacency.
- Filling the K-map accurately is the foundation for correct grouping in the next part.
Common Mistakes
- Using binary order instead of Gray-code order. That breaks adjacency.
- Swapping the meanings of rows and columns. Here columns are and rows are .
- Copying 1s into the wrong cells because the map order differs from the truth-table order.
- Forgetting that every one of the 16 cells must be filled.
Things to Be Careful About
- Read the variable labels on the diagram carefully before filling anything in.
- Check each cell using both its row label and column label.
- Do not assume left-to-right or top-to-bottom follows normal binary counting; in a K-map it follows Gray code.
Draw loop(s) around appropriate group(s) in the K-map to produce an optimal sum-of-products.
Answer
See K-map loops
Background Concept
In a Karnaugh map, loops are drawn around groups of 1s to simplify a Boolean expression. Valid groups must:
- contain , , , , ... cells
- be rectangular
- contain only 1s
- be as large as possible
K-map edges wrap around, so the leftmost and rightmost columns are adjacent, and the top and bottom rows are adjacent.
Overlapping groups are allowed if that helps produce a simpler final expression.
Understanding the Question
This part does not ask for the expression yet. It asks you to draw the loop or loops that give the optimal sum-of-products from the completed K-map.
So you must choose groups that cover all the 1s using the largest valid rectangles, including wrap-around adjacency where helpful.
Approach
From the completed K-map, there are six 1s. The best strategy is to make groups of 4, because larger groups remove more variables and give a simpler result.
Here, the optimal answer uses two groups of four:
- a normal group on the right-hand side
- a wrap-around group using the leftmost and rightmost columns
Step-by-Step Reasoning
The 1s are arranged like this:
- row : columns , ,
- row : columns , ,
A good first group is the block covering:
- rows and
- columns and
That is a group of four 1s.
The remaining uncovered 1s are in column for rows and . Because K-map edges wrap around, column is adjacent to column . So the second group is another group of four covering:
- rows and
- columns and
This second group overlaps the first at the cells in column , and that is perfectly allowed.
This is the required grouping:
These loops are optimal because they use only groups of four and cover all 1s.
Key Takeaways
- Always try to make the largest possible groups.
- K-map edges wrap around, so outer columns and outer rows can be adjacent.
- Overlap is allowed if it leads to larger groups and a simpler expression.
Common Mistakes
- Drawing groups of 2 when a group of 4 is possible. That gives a less simplified answer.
- Forgetting wrap-around adjacency between the left and right edges.
- Grouping diagonally. Diagonal cells are not adjacent in a K-map.
- Making a loop that includes a 0. Every cell in a group must be 1.
Things to Be Careful About
- Group sizes must be powers of two only.
- Groups should be chosen for simplification, not just to cover cells somehow.
- A 1 may appear in more than one group if that improves the final expression.
- Keep the row and column order in Gray code when judging adjacency.
Write the Boolean logic expression from your answer to part (c) as the simplified sum-of-products.
T = ......................................................................................................................................
Answer
T = AD + B'D
Background Concept
Each K-map loop gives one product term, often called an implicant.
To read a term from a loop:
- keep only the variables that stay constant throughout the whole group
- if a constant variable is 1, write it uncomplemented
- if a constant variable is 0, write it complemented
- any variable that changes within the group disappears from that term
This is why bigger K-map groups produce simpler terms: more variables change, so more variables cancel out.
Understanding the Question
Part (d)(i) asks you to take the loops from part (c) and write the simplified sum-of-products expression.
So you must convert each loop into one product term, then OR the terms together.
Approach
Look at each loop separately.
- Identify which row and column labels are covered.
- Work out which of , , , remain fixed in all cells of that loop.
- Write one term for each loop.
- Add the terms.
Step-by-Step Reasoning
First loop:
- columns and
- rows and
Check which variables stay constant:
- in both columns and , so keep
- changes from 1 to 0, so remove
- changes from 0 to 1, so remove
- in both rows and , so keep
So the first loop gives:
Second loop:
- columns and
- rows and
Check constants again:
- changes from 0 to 1, so remove
- in both columns, so keep
- changes from 0 to 1, so remove
- in both rows, so keep
So the second loop gives:
Now OR the two terms:
That is the simplified sum-of-products from the K-map.
Key Takeaways
- One loop gives one product term.
- Variables that change within a loop disappear.
- Variables that stay constant form the simplified term.
Common Mistakes
- Keeping a variable that changes within the group. Changing variables must be removed.
- Complementing a variable incorrectly. A constant 0 gives a complemented variable; a constant 1 gives an uncomplemented variable.
- Mixing both loops into one term. Each loop produces its own product term.
- Writing the factorised answer here. This part asks for sum-of-products, so is the correct form for this stage.
Things to Be Careful About
- Read the Gray-code labels correctly when deciding which variable values are constant.
- Wrap-around groups are treated exactly the same as normal groups when extracting terms.
- Do not include in either term here, because it changes between rows and .
Use Boolean algebra to write your answer to part (d)(i) in its simplest form.
T = ...............................................................................................................................
Answer
T = D(A + B')
Background Concept
Boolean algebra uses rules similar to ordinary algebra, although the operations represent logic.
One very useful rule is the distributive law:
This lets you factor out a common term. In logic simplification, that often gives a shorter or neater expression.
Understanding the Question
You are asked to take the expression from part (d)(i) and write it in its simplest form using Boolean algebra.
From part (d)(i), the expression is:
Both terms contain , so the obvious simplification is to factor out .
Approach
Use the distributive law directly:
- spot the common factor
- take it outside brackets
- leave the remaining terms inside the brackets joined by OR
Step-by-Step Reasoning
Start with:
Both terms have .
Factor it out:
No further simplification is possible here, so this is the simplest form.
Key Takeaways
- Boolean expressions can often be simplified by factoring out a common term.
- The rule is a standard simplification technique.
- A factorised form can be simpler than a sum-of-products form.
Common Mistakes
- Forgetting that both terms must contain the same factor before you factor it out.
- Writing , which changes the logic completely. The correct bracketed expression is .
- Trying to simplify inside the bracket when there is no valid rule to do so.
Things to Be Careful About
- This part asks for the simplest form, not specifically sum-of-products.
- Keep the OR sign inside the bracket: .
- Make sure stays complemented after factorisation.
Describe the process of segmentation for memory management.
...................................................................................................................................................
Answer
- Segmentation divides a program into logical sections such as code, data and stack.
- These sections are stored as separate segments of different sizes.
- Each segment has an entry in a segment table holding information such as its base address and length/limit.
- A logical address uses a segment number and an offset; the operating system uses the segment table to find the physical address, so segments can be placed in different areas of main memory.
A program is split into variable-sized logical segments, each with a segment-table entry such as base address and limit; addresses use segment number plus offset, allowing segments to be stored separately in memory.
Background Concept
Segmentation is a memory-management technique in which a program is divided into meaningful logical parts called segments. Unlike paging, where memory is split into fixed-size blocks, segmentation uses variable-sized blocks because different parts of a program naturally have different sizes.
Typical segments include:
- program code
- data
- stack
- heap
Each segment is treated separately by the operating system. A segment table stores details for each segment, usually including:
- where that segment starts in physical memory, called the base address
- how large the segment is, often called the limit or length
When a program refers to memory, the address is not just a single physical location. Instead, it is usually expressed as:
- segment number
- offset within that segment
The operating system checks the segment number, looks up the segment table entry, checks that the offset is within the segment limit, and then forms the physical address.
Understanding the Question
The question asks you to describe the process of segmentation for memory management. That means you should explain how memory is organised and how an address is interpreted when segmentation is used.
This is not asking for advantages/disadvantages only, and it is not asking about paging. The key clues are the word process and the specific term segmentation. So a full answer should cover:
- that a program is split into logical parts
- that the segments can be different sizes
- that the system stores information about each segment in a table
- that addressing uses a segment identifier plus an offset
Approach
A strong way to answer is to describe segmentation in the order it happens:
- split the program into logical sections
- treat each section as a separate segment
- store each segment's location and size in a segment table
- use the segment number and offset to translate a logical address into a physical address
That sequence gives the examiner the main marking points clearly and avoids drifting into paging.
Step-by-Step Reasoning
First, explain what gets divided. In segmentation, the whole program is not treated as one large continuous block. Instead, it is broken into logical units such as code, data and stack.
Second, explain the size rule. These segments are variable in size. This matters because code might be large, a stack may grow, and data may be a different size again. That is one major difference from paging, where blocks are fixed size.
Third, explain how the system keeps track of them. The operating system maintains a segment table. Each table entry corresponds to one segment and stores information such as:
- the base address, meaning where that segment begins in memory
- the limit or length, meaning how far the segment extends
Fourth, explain addressing. A memory reference is made using:
- a segment number, which says which logical section is wanted
- an offset, which says how far into that segment the required item is
The operating system then:
- finds the correct segment table entry
- checks the offset is valid for that segment
- adds the offset to the base address to obtain the actual physical location
This means the segments do not all have to sit together as one continuous block in memory. Different segments of the same program may be stored in different places.
Key Takeaways
- Segmentation divides a program into logical, variable-sized parts.
- Each segment has its own table entry, including at least a start location and size.
- Addresses are usually written as segment number plus offset.
- The operating system translates that logical address into a physical address.
Common Mistakes
- Confusing segmentation with paging. Paging uses fixed-size pages; segmentation uses variable-sized logical sections.
- Saying the whole program must be stored contiguously. In segmentation, different segments can be placed in different areas of memory.
- Forgetting the segment table. Without mentioning how the system keeps track of segments, the process is incomplete.
- Giving only examples like code and data without explaining how addressing works.
Things to Be Careful About
- Use the word logical when describing the divisions, because segments are based on program structure, not equal-size blocks.
- Mention that segment sizes can differ.
- If you mention addresses, be precise: it is segment number plus offset, not page number plus offset.
- Do not drift into virtual memory unless the question asks for it specifically.
Explain what is meant by disk thrashing.
...................................................................................................................................................
Answer
- Disk thrashing is when the system spends most of its time moving pages/segments between main memory and backing store.
- It happens because there is insufficient RAM for the processes being run, causing very frequent page faults.
- As a result, little useful processing is done because the disk activity dominates CPU time.
Disk thrashing is excessive swapping of pages or segments between RAM and disk, usually because there is not enough memory, so the system spends more time swapping than executing programs.
Background Concept
Disk thrashing happens in systems that use virtual memory. Virtual memory allows programs to use more memory than is physically available in RAM by keeping some data on secondary storage, usually a hard disk or SSD, and moving it into RAM when needed.
This movement is useful when it happens occasionally. However, if the operating system has too little RAM available for the active processes, it may need to keep removing one page or segment and then loading another one almost immediately afterwards. When that repeated swapping becomes excessive, the system is said to be thrashing.
The key idea is that the computer is technically working, but most of its work is memory transfer rather than actual program execution.
Understanding the Question
The question asks what is meant by disk thrashing. So you need more than just the phrase too much swapping. A complete answer should explain:
- what the system is doing
- why it happens
- what effect it has on performance
Because the term includes disk, the answer should make clear that the transfers are between main memory and backing store on disk.
Approach
A good explanation has a simple cause-and-effect structure:
- define thrashing as repeated transfer of memory contents between RAM and disk
- explain the cause as insufficient RAM or too many active processes
- explain the effect as very poor performance because little real processing gets done
That covers the idea fully in a compact way.
Step-by-Step Reasoning
Start with the memory situation. A program needs certain pages or segments in RAM to run efficiently. If there is enough RAM, the needed parts stay in memory long enough for useful work to be done.
Now consider what happens when RAM is too limited. The operating system loads a required page or segment from disk into RAM. To make room, it may have to write another one out to disk.
Soon after, the program or another process may need the part that was just removed. The system then has to bring that one back from disk and possibly remove something else.
This creates a cycle:
- page or segment needed
- load from disk
- remove another item from RAM
- shortly afterwards need that removed item again
- repeat
Because disk access is much slower than RAM access, the computer spends a very large proportion of time doing these transfers. That means:
- many page faults occur
- CPU time is wasted waiting for data movement
- overall system performance drops sharply
So disk thrashing means the machine is busy, but not productive. Most effort goes into swapping rather than executing instructions.
Key Takeaways
- Disk thrashing is excessive swapping between RAM and backing store.
- It is usually caused by insufficient physical memory for the current workload.
- The main symptom is severe slowdown because memory movement dominates processing.
Common Mistakes
- Saying it is just high disk usage. Thrashing specifically refers to excessive swapping caused by memory pressure.
- Forgetting the cause. A full explanation should mention too little RAM or too many active processes.
- Forgetting the effect. The important consequence is that little useful work is completed.
- Describing general fragmentation instead. Thrashing is about virtual memory activity, not how memory blocks are arranged.
Things to Be Careful About
- Use the idea of pages or segments moving between RAM and disk, since this is a memory-management term.
- Mention backing store or disk, not just memory, because the slow transfer to secondary storage is what causes the performance problem.
- Keep the explanation focused on repeated swapping, not on one normal page transfer.
- If you mention page faults, make sure they are described as frequent or excessive.
A veterinary surgery wants to create a class for individual pets.
Some of the attributes required in the class are listed in the table.
| Attribute | Data type | Description |
|---|---|---|
| PetID | STRING | unique ID assigned at registration |
| PetType | STRING | type of pet assigned at registration |
| OwnerTelephone | STRING | telephone number of owner assigned at registration |
| DateRegistered | DATE | date of registration |
State one reason why the attributes would be declared as PRIVATE.
...................................................................................................................................................
Answer
- To provide encapsulation/data hiding, so the attributes cannot be accessed or changed directly from outside the class.
To provide encapsulation/data hiding, so the attributes cannot be accessed directly from outside the class.
Background Concept
In object-oriented programming, a class contains attributes (data) and methods (operations). One of the key ideas is encapsulation. Encapsulation means keeping the data and the code that works on that data together inside the class, and controlling how other parts of the program use it.
When an attribute is declared PRIVATE, code outside the class cannot access or change it directly. Instead, access is usually through methods such as setters and getters. This is also called data hiding.
Understanding the Question
The question gives a class for pets and asks for one reason why the attributes would be declared PRIVATE.
So this is not asking for a programming-language rule or syntax. It is asking for the design reason behind making class data private.
Approach
For a one-mark theory question like this, the best approach is to give one precise OOP reason. The strongest answer is usually about:
- encapsulation
- data hiding
- preventing direct external access
- forcing controlled access through methods
Any one of these, stated clearly, would gain the mark.
Step-by-Step Reasoning
The attributes listed, such as PetID and OwnerTelephone, are part of the internal state of a Pet object.
If they are PRIVATE:
- code outside the class cannot directly do something like changing them freely
- the class controls access to them
- methods can check values before changing them if needed
So the key reason is that private attributes protect the object's data and support encapsulation.
A concise full-mark answer is:
- the attributes are private so they cannot be accessed or changed directly from outside the class
or equivalently:
- the attributes are private to provide encapsulation/data hiding
Key Takeaways
PRIVATEattributes are used to support encapsulation.- Encapsulation means data is protected inside the class.
- Access to private data is controlled through methods.
Common Mistakes
- Saying only "because that is how classes work". This is too vague and does not explain the reason.
- Talking about inheritance or polymorphism. Those are OOP ideas, but they are not what this question is testing.
- Saying private means the attribute is hidden from the programmer completely. It is hidden from outside the class, not from methods inside the class.
Things to Be Careful About
- The question asks for one reason, so one clear point is enough.
- Use OOP vocabulary accurately:
PRIVATErelates to encapsulation and data hiding. - Do not confuse
PRIVATEwith encryption or security in the network sense; this is about program design and access control inside a class.
Complete the class diagram for Pet, to include:
• an attribute and data type for the name of the pet
• an attribute and data type for the name of the owner
• a method to create a Pet object and set attributes at the time of registration
• a method to assign a pet ID
• a method to assign the date of registration
• a method to return the pet name
• a method to return the owner’s telephone number.
Answer
See class diagram
Background Concept
A class diagram is used in object-oriented programming to show the structure of a class. It usually has three parts:
- the class name
- the attributes
- the methods
Attributes store the data for each object. Methods define what the object can do.
Typical method categories are:
- a constructor, which creates an object and sets its starting values
- setter methods, which assign or update attribute values
- getter methods, which return attribute values
In UML-style class diagrams, attributes are often shown in the form AttributeName : DataType, and methods are shown with their parameter list and return type where appropriate.
Understanding the Question
The question already gives four attributes for the Pet class:
PetID : STRINGPetType : STRINGOwnerTelephone : STRINGDateRegistered : DATE
It then asks you to complete the class diagram by adding:
- an attribute for the pet's name
- an attribute for the owner's name
- a method to create a
Petobject and set attributes at registration - a method to assign a pet ID
- a method to assign the date of registration
- a method to return the pet name
- a method to return the owner's telephone number
So you must add both missing attributes and suitable methods, not just write random class members.
Approach
Start by turning each bullet in the question into a class-diagram item.
For the two new pieces of data:
- the pet's name should be an attribute such as
PetName : STRING - the owner's name should be an attribute such as
OwnerName : STRING
For the methods:
- the object-creation method is best shown as a constructor
- "assign" methods are setter-style methods
- "return" methods are getter-style methods and should show a return type
A sensible finished class therefore has:
- all six attributes
- one constructor
- two setter methods
- two getter methods
Step-by-Step Reasoning
First, add the two missing attributes.
The pet's name is text, so:
PetName : STRING
The owner's name is also text, so:
OwnerName : STRING
Now the methods.
- Method to create a
Petobject and set attributes at the time of registration
This is the constructor. A clear way to show it is with the class name as the method name:
Pet(PetType : STRING, PetName : STRING, OwnerName : STRING, OwnerTelephone : STRING)
This shows that when the object is created, the main registration details are supplied.
- Method to assign a pet ID
This is a setter-style method. A suitable method is:
SetPetID(NewPetID : STRING)
- Method to assign the date of registration
This is another setter-style method:
SetDateRegistered(NewDateRegistered : DATE)
- Method to return the pet name
This is a getter, so it needs a return type:
GetPetName() : STRING
- Method to return the owner's telephone number
Again, this is a getter with a return type:
GetOwnerTelephone() : STRING
Putting these into the class diagram gives a complete Pet class structure.
Equivalent method names such as AssignPetID() instead of SetPetID() are often accepted as long as the purpose is correct, but the important thing is that the method matches the task in the question.
Key Takeaways
- A class diagram shows attributes and methods for a class.
- Attributes should have suitable data types.
- A constructor is used to create an object and initialise values.
- Setter methods assign values; getter methods return values.
- Getter methods should show the return type in the diagram.
Common Mistakes
- Adding the attribute name without a data type. The question specifically asks for both.
- Using a getter where a setter is needed, or vice versa.
- Forgetting the return type on
GetPetName()orGetOwnerTelephone(). - Writing methods that do not match the task, for example a method to change pet type instead of assign pet ID.
- Omitting the constructor even though the question explicitly asks for a method to create the object.
Things to Be Careful About
- Keep the method purpose aligned exactly with the bullet points in the question.
- Use
STRINGfor names and telephone number, andDATEfor registration date. - The constructor should initialise registration information, not just appear as an empty method name.
- In a class diagram, methods that return a value should show that return type clearly.
- The exact names can vary slightly, but the role of each method must be unambiguous.
Several syntax diagrams are shown.
Complete the Backus-Naur Form (BNF) for the given syntax diagrams.
<operator> ::= ..................................................................................................
<label> ::= .........................................................................................................
<equation> ::= ..................................................................................................
Answer
<operator> ::= + | - | * | /
<label> ::= <letter><digit> | <letter><digit><digit>
<equation> ::= <label> = <label> <operator> <label>
See BNF
Background Concept
Syntax diagrams and BNF are two different ways of describing the same thing: the valid structure of strings in a language.
A syntax diagram shows:
- sequence by boxes and symbols placed one after another
- choice by a branch into different paths
- optional items by a path that can either include something or bypass it
- repetition by a loop
BNF expresses the same rules in text form:
::=means “is defined as”- angle brackets such as
<label>show a non-terminal - literal symbols such as
+or=are terminals |means “or”- items written next to each other mean they appear in sequence
So the main skill is converting from the visual structure of the diagram into the textual structure of BNF.
Understanding the Question
You are given syntax diagrams for letter, operator, digit, symbol, label and equation, but you only have to complete BNF for three of them:
<operator><label><equation>
The important inherited information from the stem is:
operatorhas four alternative symbols:+,-,*,/labelstarts with aletter, then adigit, and has an optional extradigitequationis a sequence oflabel,=,label,operator,label
So this is a direct translation exercise from diagram form into BNF form.
Approach
For each rule:
- Look for any branches. These become BNF alternatives using
|. - Read the path from left to right. That becomes the order of terms in the BNF.
- If the diagram allows two possible path lengths, write two BNF alternatives.
That last point matters for <label>. Since the diagram allows either:
letterfollowed by onedigit, orletterfollowed by twodigititems,
pure BNF should show both possibilities explicitly.
Step-by-Step Reasoning
Start with <operator>.
The diagram branches to four single-symbol choices:
+-*/
In BNF, that becomes:
<operator> ::= + | - | * | /
Now <label>.
The diagram shows:
- first a
letter - then a
digit - then either stop, or continue through one more
digit
So there are two legal forms:
<letter><digit><letter><digit><digit>
Therefore:
<label> ::= <letter><digit> | <letter><digit><digit>
Finally <equation>.
The diagram is a simple sequence:
<label>=<label><operator><label>
A sequence in BNF is written by listing the items in order:
<equation> ::= <label> = <label> <operator> <label>
That gives the three completed rules.
Key Takeaways
- A branch in a syntax diagram becomes
|in BNF. - A straight left-to-right path becomes concatenation in BNF.
- An optional part in a plain BNF answer is often written as separate alternatives.
- Literal symbols such as
=or+stay as terminals, while named structures stay inside angle brackets.
Common Mistakes
- Writing prose instead of BNF notation. The answer must use
::=and angle-bracketed non-terminals. - Forgetting one of the operator choices, for example missing
/. - Writing
<label>with only one form and ignoring the optional second digit. - Putting
<operator>in angle brackets inside its own alternatives, for example writing<+>or<->, which is wrong because these are terminals, not non-terminals. - Changing the order in
<equation>. The equals sign must come between the first two labels.
Things to Be Careful About
- Keep non-terminals exactly as named:
<operator>,<label>,<equation>,<letter>,<digit>. - Do not invent EBNF shorthand such as brackets unless the exam specifically allows it; here plain BNF is safest.
- Read the
labeldiagram carefully: it allows one digit after the letter, with one more digit optional. - Make sure terminals such as
=are written literally, not inside angle brackets.
A new syntax rule, password, is required. It must begin with a letter or a symbol, followed by a digit and end with one or two symbols.
Answer
See syntax diagram
Background Concept
A syntax diagram is a graphical way to define the legal structure of a string. Each diagram is built from a few standard ideas:
- sequence: one item must follow another
- selection: one of several paths may be chosen
- optionality: an item may be present or absent
- repetition: an item can occur more than once
In a syntax diagram:
- named boxes such as
letterorsymbolrefer to other syntax rules - literal tokens may appear directly as symbols
- a split in the line means a choice
- a rejoin means the different choices continue into the same next item
- a bypass path means the item it goes around is optional
Understanding the Question
You are asked to draw a new syntax diagram for password.
The rule is given in words:
- it must begin with a letter or a symbol
- then it must have a digit
- then it must end with one or two symbols
So the structure is:
- first item: a choice between
letterandsymbol - second item: always
digit - third item: always
symbol - fourth item: optional
symbol
That is exactly the kind of thing syntax diagrams are designed to show.
Approach
Break the sentence into diagram features:
- “letter or symbol” means branch into two paths.
- “followed by a digit” means both branches merge before a
digitbox. - “end with one or two symbols” means one mandatory
symbolbox followed by an optional secondsymbolbox.
The cleanest diagram therefore has:
- one split at the start
- one merge before
digit - one required
symbol - one optional final
symbolusing a bypass path
Step-by-Step Reasoning
Start at password.
The first phrase is “begin with a letter or a symbol”. That means the line must split into two alternatives:
- top branch through a
letterbox - bottom branch through a
symbolbox
After that choice, both possibilities have exactly the same remaining structure, so the two branches merge.
Next comes “followed by a digit”. So after the merge, place a digit box.
Now consider the ending: “end with one or two symbols”.
- “one symbol” means at least one
symbolis compulsory - “or two symbols” means there may be one extra
symbolafter that
So after the digit box, place one mandatory symbol box.
Then show another symbol box that can either be taken or bypassed.
That produces the required syntax diagram.
Key Takeaways
- Verbal grammar rules can be converted into syntax-diagram building blocks.
- “or” usually becomes a branch.
- “followed by” becomes sequence.
- “one or two” means one mandatory item plus one optional item.
- When alternative starts share the same ending, branch first and merge before the common continuation.
Common Mistakes
- Drawing
letterandsymbolin sequence instead of as alternatives. The password begins with one or the other, not both. - Making the digit optional. The question says it is followed by a digit, so it is required.
- Drawing zero, one or two ending symbols. The rule is one or two symbols, so at least one must be present.
- Putting the optionality on the first ending symbol instead of the second. That would wrongly allow passwords with no ending symbol.
- Forgetting to merge the first two branches before continuing to
digit.
Things to Be Careful About
- Use the existing rule names exactly:
letter,symbol,digit. - The first element is a choice between two non-terminals, so show a branch immediately after the start.
- The final section is not an unlimited repetition; it is exactly one required
symbolwith one more optionalsymbol. - Keep the diagram flowing clearly from left to right so the sequence is unambiguous.
Write the BNF for password.
...........................................................................................................................................
Answer
<password> ::= <letter><digit><symbol> | <symbol><digit><symbol> | <letter><digit><symbol><symbol> | <symbol><digit><symbol><symbol>
See BNF
Background Concept
BNF describes valid strings using production rules. Each rule lists all allowed forms of a non-terminal.
Important BNF ideas here are:
- choice is written with
| - sequence is written by placing items next to each other
- plain BNF does not usually use shorthand for “optional”, so optional structure is often written out as separate alternatives
That means if something can occur in two different lengths, you often need two versions of the rule.
Understanding the Question
You need the BNF for password, based on the verbal rule:
- first character group:
letterorsymbol - then a
digit - then one or two
symbolitems
So you must list every valid pattern that fits those conditions.
Approach
Handle the rule in two parts:
- Work out the two possibilities for the start:
<letter><symbol>
- Work out the two possibilities for the end:
<symbol><symbol><symbol>
Then combine them. Since there are 2 starting possibilities and 2 ending possibilities, there are 4 complete alternatives.
Step-by-Step Reasoning
Start choices:
<letter><symbol>
Middle part is fixed:
<digit>
End choices:
<symbol><symbol><symbol>
Now combine start + middle + end.
Using <letter> first gives:
<letter><digit><symbol><letter><digit><symbol><symbol>
Using <symbol> first gives:
<symbol><digit><symbol><symbol><digit><symbol><symbol>
Put the four legal forms together with |:
<password> ::= <letter><digit><symbol> | <symbol><digit><symbol> | <letter><digit><symbol><symbol> | <symbol><digit><symbol><symbol>
That is valid BNF and matches the required rule exactly.
Key Takeaways
- In BNF, optional structure is often written as multiple explicit alternatives.
- To build a rule systematically, split the grammar into choices and fixed parts.
- If there are two choices at one point and two at another, combine them carefully to get every valid form.
Common Mistakes
- Writing only two alternatives and forgetting the versions with two ending symbols.
- Allowing a password to start with both
<letter>and<symbol>in sequence instead of one or the other. - Missing the compulsory
<digit>in the middle. - Allowing zero ending symbols, which breaks the rule “end with one or two symbols”.
- Using informal notation like brackets or question marks instead of proper BNF when the question asks specifically for BNF.
Things to Be Careful About
- Keep the order exact: start choice, then
<digit>, then ending symbol(s). - Make sure there is at least one final
<symbol>in every alternative. - Use the non-terminal names exactly as given:
<letter>,<symbol>,<digit>,<password>. - Do not forget that the first item can itself be
<symbol>, so the password may contain symbols both at the start and at the end.
The following diagram shows an ordered binary tree.
A linked list of nodes is used to store the data. Each node consists of a left pointer, the data and a right pointer.
–1 is used to represent a null pointer.
Complete this linked list to represent the given binary tree.
Answer
See completed tree-linked-list diagram
Background Concept
A binary tree can be stored using linked nodes. Each node usually contains three parts:
- a pointer to the left child
- the data item
- a pointer to the right child
If a child does not exist, the pointer stores a null value. In this question, the null value is -1.
Although the question says "linked list of nodes", this is really a linked representation of a binary tree. The important idea is that each node stores links to other nodes rather than storing everything in one fixed diagram.
Understanding the Question
You are given the binary tree with:
Redas the rootGreento the left ofRedYellowto the right ofRedBlueto the left ofGreenOrangeto the right ofGreenIndigoto the left ofOrangeVioletto the left ofYellow
You must complete the node diagram so that each node's left and right pointer fields match those parent-child relationships. Any missing child must be shown as -1.
Approach
The safest method is to go node by node and ask two questions for each one:
- What is its left child?
- What is its right child?
If a child exists, draw the pointer to that node. If no child exists, write -1 in that pointer field.
Start at the root, then work down the tree.
Step-by-Step Reasoning
RootPtrmust point toRedbecauseRedis the root.Redhas left childGreenand right childYellow.Greenhas left childBlueand right childOrange.Blueis a leaf, so both pointers are-1.Orangehas a left childIndigoand no right child, so its right pointer is-1.Indigois a leaf, so both pointers are-1.Yellowhas a left childVioletand no right child, so its right pointer is-1.Violetis a leaf, so both pointers are-1.
The completed structure is:
Key Takeaways
- In a linked binary tree, each node stores pointers to its children.
- Left child goes in
LeftPtr; right child goes inRightPtr. - A missing child must be shown with the null pointer value, here
-1. - Leaf nodes always have both child pointers set to null.
Common Mistakes
- Reversing left and right children, for example putting
Yellowas the left child ofRed. - Forgetting that
Orangehas a left childIndigo. - Forgetting to put
-1in pointer fields where no child exists. - Treating
Violetas the right child ofYellowwhen the given tree shows it as the left child.
Things to Be Careful About
- Use the tree in Fig. 11.1 exactly, not assumptions from alphabetical order alone.
- Every node needs both pointer fields accounted for.
- Do not leave a missing pointer blank; the question explicitly says
-1represents null. - Keep
RootPtrpointing only to the root node, not to any other node.
A user-defined record structure is used to store the nodes of the linked list in part (a).
Complete the diagram, using your answer for part (a).
| RootPtr | Index | LeftPtr | Data | RightPtr |
|---|---|---|---|---|
| 0 | 0 | Red | ||
| 1 | Green | |||
| 2 | Yellow | |||
| 3 | Blue | |||
| 4 | Orange | |||
| 5 | Indigo | |||
| FreePtr | 6 | Violet | ||
| 7 |
Answer
RootPtr = 0
FreePtr = 7
| Index | LeftPtr | Data | RightPtr |
|---|---|---|---|
| 0 | 1 | Red | 2 |
| 1 | 3 | Green | 4 |
| 2 | 6 | Yellow | -1 |
| 3 | -1 | Blue | -1 |
| 4 | 5 | Orange | -1 |
| 5 | -1 | Indigo | -1 |
| 6 | -1 | Violet | -1 |
| 7 |
See completed table
Background Concept
When a linked binary tree is stored in a 1D array of records, the pointers are not drawn as arrows. Instead, each pointer stores the index number of another record in the array.
So:
LeftPtrstores the index of the left childRightPtrstores the index of the right child-1means there is no childRootPtrstores the index of the root nodeFreePtrstores the index of the first unused record
This is a common way to represent dynamic structures inside a fixed-size array.
Understanding the Question
The question has already assigned each data item to an index:
Redat index0Greenat index1Yellowat index2Blueat index3Orangeat index4Indigoat index5Violetat index6
You must convert the pointer relationships from part (a) into index values. You also need the special pointers:
RootPtr, which should point to the root recordFreePtr, which should point to the unused record
Approach
First, identify the root node and set RootPtr to its index.
Then, for each node:
- find its left child in the original tree
- write that child's index into
LeftPtr - find its right child in the original tree
- write that child's index into
RightPtr - if there is no child, use
-1
Finally, find the only unused index and make FreePtr point to it.
Step-by-Step Reasoning
The root is Red, and Red is stored at index 0, so:
RootPtr = 0
Now convert each node:
-
Index
0containsRed- left child is
Greenat index1 - right child is
Yellowat index2 - so record
0is1, Red, 2
- left child is
-
Index
1containsGreen- left child is
Blueat index3 - right child is
Orangeat index4 - so record
1is3, Green, 4
- left child is
-
Index
2containsYellow- left child is
Violetat index6 - no right child
- so record
2is6, Yellow, -1
- left child is
-
Index
3containsBlue- no left child and no right child
- so record
3is-1, Blue, -1
-
Index
4containsOrange- left child is
Indigoat index5 - no right child
- so record
4is5, Orange, -1
- left child is
-
Index
5containsIndigo- leaf node
- so record
5is-1, Indigo, -1
-
Index
6containsViolet- leaf node
- so record
6is-1, Violet, -1
The only unused record is index 7, so:
FreePtr = 7
Key Takeaways
- In an array-based linked structure, pointers are stored as index numbers.
RootPtrtells you where the tree begins.FreePtrtells you where the next unused record begins.-1is used for a null pointer when a child does not exist.
Common Mistakes
- Writing node names instead of index numbers in the pointer fields.
- Forgetting that
Yellowpoints left toViolet, soLeftPtrshould be6. - Putting
Indigodirectly underGreeninstead of underOrange. - Forgetting to set
FreePtrto the unused record.
Things to Be Careful About
- Use the fixed index values given in the table; do not invent a different order.
RootPtris the index of the root node, not the data value itself.- A leaf node needs both pointers set to
-1. - The unused record at index
7is not part of the tree; it is reached throughFreePtr.
The linked list in part (a) is implemented using a 1D array of records. Each record contains a left pointer, data and a right pointer.
The following pseudocode represents a function that searches for an element in the array of records BinTree. It returns the index of the record if the element is found, or it returns a null pointer if the element is not found.
Complete the pseudocode for the function.
FUNCTION SearchTree(Item : STRING) RETURNS INTEGER
NowPtr ← .........................................................................................................................
WHILE NowPtr <> -1
IF ..................................................................................................................... THEN
NowPtr ← BinTree[NowPtr].LeftPtr
ELSE
IF BinTree[NowPtr].Data < Item THEN
.........................................................................................................................
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NowPtr
ENDFUNCTION
Answer
FUNCTION SearchTree(Item : STRING) RETURNS INTEGER
NowPtr ← RootPtr
WHILE NowPtr <> -1
IF BinTree[NowPtr].Data > Item THEN
NowPtr ← BinTree[NowPtr].LeftPtr
ELSE
IF BinTree[NowPtr].Data < Item THEN
NowPtr ← BinTree[NowPtr].RightPtr
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NowPtr
ENDFUNCTION
See completed pseudocode
Background Concept
An ordered binary tree stores smaller values on one side and larger values on the other side. In this tree:
- values less than the current node are in the left subtree
- values greater than the current node are in the right subtree
That means searching is efficient because you do not need to check every node. At each step, one comparison tells you which direction to move.
In an array-of-records implementation, the algorithm keeps a pointer such as NowPtr to the current node. If the item is not found and there is no child to move to, the pointer becomes -1, which means the search has failed.
Understanding the Question
The function must search the array BinTree for a string Item.
The function should:
- begin at the root of the tree
- keep moving left or right according to alphabetical order
- return the index if the item is found
- return
-1if the item is not in the tree
The question already gives most of the pseudocode. You only need to fill the missing lines.
Approach
Use the standard binary-search-tree method:
- set the current pointer to
RootPtr - while the current pointer is not null, compare the current data with the item
- if the item is smaller, move left
- if the item is larger, move right
- if neither is true, the values are equal, so return the current index
- if the loop ends, return
-1
Because the skeleton compares BinTree[NowPtr].Data with Item, the left-move test is written as:
- current data
>item → go left
not the other way round.
Step-by-Step Reasoning
The first blank is:
NowPtr ← RootPtr
This is needed because every tree search must begin at the root.
The second blank is the test for moving left:
BinTree[NowPtr].Data > Item
Why >?
- if the current data is greater than the item being searched for, then the item, if it exists, must be in the left subtree
The third blank is the move to the right child:
NowPtr ← BinTree[NowPtr].RightPtr
That is used when:
- the current data is less than the item
- so the item, if it exists, must be in the right subtree
If neither comparison is true, the two strings are equal, so the function returns NowPtr.
If the search reaches a null pointer, NowPtr becomes -1. The loop stops and the final RETURN NowPtr returns -1, showing the item was not found.
Key Takeaways
- Ordered binary trees are searched by repeated comparison and branching.
- Always start at
RootPtr. - Smaller item means go left; larger item means go right.
- Falling off the tree to
-1means the item is absent.
Common Mistakes
- Initialising
NowPtrto a fixed value such as0instead ofRootPtr. - Reversing the comparison signs and therefore searching the wrong subtree.
- Returning
-1immediately after one failed comparison instead of continuing down the tree. - Forgetting that equality is handled by the
ELSEbefore returning the index.
Things to Be Careful About
- The pseudocode compares
BinTree[NowPtr].DatatoItem, so the direction tests must match that exact order. NowPtr <> -1is essential; without it, the code could try to accessBinTree[-1].- The function returns an index, not the data value itself.
- Keep the exact field names
LeftPtr,DataandRightPtras given in the question.









