Question: (10 points) Complete the following two algorithms to insert an new value to a sorted index List and a sorted positional list of integers. You

 (10 points) Complete the following two algorithms to insert an new

(10 points) Complete the following two algorithms to insert an new value to a sorted index List and a sorted positional list of integers. You may ONLY use the following methods of Positional ADT and List ADT. You may use the foreach loop in the form of "forx in collection". You may also assume the iterator will return the element in the correct order from the first element to the last element. List ADT: Positional ADT: isEmpty, size, iterator isEmptyO, size(), iterator. positions() get(1). after position), before(position), first, last(), addi, E) addAfter(position, E), addBefore(position, E), addFirst(E) set(1,E), addLast(E) remove(1) set(position, E) remove(position,e). 1) Write code to insert data into a sorted index list A. [IMPORTANT Note: A is NOT an array, but a List type. Use the correct way to access A. For example, you can NOT access the element with index directly this: A[i], you need to call it A.get(i). See the methods for List above] Alg insert (A, x) Input: A is a min to max sorted index list of integers. x is a integer that will be added to the list. Output : x is inserted to A at the appropriate location so data is still sorted from min to max. What is the worst case time complexity of your algorithm above? (10 points) Complete the following two algorithms to insert an new value to a sorted index List and a sorted positional list of integers. You may ONLY use the following methods of Positional ADT and List ADT. You may use the foreach loop in the form of "forx in collection". You may also assume the iterator will return the element in the correct order from the first element to the last element. List ADT: Positional ADT: isEmpty, size, iterator isEmptyO, size(), iterator. positions() get(1). after position), before(position), first, last(), addi, E) addAfter(position, E), addBefore(position, E), addFirst(E) set(1,E), addLast(E) remove(1) set(position, E) remove(position,e). 1) Write code to insert data into a sorted index list A. [IMPORTANT Note: A is NOT an array, but a List type. Use the correct way to access A. For example, you can NOT access the element with index directly this: A[i], you need to call it A.get(i). See the methods for List above] Alg insert (A, x) Input: A is a min to max sorted index list of integers. x is a integer that will be added to the list. Output : x is inserted to A at the appropriate location so data is still sorted from min to max. What is the worst case time complexity of your algorithm above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!