What is the execution time Big-O for each of the methods in the Queue-1.java interface for the  ArrayQueue-1.java  and   CircularArrayQueue-1.java implementations?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Hello, i need help with understanding Big-O.  

What is the execution time Big-O for each of the methods in the Queue-1.java interface for the  ArrayQueue-1.java  and   CircularArrayQueue-1.java implementations?

Short Big-O reminders:

  • Big-O is a measure of the worst case performance (in this case execution time).
  • O(1) is constant time (simple assignment statements)
  • O(n) is a loop that iterates over all of the elements.
  • O(n2) is one loop nested in another loop, each of which iterates over all the elements.
  • If a method calls another method, what happens in the called method must be taken into consideration.

Queue.java

public interface Queue<E> {
    /**
      * The element enters the queue at the rear.
      */
    public void enter(E element);

    /**
      * The front element leaves the queue and is returned.
      * @throws java.util.NoSuchElementException if queue is empty.
      */
    public E leave();

    /**
      * Returns True if the queue is empty.
      */
    public boolean isEmpty();

    /**
      * Returns the front element without removing it.
      * @throws java.util.NoSuchElementException if queue is empty.
      */
    public E front();
}

ArrayQueue.java

import java.util.NoSuchElementException;
import java.util.StringJoiner;

/**
 * A queue implementation that uses an array (not circular).
 *
 * @author  (your name)
 * @version (a version number or a date)
 */

public class ArrayQueue<E> implements Queue<E> {
    private static final int DEFAULT_CAPACITY = 100;
    private static final int FRONT = 0;
    private int rear; // Index of the next available cell of the queue
    private E[] queue;

    public ArrayQueue(int initialCapacity) {
        queue = (E[]) new Object[initialCapacity];
        rear = FRONT;
    }

    public ArrayQueue() {
        this(DEFAULT_CAPACITY);
    }
    
    @Override
    public void enter(E element) {
      // Implement as part of assignment
    }

CircularArrayQueue.java

import java.util.NoSuchElementException;
import java.util.StringJoiner;

/**
 * A queue implemented using a circular buffer.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class CircularArrayQueue<E> implements Queue<E> {
  public static final int DEFAULT_CAPACITY = 100;
  private int front; // Index of the front cell of the queue
  private int rear; // Index of the next available cell of the queue
  private E[] queue; // Circular buffer

  public CircularArrayQueue(int initialCapacity) {
    queue = (E[]) new Object[initialCapacity];
    front = 0;
    rear = 0;
  }

  public CircularArrayQueue() {
    this(DEFAULT_CAPACITY);
  }
    
  @Override
  public void enter(E element) {
    // Implement as part of assignment
  }

  @Override
  public E leave() throws NoSuchElementException {
    // Implement as part of assignment
  }

  @Override
  public E front() throws NoSuchElementException {
    // Implement as part of assignment
  }
    
  @Override
  public boolean isEmpty() {
    // Implement as part of assignment
  }
    
  private boolean isFull() {
    // Implement as part of assignment
  }

  private int incrementIndex(int index) {
    return (index + 1) % queue.length;
  }
    
  private void expandCapacity() {
    // Implement as part of assignment
  }
    
  @Override
  public String toString() {
    StringJoiner result = new StringJoiner("[", ", ", "]");
    for (int i = front; i != rear; i = incrementIndex(i)) {
      result.add(queue[i].toString());
    }
    return result.toString();
  }
}

Expert Solution
Step 1

The worst-case performance of an algorithm can be evaluated by using Big-O notation based on the size of the input data. Both Array Queue and Circular Array Queue are the linear data structures that implement a queue in which the Array Queue stores the elements in a standard array whereas the Circular Array Queue stores in a circular buffer. Big-O Notation can be used to find the execution time for both Array Queue and circular Array Queue.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of Threads
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education