CS5343 Dec 7, 2021 - Set 1

.docx

School

University of Texas, Dallas *

*We aren’t endorsed by this school

Course

5343

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

10

Uploaded by MasterRhinoceros3614

Report
CS5343 Algorithms and Data Structures Exam-2 Dec 7, 2021 Please write using PEN First Name:__________________________ Last Name: ______________________________ Student #:________________________ 1. (10 points) You are given a single linked list. The list has at least 3 nodes. The number of nodes in the list is odd. Write a recursive algorithm to find the middle node. You can only traverse the list once, so you cannot count the number of nodes in the list. Your function can have up to 2 arguments (not more). You cannot use global variables or static variables. Also do not modify the list structure. You may write the main function start the recursive function. Then write the recursive function. The list is defined as follows: Node { Int val; Node *next; } Main() { Mid( ………………………. ); Mid( tmp1, tmp2 ) {
2. (10 points) Binary tree node is defined as follows: Node { Int Val; Node *rchild; Node *lchild; } You are given a binary tree. Write a recursive algorithm that would return the mirror image of the tree. Do not use any more arguments or global variables. Mirror (root1, root2 ) {
3. (10 points) In a directed graph, give the algorithm to determine if the graph is strongly connected or weakly connected. 4. The following is a red-black tree. (10 points) a. Delete the node 17 and then 18. Show the steps and the final tree after deletions.
b. In the following tree insert 22 and then 24. Show the steps and the final tree after insert
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help