answer.
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]
2 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]2 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
What are the pros and cons of using unique closing reserved words on compound statements?
Nata [24]

Pros: Readability. Unique closing reserved words on compound statements will enhance readability and flexibility of a language. When an endwhile or an endif in a program is written by someone else, it is vivid which block is ending. Using braces is much harder is sometimes much harder to read.

Cons: Writability. They have the disadvantage of writability and thus, complicating the language by increasing the number of keywords. Use of more of these reserved words mean less words available for the programmer.







6 0
2 years ago
Calvin is an aspiring graphic designer. He wants to achieve Adobe Certified Expert certification in software that will be helpfu
bazaltina [42]

Answer:

a

Explanation:

9 0
2 years ago
Write an expression that will cause the following code to print "I am a teenager" if the value of userAge is less than 20. Zyboo
VikaD [51]

Answer:

Replace

if userAge > 20

with

userAge > 19

Explanation:

if userAge > 20  checks if age is 21, 22, 23, 24........

The else condition which prints "I am a teenager" checks if age is 20, 19, 18....

Notice that 20 is inclusive of the else condition; this shouldn't be because for userAge to be less than 20, 20 isn't inclusive

To solve this,

Replace if userAge > 20 with userAge > 19

So that, the else

The else condition which prints "I am a teenager" checks if age is 19, 18, 17, 16....

6 0
2 years ago
An automobile battery, when connected to a car radio, provides 12.5 V to the radio. When connected to a set of headlights, it pr
ladessa [460]
Base on the question, and in my further computation, the possible answers would be the following and I hope you are satisfied with my answer and feel free to ask for more.

- If you want to determine the Thevenin equivalent voltage and resistance without overloading the battery, then apply some known resistance 

<span><span>RL</span><span>RL</span></span> and measure the output voltage as <span><span>VL</span><span>VL</span></span>. Measure the voltage without a load as <span><span>V<span>OC</span></span><span>V<span>OC</span></span></span>. The voltage divider equation tells us that

<span><span><span>VL</span>=<span>V<span>OC</span></span><span><span>RL</span><span><span>R<span>TH</span></span>×<span>RL</span></span></span></span><span><span>VL</span>=<span>V<span>OC</span></span><span><span>RL</span><span><span>R<span>TH</span></span>×<span>RL</span></span></span></span></span>

Solve for <span><span>R<span>TH</span></span><span>R<span>TH</span></span></span>, and you know that <span><span><span>V<span>TH</span></span>=<span>V<span>OC</span></span></span><span><span>V<span>TH</span></span>=<span>V<span>OC</span></span></span></span>.

6 0
2 years ago
A ___________ is an algorithm for which it is computationally infeasible to find either (a) a data object that maps to a pre-spe
Deffense [45]

Answer:

a. cryptographic hash function

Explanation:

A cryptographic hash function is a hash function that is suitable for use in cryptography. It is a mathematical algorithm that maps data of arbitrary size to a bit string of a fixed size and is a one-way function, that is, a function which is practically infeasible to invert.

7 0
2 years ago
Other questions:
  • Jamie is preparing a presentation on his laptop for his college annual event. He inserts audio and video files into the presenta
    11·2 answers
  • Peter accumulated many photos from his visit to Wisconsin. He wants to upload these photos to a social networking site. Which fi
    12·1 answer
  • Templates contain common layout and formatting that can save you time by not having to recreate documents from scratch. True or
    10·1 answer
  • Write the definition of a function printLarger, which has two int parameters and returns nothing. The function prints the larger
    15·1 answer
  • 1. Write the Python code needed to perform the following:2. Calculate state withholding tax (stateTax) at 6.5 percent3. Calculat
    9·1 answer
  • Some numbers are formed with closed paths. the digits 0, 4, 6 and 9 each have 1 closed path and 8 has 2. None of the other numbe
    6·1 answer
  • Without using any additional variables, and without changing the values of ndays or the elements of the parkingTickets array, wr
    14·1 answer
  • Write a program that reads an integer and displays, using asterisks a filled and hollow square, placed next to each other. for e
    9·1 answer
  • Look at the following array definition:
    11·1 answer
  • Connie works for a medium-sized manufacturing firm. She keeps the operating systems up-to-date, ensures that memory and disk sto
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!