1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Pani-rosa [81]
4 years ago
13

Write a Scheme predicate function that tests for the structural equality of two given lists. Two lists are structurally equal if

they have the same list structure, although their atoms may be different.
Computers and Technology
1 answer:
rjkz [21]4 years ago
6 0

The two lists are structurally equal if they have the same list structure, although their atoms may be different. So, we are going to write a program which checks if elements in both the list at same position are atoms or not. If yes then it should return true else false.

<u>Program: </u>

(define (structurally-equal l1 l2)

(cond ( ? ; if both lists are null  #t)

( ? ; if one of the lists is null but the other is not  #f)

( ? ; if the 'car' part of both lists is an atom

(structurally-equal (cdr l1) (cdr l2)))

( ? ; if the 'car' part of one of the lists is an atom but the other is not  #f)

(else

(and (structurally-equal ? ?)     ; recur over the 'car' of each list

(structurally-equal ? ?))))) ; recur over the 'cdr' of each list

<u>Explanation:</u>

There are two ways of approaches. The first approach uses a function to generate an output that represents the list structure.

1. We could represent the structure of any list as a unique string or number, such that any lists with identical structure would have the same representation and no other list would generate the same output.

2. Write a function that analyses any list's structure and generates that output.

3. Run both lists through the function and compare the output. If the same, they have the same structure.

The second one, which is the approach Oscar has taken, is to recur through both lists at the same time. Here, you pass both lists to one function, which does this:

1. Is the first element of the first list identical (structurally) to the first element of the second? If not, return false.

2. Are these first elements lists? If so, return the result of (and (recur on the first element of both lists) (recur on the rest of both lists))

3. If not, return the result of (recur on the rest of both lists).

The second approach is more efficient in the simple circumstance where you want to compare two lists. It returns as soon as a difference is found, only having to process both lists in their entirety where both lists are, indeed, structurally identical.

You might be interested in
Withdrawal from a conflict is best used when ______.
Liono4ka [1.6K]

Answer:

Neither side can reach an agreement

Explanation:

i just took the test

6 0
3 years ago
Read 2 more answers
Norman Bates has a very unusual hobby what is it?
Allushta [10]

Answer:

<h3>Norman only likes to stuff birds, not other animals.</h3>
8 0
4 years ago
What is the use of comma and semicolon with print statement ?​
Natasha2012 [34]

Answer:

The use of a comma and semicolon with print statement tells the computer that the program or specific line is ending.

Explanation:

So for example, with a python program if you write print("Hello, World"); the semicolon tells the computer that, that command ends at the semicolon.

8 0
3 years ago
Estimate how many searches will be needed to justify time spent on presorting an array of 101 elements if sorting is done by mer
sertanlavr [38]

Answer:

Merge sort is sort, which contains the same elements in the array to maintain original positions concerning each other. Complexity of sort is O (nLogn) and runtime is O(nlogn)

Explanation:

Estimate time spent on presorting an array 101 element in merge and binary search, two schemes can be used in the first scheme if 101 items in sequential search then use the complexity of O(n). In the second scheme covert, the list into an array then sort an array with the complexity of O(n log n) and fetch the 101 elements.

Merge 101 elements; presorted sub-array n items have to compare the top times in sub-array and choose the maximum item and place it in a sorted array. Time for merging is proportional to ( k-1) n.

Suppose the processing time of the merger is c.(k-1) .n then scale factor has the same value.

The processing time of a sorting array is a recurrence equation.

T(n) = 3T (n/3) + 2 cn

Similarly this implement for array of 105 element.

5 0
4 years ago
A slideshow that accompanies an oral report is known as what?
pychu [463]
Presentation :)))))))))))))
5 0
4 years ago
Other questions:
  • Rony works on several confidential files for his company. Ignoring the privacy requirements, Rony places the files in a shared f
    7·1 answer
  • To run a PHP application that has been deployed on your own computer you can enter a URL in the address bar of your browser that
    7·1 answer
  • In 3–5 sentences, describe how technology helps business professionals to be more efficient.
    7·2 answers
  • Five batch jobs. A through E, arrive at a computer center at almost the same time. They hav e estimated running times of 10, 6,
    14·1 answer
  • Define a public class named Sample with two instance variables: an int called count and a String called name. Provide a complete
    7·1 answer
  • The Beaufort Wind Scale is used to characterize the strength of winds. The scale uses integer values and goes from a force of 0,
    10·1 answer
  • 6.Which of the following statements illustrates a characteristic of a person's attitudes
    14·2 answers
  • PLZZZZ HELP!!!
    12·2 answers
  • Problem: Write the Python code of a program called ComputeSquare that asks the user to enter the length of the side of the squar
    10·1 answer
  • What is the size of the rc.conf file in bytes
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!