CSci 1901: 5th Homework
Due: Thursday, May 3 No late homeworks

The homework is to be done individually as a practice for the final exam. You can do it manually and/or using the computer. Hand in your answers (both the code and the result of running it) at the beginning of your lab. For test data, use the examples included with each problem and add some when none are given.
  1. (20 points)
    Write a procedure insert-at! that destructively inserts a given element into a list in a specified position. Assume that the positions are numbered from 0, and that the position specified is always 0 or positive. If the position is greater than the length of the list the procedure should return the list itself. It should work like this:
     
    STk> (insert-at! 'k 3 '(b c m n))  
    (b c m k n)
    STk> (insert-at! 'a 0 '(b c d e))  
    (a b c d e)
    STk> (insert-at! 'a 7 '(b c d e))  
    (b c d e)
    
  2. (10 points)
    Repeat the previous question in Python.
  3. (25 points)
    Write a procedure (bonus! table key-list) to give a bonus of 100 points to the values of the keys that are included in the list key-list. Assume table is a table, as defined in the textbook.
    The procedure should work like this: suppose you are given a table frequent-flyers containing names of people and their frequent flyer miles. The keys in frequent-flyers are symbols representing names, the values are miles. Suppose you are also given the list names of names of people who should receive a bonus of 100 miles. (bonus! frequent-flyer names) should increase by 100 the values of the miles in the table frequent-flyers for the people who appear in names. Nothing should be done for people listed in names but not in frequent-flyers. You have to use the selectors and mutators from the textbook to access the entries in the table.
  4. (20 points) Repeat the previous question in Python using dictionaries.
  5. (25 points)
    Use dictionaries in Python to write a procedure which takes in a string and returns a list of pairs so that each character in the string is paired with its frequency in the string.
    >>> str2fqy('tables are dictionaries')
    {'a': 3, ' ': 2, 'c': 1, 'b': 1, 'e': 3, 'd': 1, 'i': 3, 'l': 1, 'o': 1,
    'n': 1, 's': 2, 'r': 2, 't': 2}
    
Copyright: © 2000-2007 by the Regents of the University of Minnesota
Department of Computer Science and Engineering. All rights reserved.
Comments to: Maria Gini
Changes and corrections are in red.