CSE 2320 - Assignments

Not Graded Practice for Assignment 3

This is a set of practice questions. Feel free to work on these questions, and to ask questions if you face any difficulties in coming up with answers. While collaboration with others on the graded homework is strictly prohibited, you are free to work on these practice questions together with other people.

Since they are practice questions, you do not have to, and should not, submit answers to these questions on Blackboard. These questions will not be considered in any way towards your course grade. At the same time, based on the instructor's experience, individuals spending substantial and systematic effort in answering these practice questions by themselves tend to significantly improve their overall class performance.


Practice Question 1

Extend files list_interface.h and list_interface.c as needed (including modifying the underlying representation of lists), so as to implement the functions specified below.

The new functions that you need to implement (with constant running time) are:

  1. void insertAtEnd(list A, link N). This function should insert link N at the end of list A.

  2. link deleteAtEnd(list A). This function should delete the link that is at the end of list A and return it to the calling function.
Requirements your solution must satisfy:


(Challenge) Practice Question 2

Extend files list_interface.h and list_interface.c so as to define a new function int hasCycleFast(list A) that takes time linear to the number of unique links in list A. The function should return 1 if the list contains a cycle (i.e., a case where a link is pointing to a preceding link), and 0 otherwise.


Practice Question 3

Write a function int countNodes(list A, link N1, link N2) that returns the number of nodes that are between N1 and N2 in list A.


Practice Question 4

(This is Problem 3.34 from the textbook).

Write a function that moves the largest item on a given list to be the final node on the list.


Practice Question 5

(This is Problem 3.35 from the textbook).

Write a function that moves the smallest item on a given list to be the first node on the list.


Practice Question 6

(This is Problem 3.36 from the textbook).

Write a function that rearranges a linked list to put the nodes in even positions after the nodes in odd positions in the list, preserving the relative order of both the evens and the odds.


Practice Question 7

(This is Problem 3.37 from the textbook).

Write a function that takes as arguments a linked list and two nodes T and U, and that exchanges the positions of the nodes AFTER the two given links T and U.


Practice Question 8

(This is Problem 3.39 from the textbook).

Write a function that takes two arguments, the first argument being a list, and the second argument being a function that takes a link as an argument. The function should remove all items on the given list for which the function returns a nonzero value.


Practice Question 9

(This is Problem 3.49 from the textbook).

Write a function void removeEvens(list A) that removes the nodes in even positions (the zeroth, second, fourth, sixth, and so forth) of list A. Remember, the first element of the list is considered to be at position 0.


Practice Question 10

(This is Problem 3.53 from the textbook).

Suppose that you have a finite set of nodes with no null pointers (each node refers to itself or to some other node in the set). Prove that you ultimately get into a cycle if you start at any given node and follow links.


(Challenge) Practice Question 11

(This is Problem 3.54 from the textbook).

Under the conditions of the previous task, write a function that, given a link to a node, finds the number of different nodes that it ultimately reaches by following links from that node, without modifying any nodes. Do not use more than a constant amount of extra memory space.


(Challenge) Practice Question 12

(This is Problem 3.55 from the textbook).

Under the conditions of the previous task, write a method that determines whether or not two given links, if followed, eventually end up on the same cycle.


Back to the list of assignments.