Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 5 Write each of the following functions on linked lists in Haskell or Julia using recursion. No loops, higher - order functions, or list

Question 5
Write each of the following functions on linked lists in Haskell or Julia using recursion. No
loops, higher-order functions, or list comprehensions can be used in the implementations. For
Julia, the linked list data structure is defined as follows:
mutable struct ListNode
data
next: :Union{Nothing, ListNode}
end
LinkedList = Union{Nothing, ListNode}
harmonic(n): This function returns a list that contains the first n items in the harmonic
series: 1,12,dots,1n.
iterate_upto(f,a,n): The (iterate f a) function in Haskell generates an infinite
list, where the first item is a, the next one is calculated by applying the function f on
the previous item, and so on. The function iterate_upto (f,a,n) is similar to the
iterate function except that it only returns the first n items. For example, the function
defined below returns the first n rows of the Pascal's triangle:
draw_pascal n=
iterate_upto (1 row zipWith (+)(0:row)(row ++[0]))[1] n
gen (int n)(extra 5 points): This function returns a list of all possible n-character strings
of a's and b's that do not contain the substring aaa. The order of the strings in the list
is not important.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions