Question

In: Computer Science

1) Given an array queue implementation with one unused entry and frontIndex and backIndex references, match...

1) Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5:

a.) frontIndex is 0 and backIndex is 4

b.) frontIndex is 1 and backIndex is 4

c.) frontIndex is 3 and backIndex is 0

empty queue

one element in the queue

three elements in the queue

four elements in the queue

five elements in the queue

six elements in the queue

invalid

Please Help!

Solutions

Expert Solution

a) four elements in the queue

As we know, we can only add an element in the back and remove an element from the front in the queue. So, according to this option, the back index is in 4th position means the user entered 4 elements in the queue i.e. in {0,1,2,3} positions and the front index is still in 0th index means the user didn't remove any element yet. The user still didn't use the 4th index. So, the queue contains 4 elements in it.

b) three elements in the queue

As we know, we can only add an element in the back and remove an element from the front in the queue. So, according to this option, the back index is in 4th position means the user entered 4 elements in the queue i.e. in {0,1,2,3} positions and the front index is in 1st index means the user removed 1 element from index 0. The user still didn't use the 4th index. So, the queue contains 3 elements in it.

c) Invalid

As we know, we can only add an element in the back and remove an element from the front in the queue. If it is a Circular Queue, then there is a possibility that the back index came before the front index but In Normal Queue, back index never came before front index. So, this option is Invalid.


Related Solutions

Using the implementation of the array based list given, write a CLIENT method (that is NOT...
Using the implementation of the array based list given, write a CLIENT method (that is NOT part of the class) called replace, that given a value and a position replaces the value of the element at that position. REMEMBER error checking public static void replace( List aList, int newValue, int position) public class ArraybasedList implements MyListInterface{ private static final int DEFAULTSIZE = 25; // Data members: private int currentSize; private int maxSize; private S[] elements; //default constructor has NO parameters...
public class Assignment3 { public static Queue> makeQueue(double[] a){ // Each element of the given array...
public class Assignment3 { public static Queue> makeQueue(double[] a){ // Each element of the given array a must be inserted into a BTNode, // this method returns a queue of BTNodes, each node will contain a dataNode // the dataNode will have the value equal to the element of the array // count equal to the number of times that the element repeats // min and max must be equal to value. // the BTNode created must have its parent,...
Please make an Array-based implementation of a Binary Tree in Python based on the given file...
Please make an Array-based implementation of a Binary Tree in Python based on the given file below. Make sure to keep the Abstract Data File of the starter code below when building the Array-based implementation. Python Starter Code Given Below: class ArrayBinaryTree(BinaryTree): """Linked representation of a binary tree structure.""" # -------------------------- nested _Node class -------------------------- class _Node: def __init__(self, element, parent=None, left=None, right=None): # -------------------------- nested Position class -------------------------- class Position(BinaryTree.Position): """An abstraction representing the location of a single element."""...
Make an Array implementation of a binary tree given the below class ArrayBinaryTree(BinaryTree): """Linked representation of...
Make an Array implementation of a binary tree given the below class ArrayBinaryTree(BinaryTree): """Linked representation of a binary tree structure.""" # -------------------------- nested _Node class -------------------------- class _Node: def __init__(self, element, parent=None, left=None, right=None): # -------------------------- nested Position class -------------------------- class Position(BinaryTree.Position): """An abstraction representing the location of a single element.""" def __init__(self, container, node): def element(self): def __eq__(self, other): # ------------------------------- utility methods ------------------------------- def _validate(self, p): """Return associated node, if position is valid.""" def _make_position(self, node): """Return Position...
1. Match each transaction with the type of entry that will be required at April 30,...
1. Match each transaction with the type of entry that will be required at April 30, the company's year-end. A. Deferral Adjusting entry B. Accrual Adjusting entry The company has $8,300 in Prepaid Rent at the beginning of April and uses $3,600 of that for its April rent. The company provides lawn care in April for customers who will be billed and make payment in May. The company owes interest on loans for the month of April and will not...
Propose an algorithm in C to match numbers / tokens (words) from one array to another...
Propose an algorithm in C to match numbers / tokens (words) from one array to another array and pull out the matching numbers.
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that...
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that reverses the whole queue. In your driver file (main.cpp), create an integer queue, push some values in it, call the reverse function to reverse the queue and then print the queue.
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array...
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time. Return that integer. Input: arr = [1,2,2,6,6,6,6,7,10] Output:
//   Given an array of size 9, with the values of 1-9, determine if the array...
//   Given an array of size 9, with the values of 1-9, determine if the array //   is valid or not. //   Display a message stating the row is VALId, or state its INVALID and what //   was the index number that determined the data invalid. // //   Use this java code as a start of your code. //   Test the array data by changing the values. //============================================================================= import java.util.*;    public class Soduko_ValidateRow    { public static void main(String...
1. Adapt the custom array list implementation code with the following changes: (a) Add code to...
1. Adapt the custom array list implementation code with the following changes: (a) Add code to the ensureCapacity() method to print out a message including how many elements are copied to the new array on resizing Array List Implementation: public class MyArrayList<E> implements MyList<E> { public static final int INITIAL_CAPACITY = 16; private E[] data = (E[])new Object[INITIAL_CAPACITY]; private int size = 0; // Number of elements in the list public MyArrayList() { }    public MyArrayList(E[] objects) { for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT