CSE 2320 - Assignments - Assignment 4

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


Task 1 (10 pts.)

(This is Problem 3.56 from the textbook).

Write a function that takes a string as an argument and prints out a table giving, for each character that occurs in the string, the character and its frequency of occurrence (the number of times that the character occurs).


Task 2 (10 pts.)

(This is Problem 3.57 from the textbook).

Write a function that takes a string as an argument, and that checks whether that string is a palindrome (reads the same backward or forward), ignoring blanks. For example, your program should report success for the string "if i had a hifi".


Task 3 (15 pts.)

(This is Problem 3.60 from the textbook).

Write a function that takes in a string as an argument, and that replaces substrings of more than one blank in a given string by exactly one blank. Note that this function should modify the contents of its input argument, as opposed to returning a new string that has the required modifications.


Task 4 (15 pts.)

(This is Problem 3.74 from the textbook).

Write a function countEdges(int ** adjacencies, int A, int B, int V) that takes as input the adjacency matrix of graph, two integers specifying vertices A and B, and an integer V specifying the number of vertices in the graph. The function should return the number of vertices in the graph that serve as connectors between A and B. A vertex C is called a "connector between A and B" if and only if is an edge from A to C and from C to B. You can assume that the graph is undirected.


Task 5 (10 pts.)

Let g be a function such that g(N) = g(N-1) + N6 , and g(N) > 0 for all N >= 0. Justify your answer.


Task 6 (10 pts.)

Let g be a function such that g(N) = 4g(N/2), and g(N) > 0 for all N >= 0. Justify your answer.


Task 7 (15 pts.)

Suppose that: Given these assumptions, write a function int ** malloc2dSpecial(int max_i, int max_j) that allocates memory for such a 2D array as efficiently as possible (it allocates memory that may need to be accessed, but does not allocate any memory that will never be accessed).


Task 8 (15 pts.)

Write a function int sameNeighbors(graph g, int v1, int v2) that: In writing this function, you are not allowed to assume anything about how graphs are implemented. The only source of information about the graph for your code can come through these functions:
// Returns the list of neighbors of vertex v in graph g.
list vertexNeighbors(graph g, int v);

// Returns 1 if there is an edge between v1 and v2.
// Returns 0 otherwise.
int edgeExists(graph g, int v1, int v2);
You can assume that lists are defined as discussed in class: a list object has a variable first that points to its first node, and a link contains a variable item (of type int, NOT of type void *) and a variable next (of type link). Your code can access and modify member variables of lists and links directly.


How to submit

The assignment should be submitted via Blackboard. Submit a file called answers.xxx, that contains a PDF or Word file with your solutions for each task. Include your name and UTA ID number at the top of this document. Even though most tasks are programming tasks, it is still useful for grading to have a document where you just show the code you wrote to solve a task.

As stated on the course syllabus, programs must be in C, and must run on omega.uta.edu.

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.