Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A non-circular, singly linked list Abstract Data Type has a private Node pointer, called first, which points to the first node of the list. This

image text in transcribed
image text in transcribed
A non-circular, singly linked list Abstract Data Type has a private Node pointer, called first, which points to the first node of the list. This ADT does not maintain a header pointer to the last node of the list, but it does maintain a variable size to keep track of the number of nodes in the list. Given a pointer to a node n, assume that values can be read or written to by using the field names n.val and n.next for the value and next fields of the node respectively. Assume that a garbage collector is being used, so nodes do not need to be explicitly freed. Use END for invalid or null address pointer values. (a) delete nth(int n) is a non-recursive method of the ADT that removes node number n from the list and throws an IllegalArgumentException if no such element exists or if n is less than 0. The first node is numbered 0. Fill in the missing part of the pseudocode for this function below: void delete.nth(int n) { // WRITE THE CODE THAT SHOULD BE HERE n return [10 marks] (b) Assume that this ADT has two different different methods to delete all the elements from the singly linked list as follows: void delete_all_from_start() { while (size > 0) delete-nth (0) return } void delete all from endo { while (size > 0) delete-nth (size - 1) return } Give the complexities of these two methods in big o notation and explain how you derived them. Write the pseudocode for a much simpler and more efficient method to delete all elements from the list. [10 marks] (ii) Let sart: {x Nx>0} + {y ER.y > 0} be the square root function from non-negative integers to non-negative reals, i.e. sqrt(x) = y if and only if x = y2 Is sort injective? surjective? bijective? Justify your answers. [3 marks] (iii) Let float javaSqrt(int x) be a Java implementation of this square root function (assume it throws an exception if x is negative). Discuss the differ- ences between sort and javaSqrt when considered as mathematical functions between sets. [4 marks]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

What is focal length? Explain with a diagram and give an example.

Answered: 1 week ago

Question

What is physics and how does it apply in daily life?

Answered: 1 week ago

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago