2. A binary tree is either empty or it is composed of a root element and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2. A binary tree is either empty or it is composed of a root element and two children, which are binary trees themselves. In Prolog we can represent an empty tree by the constant 'nil' and represent a non-empty tree by a list [X,L,R], where X denotes the value in the root node and Land R denote the left subtree and right subtree, respectively, e.g., [a,[b,[d,nil,nil],[e,nil,nil]],[c,nil,[f,[g,nil,nil],nil]]] (2a) Draw the binary tree corresponding to the list above. (2b) Write a Prolog program istree(L) that determines if L is a binary tree. 2. A binary tree is either empty or it is composed of a root element and two children, which are binary trees themselves. In Prolog we can represent an empty tree by the constant 'nil' and represent a non-empty tree by a list [X,L,R], where X denotes the value in the root node and Land R denote the left subtree and right subtree, respectively, e.g., [a,[b,[d,nil,nil],[e,nil,nil]],[c,nil,[f,[g,nil,nil],nil]]] (2a) Draw the binary tree corresponding to the list above. (2b) Write a Prolog program istree(L) that determines if L is a binary tree.
Expert Answer:
Answer rating: 100% (QA)
a The binary tree corresponding to the list ab dnilnil enilnilcnil fgnilnilnil can be drawn as follo... View the full answer
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
1.) The molar mass of CaCl2 is 110.98 g. By how many degrees would the freezing point decrease in a solution of 0.420 kg of water containing 12.98 g of CaCl2? The Kf of water is 1.86C/m, and the van...
-
Use the following information for Questions 1 a) and 1 b): a) At the beginning of the year, Juju Sdn. Bhd. estimated the following: Polishing Department Overhead Direct labour hours Kiln hours Firing...
-
What are the differences between Technical Advice Memoranda (TAMs) and Technical Expedited Advice Memoranda (TEAMs)?
-
A financial institution plans to offer a derivative that pays off a dollar amount equal to S2T at time T where ST is the stock price at time T. Assume no dividends. Defining other variables as...
-
Verify that the Tweedie distribution is a member of the linear exponential family of distributions by checking equation (13.9). In particular, provide an expression for \(S(y, \phi)\) (note that...
-
Two mutually exclusive alternatives are being considered. One of the alternatives must be selected. Using a 15% nominal interest rate compounded continuously, determine which one. Solve by annual...
-
Jane Corp. had a net profit margin of 6% last year and an equity multiplier of 4.0. If its total assets are $250 million, what is the firm's return on equity? b). Excerpts of The Tree Ltd.'s...
-
Journalize all these transactions into a general ledger. Transactions May 1 Purchased merchandise from Keys Wholesale on account for $735.30, Invoice No 91 Dated May 1, terms 2/10, n30 May 2...
-
II. CASE (40%) [LO 3, 40 points] Patients arriving in an emergency unit of a hospital are queued based on their arrival. They are then checked by nurses and the nurses have the right to move the...
-
On a chilly 10C day, you quickly take a deep breathall your lungs can hold, 4.0 L. The air warms to your body temperature of 37C. If the air starts at a pressure of 1.0 atm, and you hold the volume...
-
When the hoof of a galloping horse hits the ground, the digital flexor tendon in its lower leg may stretch by 5% in length, a significant stretch for this 45 cm tendon. The tendon is elastic; mostbut...
-
A 500 kg horse can provide a steady output power of 750 W (that is, 1 horsepower) when pulling a load. How about a 38 kg sled dog? Data show that a 38 kg dog can pull a sled that requires a pulling...
-
When people exercise, they report feeling exhaustion when their body temperature rises to 39.7C. A 68 kg man is running at 15 km/h on a hot, muggy dayso hot and muggy that he cant lose any heat to...
-
If you slide down a rope, its possible to create enough thermal energy to burn your hands or your legs where they grip the rope. Suppose a 40 kg child slides down a rope at a playground, descending...
-
17.25 Figure P17.25 shows the load components acting on a helical gear mounted on a sim- ply supported shaft. Bearing B takes thrust. A flexible coupling for transmitting torque attaches to the right...
-
The Ranch 888 Noodle Company sells two types of dried noodles:ramen, at $6.50 per box, and chow fun, at $7.70 per box. So farthis year, the company has sold a total of 110,096 boxes ofnoodles,...
-
Write a program that produces the following output using nested for loops. Use a class constant to make it possible to change the number of stairs in the figure. ******* /* ****** ****** / * ****** /*
-
For the next four problems, consider the task of representing types of tickets to campus events. Each ticket has a unique number and a price. There are three types of tickets: walk-up tickets,...
-
Write a method called plusScores that accepts a Scanner representing an input file containing a series of lines that represent student records. Each student record takes up two lines of input. The...
-
Family Supermarkets (FS) has decided to increase the size of its Memphis store. It wants information about the profitability of individual product lines: soft drinks, fresh produce, and packaged...
-
How do managers refine a costing system?
-
When does product undercosting or overcosting occur?
Study smarter with the SolutionInn App