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

Implementation of a a queue with a "circular" array or a "regular" array. (a) "circular" array:...
Implementation of a a queue with a "circular" array or a "regular" array. (a) "circular" array: consider using the smallest number of fields/variables in a struct/class. List the fields/variables that support the enqueue and dequeue operations in O(1) time in the worst case. Explain why the list is the smallest and the two operations are O(1) time. (b) "regular" array: explain the worst-case time complexity in big-O for the operations (queue size is at most n).
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...
Assume that the monthly profits of a company are given in an array, each entry representing...
Assume that the monthly profits of a company are given in an array, each entry representing the profits for the corresponding month. Propose an algorithm to find a group of consecutive months where the profit was the highest. For example, the profits, in millions, for a year Jan-Dec is given by A=[2 -5 3 4 0 -1 5 8 -9 1 -2 0]; The highest profit was from the period March-August and the value is 19 million. Assume that the...
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."""...
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...
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.
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:
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT