CSE 2320 - Assignments - Assignment 3

Submit to Blackboard before the deadline. You will be able to revise your answers until the deadline with no penalty.

IMPORTANT: By submitting your answers, you are certifying that these answers have been exclusively your own work. All students enrolled in this course are expected to adhere to the UT Arlington Honor Code:

I pledge, on my honor, to uphold UT Arlington's tradition of academic integrity, a tradition that values hard work and honest effort in the pursuit of academic excellence. I promise that I will submit only work that I personally create or contribute to group collaborations, and I will appropriately reference any work from other sources. I will follow the highest standards of integrity and uphold the spirit of the Honor Code.


Task 1 (50 pts.)

Extend files list_interface.h and list_interface.c to include declarations and implementations of the following new functions:
  1. void insertAtPosition(list A, link N, int P). This function should insert link N so that, at the end of the function call, link N is at position P of list A. We use the convention that the first element of the list is at position 0.

  2. void deleteAtPosition(list A, int P). This function should delete the link that is at position P of list A. Again, we use the convention that the first element of the list is at position 0.

  3. int countOccurrences(list A, int V). This function should return the number of times value V is contained in list A.

  4. list find(list A, int V). This function returns a list of positions of all links that contain value V in list A. Again, we use the convention that the first element of the list is at position 0.

  5. void deleteOccurrences(list A, int V). This function should delete (and free) all links in list A that contain value V.

  6. list sublist(list A, int start, int end). This function returns a list that contains the values that appear in list A at positions start, start+1, ..., end.

  7. int hasCycle(list A). This function should return 1 if list A has a cycle, i.e., if any link in list A points to a preceding link in list A.


Task 2 (20 pts.)

For each function discussed in Task 1, specify the best running time (in Theta notation) that can be attained for that function, using lists as defined at list_interface.h and list_interface.c.


Task 3 (30 pts.)

Extend files list_interface.h and list_interface.c so that lists are doubly linked. Adjust all existing functions at list_interface.c as needed, to work correctly with this change. Specify in your answers.xxx document which functions you modified, and provide the modified implementatios for those functions. Also, using this new representation, implement the following two functions so that their running time is constant:
  1. int deleteLink(list A, link N). This function should delete link N from list A, and deallocate the memory used for that link.

  2. int swapLinks(list A, link N1, link N2). This function should swap the positions of links N1 and N2 in list A.


How to submit

The assignment should be submitted via Blackboard. Submit a ZIPPED directory called assignment.zip. No other forms of compression are accepted, contact the instructor or TA if you do not know how to produce .zip files. The zipped directory should contain the following documents:

As stated on the course syllabus, programs must be in C or Java, and must run on omega.uta.edu. If you want to do this in any language other than C, you have to re-implement in that language all the code that is currently implemented at list_interface.h and list_interface.c. If you want to use another language or platform, you must obtain prior approval via e-mail by the instructor.

IMPORTANT: Pay close attention to all specifications on this page, including file names and submission format. Even in cases where your answers are correct, points will be taken off liberally for non-compliance with the instructions given on this page (such as wrong file names, wrong compression format for the submitted code, and so on). The reason is that non-compliance with the instructions makes the grading process significantly (and unnecessarily) more time consuming. Contact the instructor or TA if you have any questions.


Back to the list of assignments.