Summer 2006 CMSC132 Midterm: Hashing, Networking, Sorting, Complexity, Regex, Recursion, D, Exams of Computer Science

A midterm exam for the cmsc132 course during the summer 2006 semester. The exam covers various topics including hashing, networking, sorting, algorithmic complexity, regular expressions, recursion, linear data structures, and maps/sets. The exam consists of multiple-choice and short answer questions.

Typology: Exams

Pre 2010

Uploaded on 02/13/2009

koofers-user-bx0
koofers-user-bx0 🇺🇸

9 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC132
Summer 2006
Midterm #2
First Name: _______________________
Last Name: _______________________
Student ID: _______________________
Section time ___________ TA: __________________________
I pledge on my honor that I have not given or received any unauthorized
assistance on this examination.
Your signature: _____________________________________________________________
General Rules (Read):
This exam is closed book and closed notes.
If you have a question, please raise your hand.
Total point value is 100 points.
The short answer questions are not essay questions. Strive to answer them in 1 or 2
sentences. Longer answers are not necessary and are discouraged.
WRITE NEATLY. If we cannot understand your answer, we will not grade it (i.e., 0
credit).
PUNT RULE:. For any question, you may write PUNT, and you will get ¼ of the points
for the question (rounded down). If you feel totally lost on a question, you are
encouraged to punt rather than waste time writing down a bunch of vaguely related
verbiage in hopes of getting some partial credit.
1
Grader Use Only:
#1 (12)
#2 (12)
#3 (12)
#4 (12)
#5 (10)
#6 (14)
#7 (14)
#8 (14)
Total (100)
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Summer 2006 CMSC132 Midterm: Hashing, Networking, Sorting, Complexity, Regex, Recursion, D and more Exams Computer Science in PDF only on Docsity!

CMSC

Summer 2006

Midterm

First Name: _______________________

Last Name: _______________________

Student ID: _______________________

Section time ___________ TA: __________________________

I pledge on my honor that I have not given or received any unauthorized

assistance on this examination.

Your signature: _____________________________________________________________

General Rules (Read):

 This exam is closed book and closed notes.

 If you have a question, please raise your hand.

 Total point value is 100 points.

 The short answer questions are not essay questions. Strive to answer them in 1 or 2

sentences. Longer answers are not necessary and are discouraged.

 WRITE NEATLY. If we cannot understand your answer, we will not grade it (i.e., 0

credit).

 PUNT RULE:. For any question, you may write PUNT, and you will get ¼ of the points

for the question (rounded down). If you feel totally lost on a question, you are

encouraged to punt rather than waste time writing down a bunch of vaguely related

verbiage in hopes of getting some partial credit.

Grader Use Only:

Total (100)

Problem 1 Hashing (12 pts)

  1. (2 pts) What are the properties of a good hash function? Notice we are not asking about the properties of the Java hashCode method.

c. ftp client

  1. (2 pts) What other piece of information we need in addition to the IP address in order to identify a process in a computer?
  2. (1 pt) TCP is unreliable. True/False
  3. (1 pt) UDP has low overhead. True/False.
  4. (2 pts) What is a DNS server?
  5. (2 pts) Identify the protocol, and the domain name in the following URL: ftp://www.notreally.bogus/dist/p1.pdf Protocol: Domain Name:
  6. (2 pts) Say a server has obtained a socket to communicate with a client (e.g., clientRequestSocket = serverSocket.accept()). What should the server do next in order to send and receive information from the client? You do not need to write code, just indicate what the server should do.

Problem 3 Sorting (12 pts)

  1. (2 pts) What is the proven lower bound for comparison-based sorting? Write you answer using big- O notation.
  2. (2 pts) Name two linear sorting algorithms discussed in class.
  1. (2 pts) What causes quicksort to have a cuadratic (O(n^2 )) performance? Briefly explain.
  2. (2 pts) What two sorting algorithms have an average case and worst case complexity that corresponds to O(nlog(n))?
  3. (2 pts) Name two sorting algorithms that are stable?
  4. (2 pts) What is an in-place sorting algorithm? Briefly explain

Problem 4 Algorithmic Complexity (12 pts)

  1. (2 pts) What array operation has an asymptotic complexity of O(1)?
  2. (2 pts) What is the critical section of an algorithm? Briefly explain.
  1. (3 pts) What is the output of the following code fragment? Pattern p = Pattern.compile("( .. )site( .. )"); Matcher m = p.matcher("BCsite12 done DDsiteDD"); while (m.find()) System.out.println(m.group(2));
  2. (3 pts) What is the language defined by the following Java regular expression? a+(b|c)

Problem 6 Recursion (14 pts)

The static method reverse has the following prototype: public static String reverse(int[] a) The method returns a string with the elements of the integer array in reverse order. For example, the method call reverse(new int[]{10, 20, 30}) will generate the string 30 20 10. An empty space should appear between elements. The method should return the empty string (“”) if an array of size zero is provided. Feel free to add an auxiliary method. Non-recursive solutions will receive no credit.

Problem 7 Linear Data Structures (14 pts)

The following Java class definition is for a singly linked list: public class LinkList { private Node head;// Represents the first node of the list class Node { E data; Node next; } } Define a non-static method named removeLast which removes the last element of the linked list. The prototype for the method is:

/* Complete this method / } public List getRoute(List cities) { List route = new ArrayList(); / Complete this method */ return route; } } What you must implement

  1. Complete the above constructor so an appropriate map object is created.
  2. Complete the addRoadInfo method. This method creates an entry in the map that stores the name of the road that exists between the cities represented by startCity and endCity. For simplicity you can assume there is only one road between any two cities.
  3. Complete the getRoute method. This method returns a list with the names of roads we must follow in order to visit the cities provided in the parameter. The cities should be visited in the same order they appear in the parameter. You can assume that the parameter represents a route for which there are roads connecting the specified cities. For this problem keep in mind that:
  4. The get method allows us to retrieve an element from the map and the put method allows us to insert/update an element in the map.
  5. The get method allow us to retrieve an element from an ArrayList and the remove method allow us to remove an element from an ArrayList. Both methods require an index as an argument.
  6. You don’t have to worry about import statements.