Question: The code below recursively creates a stream from an array, using concatenation. const arr = [ 1 , 2 , . . . , 1

The code below recursively creates a stream from an array, using concatenation.
const arr =[1,2,...,14]; // all numbers from 1 to 14 function concat(s1: Stream, s2: Stream): Stream { return s1.isEmpty()? s2 : snode(s1.head(),()=> concat(s1.tail(), s2)); } function arr2strm(a: T[], start: number, len: number): Stream { if (len ===1){ return snode(a[ start], sempty); } const half =(len - len %2)/2; return concat(arr2strm(a, start, half), arr2strm(a, start + half, len - half)); } const s = arr2strm(arr,0, arr.length);
How many nodes are created with snode() by this code?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!