Data Structures and Algorithms (NTU, Class 01/02, Spring 2011) instructor: Hsuan-Tien Lin
Homework #2
TA in charge: Polone Chen RELEASE DATE: 03/16/2011 DUE DATE: 03/29/2011, 17:20
As directed below, you need to submit your code to the designated place on the course website.
Any form of cheating, lying or plagiarism will not be tolerated. Students can get zero scores and/or get negative scores and/or fail the class and/or be kicked out of school and/or receive other punishments for those kinds of misconducts.
Discussions on course materials and homework solutions are encouraged. But you should write the final solutions alone and understand them fully. Books, notes, and Internet resources can be consulted, but not copied from.
Since everyone needs to write the final solutions alone, there is absolutely no need to lend your homework solutions and/or source codes to your classmates at any time. In order to maximize the level of fairness in this class, lending and borrowing homework solutions are both regarded as dishonest behaviors and will be punished according to the honesty policy.
Both English and Traditional Chinese are allowed for writing any part of your homework (if the compiler recognizes Traditional Chinese, of course). We do not accept any other languages. As for coding, either C or C++ or a mixture of them is allowed.
This homework set comes with 200 points and 10 bonus points. In general, every home- work set of ours would come with a full credit of 200 points.
2.1 Asymptotic Complexity
In this problem, you can use any theorems in the textbook and any theorems on the class slides as the foundation of your proof. You cannot use any other theorems unless you prove them first.
(1) (10%) Do Exercise 1(b) on page 41 of the textbook (Subsec. 1.5.3).
(2) (10%) Do Exercise 1(f) on page 41 of the textbook (Subsec. 1.5.3).
(3) (10%) Do Exercise 2(c) on page 41 of the textbook (Subsec. 1.5.3).
(4) (10%) Do Exercise 2(e) on page 41 of the textbook (Subsec. 1.5.3).
2.2 Structure
(1) (10%) Do Exercise 3 on page 64 of the textbook (Sec. 2.3) for only triangle and circle.
2.3 Sparse Matrix
(1) (10%) Do Exercise 6(a) on page 84 of the textbook (Sec. 2.5).
(2) (10%) Use either C or any pseudo-code to do Exercise 6(b) on page 84 of the textbook (Sec.
2.5).
(3) (10%) Do Exercise 6(c) on page 84 of the textbook (Sec. 2.5) for add.
(4) (10%) Do Exercise 6(c) on page 84 of the textbook (Sec. 2.5) for transpose.
(5) (Bonus 10%) Use either C or any pseudo-code to do Exercise 5 on page 84 of the textbook (Sec. 2.5).
1 of 2
Data Structures and Algorithms (NTU, Class 01/02, Spring 2011) instructor: Hsuan-Tien Lin
2.4 Special Matrix
(1) (10%) Do Additional Exercise 6(a) on page 100 of the textbook (Sec. 2.9).
(2) (10%) Do Additional Exercise 6(b) on page 100 of the textbook (Sec. 2.9).
(3) (10%) Do Additional Exercise 6(c) on page 100 of the textbook (Sec. 2.9).
2.5 Sparse Matrix Processing
In this problem, we ask you to process a very big sparse matrix: a Netflix-like data set as introduced in class. In the data set, you will be given tuples of the form (m, u, rmu), where m is the index of a movie, u is an index for the users and rmu∈ {1, 2, 3, 4, 5} is the rank (i.e. number of stars) that user u rates movie m.
(1) (15%) Design a data structure for storing the data set provided by the TAs. The data structure should support the following actions: retrieve(m, u), which returns rmu; users(m, n), which returns all users (as indices stored in a dynamically-allocated array) who have rated both movies m and n;
movies(u, v), which returns all movies (as indices stored in a dynamically-allocated array) that have been rated by both users u and v. Describe your design of the internal objects and the actions.
(2) (15%) Show the time complexity of retrieve, users, movies of your design. (Note: the faster the better!)
(3) (10%) Show the time complexity for converting from the data set provided to your data structure.
(Note: the faster the better!)
(4) (10%) Calculate the exact number of bytes that your data structure consumes (space complexity) when using the data set provided. (Note: the smaller the better!)
(5) (30%) Implement the data structure you designed and write a demo program to show how your data structure performs the three desired actions. Then, briefly (≤ 20 lines) state how you test whether your implementation is correct.
Please submit the code (data structure and demo program) as a file hw2 5.c or hw2 5.cpp as discussed below.
Submission File
Please submit your written part of the homework on all problems together before the deadline in the Tuesday class (03/29/2011) or to the TA at CSIE R217. Also, you need to upload your coding part as a single ZIP compressed file to CEIBA. The zip file should be like b86506054.zip, where the file name should be changed to your own school ID. The ZIP file should contain the following items:
• hw2 5.c or hw2 5.cpp
• an optional README, anything you want the TAs to read before grading your code
The TAs will use the Makefile provided on the course website to test your code. Please make sure that your code can be compiled with the Makefile on CSIE R217 linux machines.
2 of 2