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,...
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...
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.
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...
//   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...
1. Given an array of integers a dimension n. If the array contains the same number...
1. Given an array of integers a dimension n. If the array contains the same number of even and odd elements get (a1 + an) (a2 + an-1) ... 2. Given an array of integers dimension n. All array elements with even numbers preceding the first element to the maximum, multiplied by the maximum. 3. Given an array of dimension n. Insert after each zero element of the element in the middle (or the amount of secondary elements for even...
C++ Program 1–Implement a Priority Queue(PQ) using an UNSORTED LIST. Use an array size of 10...
C++ Program 1–Implement a Priority Queue(PQ) using an UNSORTED LIST. Use an array size of 10 elements. Use a circular array: Next index after last index is 0. Add the new node to next available index in the array. When you add an element, add 1 to index (hit max index, go to index 0). Test if array in full before you add. When you remove an element, from the list, move the following elements to the left to fill...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT