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

Report
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
5. Following is an AVL tree (10 points) a. Show the steps of inserting 57. b. In the original tree, show the steps of deleting 76.
6. In the following B Tree of order 4. Use successor when needed.(10 points) a. Show the steps of inserting 49 b. In the original B tree, show the steps of deleting 24, followed by deleting 30.
7. In the following heap, (10 points) a. Show steps to insert 78 b. In the original heap, show the step to delete one node.
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
8. Given the following tree: (8 points) a. Which nodes have a height of 2 b. Which nodes have a depth of 2 9. Give an example of a binary tree that is full, but not complete. (6 points) 10. Given the following tree: (10 points) a. Show the post-order traversal. b. Show the pre-order traversal.