Solved

ADT's

Posted on 1997-06-15
1
200 Views
Last Modified: 2010-04-16
Please could anyone can help with this apparantly easy question on ADT's


The generic ADT named DIRECTORY(NI), where NI represents any ADT having a NAME operation returning a STRING. An example of NI is the ADT PERSON that has an operation called NAME which returns the name of a person as an instance of type STRING. The operations of the generic directory are as follows:-
CREATEDIR - creates an empty directory.
RETRIEVE - takes a directory and a name(i.e a string) as source and returns an item of NI as its result.
ADD - takes a directory and an item of NI and returns the directory with that item added.
ISINDIR - takes a directory and a name and returns TRUE if an item with that name is in the directory.
COUNT - takes a directory and return the number of items in that directory.

{THE QUESTION}

Using the constructive approach, write down the semantics of the RETRIEVE and COUNT operations.  Use the ADT BSTree as an underlying model.
0
Comment
Question by:dave1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
kev45 earned 50 total points
ID: 1215380
If I understand your question correctly, NI is a node on a binary tree as follows:

TYPE
  NIptr = ^NIType;
  NIType = RECORD
             Left : ^NIType;
             Right : ^NIType;
             Data : string;    {I'm assuming Turbo Pascal}
           END;
VAR
  NI : NIType;
  DIRECTORY : NIptr;

with a function name as follows:
FUNCTION NAME(N : string) : string;
BEGIN
  NAME := NI.Data;
END;

Therefore Directory's Retrieve would be as follows:

FUNCTION RETRIEVE(N : string) : NIType;
VAR
  Tmp : NIType;

BEGIN
  Tmp.Left := nil;
  Tmp.Right := nil;
  Tmp.Data := N;
  RETRIEVE := Tmp;
END;

And count would be as follows:

FUNCTION Count (D : ^NIType) : integer; {or longint if many nodes}
BEGIN
  IF (D.left = nil) AND (D.right = nil) THEN
    Count := 1
  ELSE
    IF (D.left = nil) THEN
      Count := Count(D.right) + 1
    ELSE
      IF (D.right = nil) THEN
         Count := Count(D.left) + 1
      ELSE
         Count := Count(D.left) + Count(D.right) + 1;
END;  

Kevin
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popular third-party chat platforms like Slack, Discord, and Telegram are just a few of the many new productivity applications that are being hijacked by cybercriminals to create command-and-control (C&C) communications infrastructures for their malw…
In this blog we highlight approaches to managed security as a service.  We also look into ConnectWise’s value in aiding MSPs’ security management and indicate why critical alerting is a necessary integration.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question