Seow Alex

@seowalex

Joined on Aug 18, 2020

  • Data Abstractions Question 1 Draw box-and-pointer for the values of the following expressions. Also give box and list notation. list(list(1, 2, list(3)), list(4, 5), pair(6, 7)); pair(1, list(2, 3, pair(4, null))); pair(1, pair(2, list(3, list(4, 5))));
     Like  Bookmark
  • Streams II Question 1 Describe the streams A and B produced by the following definitions. Assume that integers is the stream of positive integers (starting from 1): function scale_stream(c, stream) { return stream_map(x => c * x, stream); } const A = pair(1, () => scale_stream(2, A));
     Like  Bookmark
  • Searching and Sorting II; Memoization Question 2 The following function, bubblesort_array, is an implementation of the Bubble Sort algorithm to sort an array of numbers into ascending order. function bubblesort_array(A) { const len = array_length(A); for (let i = len - 1; i >= 1; i = i - 1) { for (let j = 0; j < i; j = j + 1) { if (A[j] > A[j + 1]) {
     Like  Bookmark
  • Problem Solving and List Processing Question 1 Write the function map using accumulate. Name your function my_map. function my_map(f, xs) { return accumulate((x, y) => pair(f(x), y) , null, xs); } Question 2 Write a function called remove_duplicates that takes in a list as its only argument and returns a list with duplicate elements removed. The order of the elements in the returned list does not matter. Use filter in your function.
     Like  Bookmark
  • Tree Recursion The following pattern of numbers is called Pascal's triangle. $$ 1 \ 1 \qquad 1 \ 1 \qquad 2 \qquad 1 \ 1 \qquad 3 \qquad 3 \qquad 1 \ 1 \qquad 4 \qquad 6 \qquad 4 \qquad 1 $$
     Like  Bookmark
  • Recursion; Iterative and Recursive Processes Question 1 Consider the following Source program: function f1(rune_1, n, rune_2) { return n === 0 ? rune_2 : f1(rune_1, n - 1, beside(rune_1, stack(blank, rune_2))); }
     Like  Bookmark
  • Source Academy Burger Joint Suppose we're designing a point-of-sale and order-tracking system for a new burger joint. It is a small joint and it only sells 4 options for combos: Classic Single Combo (hamburger with one patty), Classic Double With Cheese Combo (2 patties), and Classic Triple with Cheese Combo (3 patties), Avant-Garde Quadruple with Guacamole Combo (4 patties). We shall encode these combos as 1, 2, 3, and 4 respectively. Each meal can be biggie-sized to acquire a larger box of fries and drink. A biggie-sized combo is represented by 5, 6, 7, and 8 respectively, for combos 1, 2, 3, and 4 respectively. Question 1 Write a function named biggie_size which when given a regular combo returns a biggie-sized version. function biggie_size(combo) { return combo + 4; }
     Like  Bookmark