Métodos computacionales

Midterm Exam: What you need to know


Programming Languages and Paradigms

  1. General introduction to Programming Languages ([SCOTT] chapter 1).

    1. Language design.
    2. Classification of programming languages.
    3. Compilation and interpretation.
    4. Overview of compilation.
  2. Clojure fundamentals.

    1. Read, Evaluate, Print, Loop (REPL).
    3. Global and local bindings (def, let).
    4. Basic data types (nil, booleans, numbers, strings, characters, symbols, keywords) and their functions: +, +', -, *, *', /, <, <=, =, not=, ==, >, >=, boolean, char, char?, dec, even?, format, inc, keyword?, neg?, nil?, number?, odd?, pos?, quot, rem, str, string?, symbol?, and zero?.
    5. The quote (') special form.
    6. Logic operations: not, and, or. Short-circuit evaluation.
    7. Conditions (if, cond, case). Truthy and falsy values.
    8. Functions. Definition (defn) and application. Parameters. Multi-arity and variadic functions. Docstrings. Anonymous functions and closures. The apply, fn?, and ifn? functions.
    9. Special forms. How they differ from functions.
    10. Repetitions. Recursion and loop/recur.
    11. Functional programming. Higher-order functions.
    12. Destructuring.
  3. Clojure collections.

    1. The concept of sequence.
    2. Sequence functions: butlast, concat, cons, count, cycle, distinct, drop, drop-while, empty?, every?, filter, first, interleave, interpose, iterate, last, map, mapcat, nth, partition, partition-by, range, reduce, remove, repeat, rest, reverse, seq, seq?, some, sort, split-at, split-with, take, and take-while.
    3. Collection types (lists, vectors, maps, and sets).
    4. Lazy sequences.
    5. List functions: conj and list.
    6. Vector functions: assoc, conj, get, nth, vec, and vector.
    7. Map functions: assoc, contains?, dissoc, frequencies, get, keys, merge, vals, and zipmap.
    8. Set functions: conj, contains?, disj, get, and set.
  4. Parallel programming.

    1. Concurrency and parallelism concepts.
    2. Speedup.
    3. Hardware support for parallelism (multiprocessors, SMT, multi-cores).
    4. The pmap function.

Allowed Items During the Exam

NOTE: Once the exam starts you are not allowed to share any items with anyone else.

  1. Pen, pencil, eraser, pencil sharpener.

  2. Simple scientific calculator. You are not allowed to use a cell phone, programmable calculator, tablet, computer, or any other electronic device.

  3. Personal cheat sheet with the following characteristics:

    1. Must be one of these:

      • \(5 \times 8\) inches index card (\(12.7 \times 20.32\) cm).

      • Half letter size sheet of paper (\(13.97 \times 21.59\) cm).

    2. Must be handwritten. Computer-made cards/sheets are not allowed.

    3. You can write in both sides of the card/sheet.

    4. Must include your student ID and full name on the upper-left corner of both sides of the card/sheet.

    5. There are no restrictions on the specific content written on the card/sheet.

Sample Questions

  1. Give three examples of Clojure built-in higher-order functions.

  2. What is the result of the following Clojure expression?

    (take-while #(< % 10)
                (iterate #(+ % %) 1)))
  3. Write a Clojure function called contains-all-digits? that takes an integer argument \(n\) and returns true if \(n\) contains each of the ten digits from 0 to 9 at least once, or false otherwise.


    (contains-all-digits 1023456789)
    => true
    (contains-all-digits 1236)
    => false
  4. You are given the following Clojure code:

    (defn mystery
      ([x] (mystery x #(* 2 %) #(inc %)))
      ([a b c] (c (b a))))
    (defn wierd
      [& t]
      (let [n (count t)]
          (zero? n) 1
          :else (inc (apply wierd (rest t))))))

    What is the result of evaluating the following expressions?

    1. (mystery 5)
    2. (wierd 4 8 15 16 23 42)
    3. (mystery 2 dec inc)
    4. (mystery 10 wierd (fn [z] (* z z)))
  5. Write a function in Clojure called how-many-div-3 that receives as input a sequence of integers and returns the result of counting how many of these numbers are exactly divisible by 3. For example:

    (how-many-div-3 ())
    => 0
    (how-many-div-3 [6 2 3 12 4])
    => 3
    (how-many-div-3 '(2 5 7 11 19))
    => 0
    (how-many-div-3 [0 33 66 99])
    => 4
  6. You have a sequential program that takes 10 seconds to execute using 1 processor. The parellel version of the same program takes 2 seconds to execute using 8 processors. Calculate its speedup.