Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

advanced level school Python programming. need helps 3 A data structure is required to store 25 nodes. A linked list is maintained of all the

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

advanced level school Python programming. need helps

3 A data structure is required to store 25 nodes. A linked list is maintained of all the nodes. A node contains a data value and two pointers: a left pointer and a right pointer. Items in the list are initially linked using their Leftchild pointers. Each node is implemented as an instance of the class ConnectionNode. The class ConnectionNode has the following properties: The structure for the linked list is implemented as follows: The first available node is indicated by NextFreeChild. The initial value of Root is 1 and the initial value of NextFreeChild is 1. The diagram shows the empty data structure with the linked list to record the unused nodes. Task 3.1 Write the program code to declare the empty data structure and linked list of 25 unused nodes. Add statement(s) to initialise the empty data structure. This data structure is used to record the possible routes for a robot to travel from a node A to a node Z. The following data structure illustrates many possible routes, for example, ADKLMZ. It is only possible to move to one of two possible nodes; for example, from node A, the only move is to node B or node D. This data structure has 15 nodes ( A to N and Z ) but for future development a maximum of 25 nodes is specified. All nodes are unique. The pseudocode on the next page can be used to add a node to the data structure. The procedure AddToRobotData uses the parameters NewDataItem, ParentItem and ThisMove. The parameter ThisMove holds the move made to create this new item ('L' for LeftChild, 'R' for RightChild, ' X ' for initial state/root), and the Parent Item parameter holds the value of the parent item which points to this NewDataItem. To add node B as shown, the procedure call would be AddToRobotData ('B', 'A', 'L'). The parameters used would be: B, the new node A, the parent node I, the location of the child (which has an index of 2) is recorded in Leftchild of A. The following pseudocode (available in PSEUDOCODE_TASK_3_2.TXT) can be used to add a node the data structure. FUNCTION FindNode (NodeValue) RETURNS INTEGER Found FALSE CurrentPosition Root REPEAT IF RobotData[CurrentPosition]. DataValue = NodeValue THEN Found TRUE ELSE CurrentPosition CurrentPosition +1 ENDIF UNTIL Found = TRUE OR CurrentPosition >25 IF CurrentPosition > 25 THEN RETURN 0 ELSE RETURN CurrentPosition ENDIF ENDFUNCTION PROCEDURE AddToRobotData(NewDataItem, ParentItem, ThisMove) IF Root =1 AND NextFreeChild =1 THEN NextFreeChild RobotData[NextFreeChild].LeftChild RobotData[Root].LeftChild 0 RobotData[Root]. DataValue NewDataItem ELSE // does the parent exist? ParentPosition FindNode (ParentItem) IF ParentPosition > 0 THEN // parent exists // does the child exist? ExistingChild FindNode (NewDataItem) IF ExistingChild > 0 THEN // child exists ChildPointer ExistingChild ELSE ChildPointer NextFreeChild NextFreeChild RobotData[NextFreeChild]. LeftChild RobotData [ChildPointer]. LeftChild 0 RobotData[ChildPointer]. DataValue NewDataItem ENDIF IF ThisMove = ' L ' THEN RobotData[ParentPosition]. LeftChild ChildPointer ELSE RobotData[ParentPosition].RightChild ChildPointer ENDIF ENDIF ENDIF ENDPROCEDURE Task 3.2 Write code to implement AddToRobotData and FindNode from this pseudocode. You may use the text file PSEUDOCODE_TASK_3_2.TXT as a basis for writing your code. Task 3.3 Write a procedure OutputData which displays the value of Root, the value of NextFreechild and the contents of RobotData in index order. Task 3.4 The file SEARCHTREE. TXT contains the data for the search tree. Each row of the file contains three comma separated values, for example, the first row contains ' A ', ' O ' and ' X '. The file is organised as: NewDataItem, ParentItem, ThisMove NewDataItem, Parentitem, ThisMove There are a total of 20 lines in the SEARCHTREE. TXT file representing possible routes. Write a main program to read the contents of this file and use AddToRobotData and FindNode to insert these routes into RobotData. Your program will then call the OutputData procedure. Task 3.5 Write a recursive pre-order tree traversal that will display all valid routes from A to Z by following the routes described in RobotData

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

list the advantages of typical creditor/debtor relationships.

Answered: 1 week ago

Question

Describe the factors influencing of performance appraisal.

Answered: 1 week ago