Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Quartiles are used in statistics to classify data. Per their name, they divide data into quarters. Given a set of data: [ 1 , 2
Quartiles are used in statistics to classify data.
Per their name, they divide data into quarters.
Given a set of data:
The lower quartile Q would be the value that
separates the lowest quarter of the data from
the rest of the data set. So in this instance,
Q The middle quartile also known
as the median or Q separates the lowest quarters
of the data from the rest of the data set. In
this case, Q The upper quartile Q
separates the lowest quarters of the data
from the rest of the data set. In this case, Q
The interquartile range IQR is the difference between
the third quartile and the first quartile: Q Q
In case the number of values in the list are odd
the central element is a unique element.
Example, if the list has size
The fifth element in the list will be the median.
In case the number of values in the list are even
the central element is a average of two elements.
Example, if the list has size
The average of fifth and sixth element in the
list will be the median. Q is the median of
the beginning and the element preceding median,
and Q is the median of the element succeeding
median and the end.
Another example, if the data were
Q Average of and
Q List consisting of elements: everything before median Average of and
Q List consisting of elements: everything after median Average of and
IQR
## Problem Statement
Given a sorted singly linked list without a tail
eg head return the
interquartile range of the data set using
the slow and fast pointer approach OR
using a methodology that does not iterate
over the linked list twice. You must not iterate
over the entire linked list more than once and you
cannot use arrays, vectors, lists or an STL
implementation of List ADT in this problem.
If you prohibit the above requirements, you will
incur a penalty on your score.
The following Node class is already defined
for you and we have already implemented the
insert and main function:
c
class Node
public:
int value;
Node next nullptr;
;
Node insertEndNode head, int key
Node temp new Node;
tempvalue key;
ifhead nullptr
head temp;
else
Node curr head;
whilecurrnext nullptr
curr currnext;
currnext temp;
return head;
float interQuartileNode head
Enter here
### Restriction:
For this problem, we ask that you use properties of lists rather than using another container,
for example you cannot move all of the elements into a vector and then find the IQR of the vector.
Additionally, you should not count the elements of the list and use this count
to determine the locations of Q and Q in the list eg count and count
Instead, you should use the properties of linked lists and list traversal ideas we've brought up
in classdiscussion to solve this problem.
Hint: Think about how you can adapt the slowfast pointer technique to solve this problem
RE
Some examples of acceptable code structures would be
using one loop with any number of conditionals outside the loop,
or using a divide and conquer approach.
Note: When using fastslow pointer to find a median,
you may use the size of the list to see if it's even or odd,
as this determines how you will find the median.
If you are counting the nodes in the list to use it in this capacity,
it is acceptable for this problem.
Any other use of a count for this problem is not allowed.
### Sample Input:
c
### Sample Output:
c
### Explanation:
Input is a set of numbers inserted into a
Linked List separated by spaces.
The head of this linked list is passed into the
interQuartile function.
Output is the Interquartile Range of the list,
a floating point value. IQR QQ
We are rounding returned values to two decimal
places in main using setprecision
Note you are expected to return a floating point
value.
### Constraints
The list can contain any integers.
The list will have at least values.
The list is sorted.
CAN ONLY USE LOOPS ONCE
CAN ONLY ITERATE THE LINKED LIST ONCE
PLEASE READ THROUGH THE RESTRICTIONS AND CONSTRAINTS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started