Question: You must complete the implementation of UltraFast by correctly coding all eight operations and optimizing their efficiency. For UltraFast, the running time for get (
You must complete the implementation of UltraFast by correctly coding all eight operations and
optimizing their efficiency. For UltraFast, the running time for getiand maxmust be Oand
for pushxpopsetixdoubleTopswapTopand ksumkrunning time must not
exceed Olog n below is the code for UltraSlow.java : package compa;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
public class UltraSlow implements UltraStack
List ds;
public UltraSlow
ds new ArrayList;
public void pushint x
dsaddx;
public Integer pop
ifdssize
return null;
return dsremovedssize;
public Integer getint i
ifi i dssize
return null;
return dsgeti;
public Integer setint i int x
ifi i dssize
return null;
return dsseti x;
public void doubleTop
if size
dsadddsgetdssize;
public void swapTop
if size
Integer temp dsgetdssize;
dssetdssize dsgetdssize;
dssetdssize temp;
public Integer max
Integer m null;
for int x : ds
if m null x m
m x;
return m;
public long ksumint k
long sum ;
forint i; i iterator
return dsiterator;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
