CS5343 - Mid Term - Spring 2021

.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

7

Uploaded by MasterRhinoceros3614

CS5343 Algorithms and Data Structures Midterm Exam – Apr 1, 2021 First Name:______RAGAVALLI_________________ Last Name:_____OMMI____________________________ Student #:___2021513479_____________________ 1. The node of a list is: Node { Int val; Node *next; Node *prev; } Node *head; Node *tail; (10 points) Write an algorithm to delete a Node n in the list. Node n could be the head or the tail node or a node between head and tail. The list may contain only one node, so after deletion it will be empty. Head and tail are global variables. Do not use any other static or global variables. Do not add any arguments to the function, except the ones already given. deleteNode( Node *n ) { }
2. Write an Append() Algorithm that takes two single-linked lists, 'a' and 'b', appends 'b' onto the end of 'a'. You are given the head pointer of each list. (15 points) Class Node { Int data; Node *next }; Main() { Append(heada, headb) { } Append( tmp1, tmp2 ) { }
3. Given a binary tree. Some internal nodes of the tree have two children and some internal nodes have only one child. Write an algorithm that will count the number of nodes that have exactly two children. No global variables and no new arguments to the function.(15 points) Node { Int val; Node *lchild; Node *rchild; }; Main() { Int n = count(root); } Int count(tmp) { } 4. Answer the following: (6 points) a. What is the big O of bubble sort b. Give an example of sequence of numbers where bubble sort has better Big O than selection sort.
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