CS61C Fall 2014 Lab 0 - Introductions



You need to have an EECS instructional account (cs61c-** or cs61c-***) in order to do your lab work. Most importantly, you will need to log in to this account in order to enroll in the class. Exercise 0 below will guide you through setting up your account.

Policies Overview: Partners

All labs and projects this semester will be done with partners. For labs, this will reduce the number of check-offs we have to perform (so we can spend more time answering questions), and also it gives you someone to discuss class material with. We will cover course/lab policies in more depth later.


Exercise 0: Account Setup

Once your TA gives out account forms, both you and your partner should do the following:

  1. Log into your account using the details on the form. You should be prompted to enter some personal information (name, SID) so that we can accurately assign grades at the end of the semester.
  2. If you were not prompted to enter your information in the last step, run register in Terminal.
  3. Finally, you should change your password. In Terminal, enter ssh update.cs.berkeley.edu and follow the prompts.
  4. Now you're ready to start the lab!

Exercise 1: Self-Assessment

Note: As an exception to lab exercises, this is a solo exercise.

The prerequisite material for this class is "CS 61B or solid experience with a C-based programming language," which in reality is Java, as that is the language for our 2nd project. We have found that in the past students who lack the necessary experience often 1) overestimate their proficiency and 2) find themselves unable to keep up with the course. The following two problems are designed to check that you are ready for the material in CS 61C.

Please write your solution by hand in Java. It is important that the code you write is syntactically correct and free of errors. While we expect that the problems can be solved by students with necessary experience (perhaps with a bit of brushing-up on Java), solving them correctly does not mean you will automatically do well in the class!

Ex 1.1: Fibonacci

Write a function that, when given a number n, returns the n-th Fibonacci number. The function signature is given to you below:

// Returns the n-th fibonacci number. You may assume that n >= 0.
public static int fibonacci(int n) {


Background: The Fibonacci numbers are defined by the following relationship:

Fib0 = 0
Fib1 = 1
Fibn = Fibn-1 + Fibn-2           Where Fibn is the n-th Fibonacci number. 

The list of the first 10 fibonacci numbers are given below:
  Fib0 = 0
  Fib1 = 1
  Fib2 = 1
  Fib3 = 2
  Fib4 = 3
  Fib5 = 5
  Fib6 = 8
  Fib7 = 13
  Fib8 = 21
  Fib9 = 34

Ex 1.2: Zipper

Write a function that when given two arrays, each sorted smallest-to-largest, returns a new array that contains all elements from both input arrays sorted in smallest-to-largest order. For example, if the input arrays are as follows:

Array Input 1 = { 1, 4, 7, 8, 8 , 9}
Array Input 2 = { 2, 4, 6, 8}

The output should be an array containing items in the following order:

Array Output = { 1, 2, 4, 4, 6, 7, 8, 8, 8, 9 }

The function signature is given below:

// you may assume first and second are not null
public static int[] zipper(int[] first, int[] second) {

When you are done with both exercises, please wait quietly until your TA gives you further instructions.