2023 JPJC P1 Solutions
Uploaded by Kozak327 · 8 September 2026
Preview
Text from the first pages2023 JPJC Prelim Paper 1 Suggested Soluon 1 1a OOP Robot x: INTEGER y: INTEGER #1m Constructor(x: INTEGER, y: INTEGER ) moveLeft(dist: INTEGER) moveForward(dist: INTEGER) moveBackward(dist: INTEGER) moveDown(dist: INTEGER) #1m getX():INTEGER getY():INTEGER display() Drone z: INTEGER #1m Constructor(x: INTEGER, y: INTEGER, z: INTEGER ) moveUp(dist: INTEGER) moveDown(dist: INTEGER) #1m getZ():INTEGER display() #1m Each mistake (repeated/missing attributes or methods, missing arrow) minus 1 m 6m 1b i. Encapsulation Encapsulation is used to hide the values/attributes of an object inside a class, preventing unauthorized parties’ direct access to them. Publicly accessible methods are provided in the class to access the values. [1m] Example, attributes x, y, z are private, getX, getY, getZ are publicly accessible [1m] ii. Inheritance In inheritance, the child class inherits the attributes and methods from the parent class. [1m] Examples of inheritance, x and y attributes, moveLeft, moveRight, etc… methods. [1m] iii. Polymorphic Polymorphism in python means methods in the child class that have the same name as the methods in the parent class. The method in the child class overwrites/modifies the code that it has inherited from the parent class. [1m] Display method is polymorphic. [1m] 6m #1
2023 JPJC Prelim Paper 1 Suggested Soluon 2 2 a) Role and Purpose of a Primary Key i. A primary key is a unique identifier for each record in a table. [1] It helps enforce entity integrity, ensuring that there are no duplicate records in the table. [1] In the context of the "GreenHarvest" scenario, the primary key ensures that each farmer or crop has a unique identifier (farmerID or cropID), preventing data duplication. ii. A foreign key is a field in one table that establishes a link between the data in two tables. [1] Its role is to maintain referential integrity, ensuring that data in one table corresponds to data in another table. [1] In the "GreenHarvest" scenario, foreign keys in the HarvestRecord table link each harvest to a specific farmer and crop (farmerID and cropID), ensuring that each harvest record relates to a valid farmer and crop in their respective tables. b) In the context of "GreenHarvest," data redundancy refers to the repetition of the same data within the database. [1] For example, having to store the same crop's details for each harvest record can be redundant. [1] Data inconsistency, within the context of "GreenHarvest," refers to conflicting or contradictory data values within the database (i.e.: the same piece of information is stored differently in various places). [1] For instance, if the farmer’s name is stored differently in different harvest records, it can create inconsistencies. [1] c) In the context of "GreenHarvest," unresolved data redundancy can result in update anomalies. For instance, if information about crops, such as planting dates, is stored redundantly across multiple records in the Crop table. [1] Suppose you need to update the planting date of "Crop A" because it was initially recorded incorrectly. If this information is redundantly stored in multiple harvest records, you must update it in all related records. Failure to do so can lead to inconsistencies, where some records show the corrected date while others display the incorrect one. [1]
2023 JPJC Prelim Paper 1 Suggested Soluon 3 d) Table Descriptions: Farmer (farmerID, FirstName, LastName, ContactNumber) Crop (cropID, CropName, CropType, PlantingDate) HarvestRecord (farmerID*, cropID*, HarvestDate) [3] Farmer with additional 2 attributes and primary key [3] Crop with additional 2 attributes and primary key [3] HarvestRecord with composite and foreign key e) ER diagram (4 marks instead of 6 marks) [1] Three tables [1] correct sequence [1] relationship between farmer and harvestrecord [1] relationship between harvestrecord and crop 3a Binary Tree Answer: (i) D B E A F C G (ii) X is In-order traversal 2 1 b Answer: FUNCTION Count(CurrPtr) RETURNS INTEGER IF CurrPtr = -1 # base case RETURN 0 ELSE RETURN 1 + Count(BT(CurrPtr).LeftPtr) + Count(BT(CurrPtr).RightPtr) ENDIF ENDFUNCTION 1 1 2 1 Farmer HarvestRecord Crop
2023 JPJC Prelim Paper 1 Suggested Soluon 4 4a 4b 4c When n = 1, Fib(n-2) would be Fib(-1) [1] which causes infinite recursion leading to memory stack overflow. [1] Add the following base case to the pseudocode: [1] IF n = 1 THEN RETURN 1 ENDIF Test case Data RETURN Purpose 1 n = 0 0 Test base case 1 2 n = 1 1 Test base case 2 3 n = 2 1 Test general case 7 marks instead of 5 marks Step 1: Return n if n is less than or equal to 1. Step 2: Declare temp, termA and termB. Assign 0 to temp, termA and 1 to termB. Step 3: Add termA to termB and assign the sum to temp. Step 4: Assign termB to termA and temp to termB. Step 5: Subtract 1 from n. Step 6: Repeat from step 4 if n is larger than 0. Otherwise return termA. Steps 1 to 5 – 1 mark each Step 6 – 2 marks
2023 JPJC Prelim Paper 1 Suggested Soluon 5 5 a,b) 4 marks from the diagram 4 marks for labelling function calls for mergesort 0 m - merge no need to label 5c For bubble sort, the time complexity of a mostly sorted array is close to that of a pre-sorted array, which is O(n) due to the use of a boolean flag to check and terminate the sort when no swap was done in a pass. For merge sort, the time complexity is O(n log2n) for pre-sorted array, as well as for best, average and worst case. It is fixed Thus, bubble sort is faster for mostly sorted array. 1 1
2023 JPJC Prelim Paper 1 Suggested Soluon 6 6a Network + Security (a) Reason for layering (Any two advantages): - Simplifies the network model; Enables programmers to specialize in a particular layer of the model; - Provides design modularity; Allows for standardized interfaces to be produced by networking vendors 1. Easy Debugging It is very simple to debug because the layers are discrete. Example if an error happens in the application layer, the developer may only debug that layer. 2. Modularity This design supports modularity because each layer only executes tasks it is responsible to perform. 3. Abstraction Each layer is concerned with its own set of functions. As a result, the functions and implementations of the other layer are abstract to it. 4. Easy update A modification in one layer does not affect the other layers. 6b (b) Transport Layer: The Transport layer is responsible for providing reliable data transfer between applications. It has two protocols: 1. Transmission Control Protocol (TCP) [1] - is a connection-oriented protocol that establishes a reliable connection between two devices before transferring data. It ensures that all the data is received in the correct order and without errors. [1] - Useful for online transaction, emails. [1]
2023 JPJC Prelim Paper 1 Suggested Soluon 7 6b 2. User Datagram Protocol (UDP) [1] - on the other hand, is a connectionless protocol that does not provide error checking or guaranteed delivery. [1] - Useful for real-time services like live-conference or online games [1] Any one of the above. 6c The router uses its NAT table to map the arriving packet’s destination public IP address and port with the private IP address and port of the device in the LAN, and send the packet to the device. 2 6di - JPNet users’ computers could be infected with Malware sent through email. These infected computers form a botnet. - When the attacker launches an attack, these botnets will work simultaneously to send large amount of network tr
Content continues in the PDF. Download PDF
Related notes
- 2024 ACJC Computing PromoExam Papers · 2024
- 2023 ACJC Promo QPExam Papers · 2023
- 2022 ACJC Computing Promo Paper 2Exam Papers · 2022
- 2021 ACJC Computing Promo Paper 2Exam Papers · 2021
- 1992 AJC Computing QPExam Papers · 1992
- 2023 YIJC P2 Question PaperExam Papers · 2023
- 2023 YIJC P1 Question PaperExam Papers · 2023
- 2023 RVHS P2 CombinedExam Papers · 2023
- 2023 RI P2 Question PaperExam Papers · 2023
- 2023 RI P1 Question PaperExam Papers · 2023
- 2023 NYJC-VJC-TJC P2 Question PaperExam Papers · 2023
- 2023 NJC P2 Question PaperExam Papers · 2023
- See all H2 Computing notes

