Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Question
Chapter 7, Problem 25C
Program Plan Intro
1. Below mentioned variables are used:
- ArrayList-integer array List
- size- capacity of array List.
- front- Index 0 of array.
- rear-end of array.
2. Below Mentioned functions are used:
- enQueue()-toinsert the element in a circular array list
- deQueue()-to delete the rear element.
- displayQ()-display the elements of queue.
- main()-main function in program that reads the input from user anddisplays the output.
Program description:
This program is for creating a circular array list which has a constant capacity. Since this is a circular array the front and rear positions are the same. So insertion of an element or deletion if an element need not requires a loop.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In an array-based implementation of a List, why does the add operation take
O(n) time in the average case?
Select one:
a. The time it takes to shift entries over to make room in the array depends on
the number of entries in the List
b. The time to copy the current entries into a newly allocated, larger array
depends on the number of entries in the List
c. The time to access the position in the array to add the new entry depends on
the number of entries in the List
d. The time to access the position in the array to add the new entry depends on
the capacity of the array
Write and implement a recursive version of the binary search algorithm. Also, write a version of the
sequential search algorithm that can be applied to sorted lists. Add this operation to the class
orderedArrayListType for array-based lists. Moreover, write a test program to test your algorithm.
For each problem, please provide
Describe the worst-case input (the input that would cause the largest running time)
Summation used to calculate number of steps for the worst case
Explanation of how the code relates to the summation
a. (loops require discussing number of iterations and steps per iteration)
b. (recursion requires a diagram)
A O bound
i.
i.
ii.
iv.
static Integer sum(List a) {
if (a.size() == 0) {
return 0;
} else if (a.size() == 1) {
return a.get(0);
} else {
a.size()/2;
int rightLen = a.size() - leftLen;
int leftLen
List aLeft
List aRight
();
();
%3D
new
new
%D
for (int i=0; i
Chapter 7 Solutions
Data Structures and Algorithms in Java
Knowledge Booster
Similar questions
- implement QuickSort of ints that sorts the numbers in the non-decreasing order. Implement the rearrange function using QuickSort ( such that the pivot is set on the extreme left and the rearrangement is carried on on two pointers) using the O(n) time algorithmThe function gets as input an array, and index of the pivot.The function rearranges the array, and returns the index of the pivot after the rearrangement. int rearrange(int* A, int n, int pivot_index); Implement the QuickSort algorithm. - For n<=2 the algorithm just sorts the (small) array (smaller number first). - For n>=3 the algorithm uses the rearrange function with the pivot chosen to be the median of A[0], A[n/2], A[n-1]. void quick_sort(int* A, int n);arrow_forwardImplement a recursive function void deleteMax() on the IntList class (provided). The function will delete from the IntList the IntNode containing the largest value. If there are multiple nodes containing this largest value, only delete the 1st one. Be careful not to cause any memory leaks or dangling pointers. You may NOT use any kind of loop (must use recursion). You may NOT use global or static variables. You may NOT use any standard library functions. Ex: list: 5->7->1->16->4->16->3 list.deleteMax(); list: 5->7->1->4->16->3 IntList.h #ifndef __INTLIST_H__#define __INTLIST_H__ #include <ostream> using namespace std; struct IntNode {int value;IntNode *next;IntNode(int value) : value(value), next(nullptr) {}}; class IntList { private:IntNode *head; public: /* Initializes an empty list.*/IntList() : head(nullptr) {} /* Inserts a data value to the front of the list.*/void push_front(int val) {if (!head) {head = new IntNode(val);} else {IntNode…arrow_forwardplease do what is says Given a string representing an array/vector/linked-list (your choice, will use array for clarity moving forward) of integers both positive and negative, output all the negative values on the left-hand side of the array and all positive numbers on the right-hand side of the array while maintaining their relative positions. You must do this in linear time and linear space complexity or better, i.e. you cannot scan the entire list multiple times again and again to place the values in an new array. You MUST utilize methods related to QuickSort to receive credit for this problem. We will NOT accept iterative solutions. NOTE: Do NOT sort the array, the elements need to remain in their original relative order. Hint: take a look at the partition function in QuickSort. Case 1: Input 3: 1 -1 2 -2 3 -3 4 -4 5 -5 Output 3: -1 -2-3-4 -5 1 2 3 4 5 Case 2: Input 2: 14 9 -12 -13 -11 4 -4 3 3 9 Output 2: -12 -13 -11…arrow_forward
- The SparseVector class should be extended to include a method sum() that accepts a SparseVector as an argument and returns a SparseVector that represents the term-by-term total of the input and output vectors. Note: To handle the situation where an entry becomes 0, you must use delete() (and pay close mind to precision).use java to codearrow_forwardRecall the implementation for Sorted Array-Based Collection in lecture and your reading. If N represents the number of elements in a sorted array-based collection, then the size method in that collection is of 0(1). True Falsearrow_forwardWrite and test a Python function, that makes use of numpy, to return the sum of the elements onthemain diagonal (upper left to lower right) of a square matrix. In linear algebra, this value is calledthetrace of the matrix.For example, with a matrix represented as a list of lists eg. [[9, 8, 7], [6, 5, 4], [3, 2, 1]], yourfunctionshould return (9 + 5 + 1) = “15”Your Python function solution should work for any sized square matrix passed to it. Demonstratethat this is the case with 3x3, 4x4, and 6x6 matrix examples.arrow_forward
- Every time I call remove‐from‐end on a dynamic array list it takes O(1) time, except if I’m using half the space or less. In that case, it takes O(n) because it will shrink the array (by making a new smaller array and copying all the elements to the smaller space). Determine and prove the runtime of this algorithm for removal‐from‐end is O(1) amortized. [Note: you may not “prove” it by saying “this is the same as X”, use more formal proof methods.]arrow_forwardWrite a Java generic sort function, the generic sort function takes an array of objects as input and sorts them in place, You can assume that the objects e the array do implement the Comparable Interface, in other words, obj1.compareTo(obj2) returns -1,0, or 1 if objt is less than, equal or greater than obj2, respectively. You are free to pick any sorting algorithm (bubble sort, insertion, heap sort, etc.).arrow_forwardImplement a CircularArray class that supports an array-like data structure whichcan be efficiently rotated. If possible, the class should use a generic type (also called a template), and should support iteration via the standard for (Obj o : circularArray) notation.arrow_forward
- : You are given an array-like data structure Listy which lacks a sizemethod. It does, however, have an elementAt ( i) method that returns the element at index i in 0( 1) time. If i is beyond the bounds of the data structure, it returns -1. (For this reason, the data structure only supports positive integers.) Given a Listy which contains sorted, positive integers,find the index at which an element x occurs. If x occurs multiple times, you may return any index.arrow_forwardThe "dynamic array" data structure is used as the basis of Java's ArrayList library class. Describe this data structure and explain how it achieves (amortized) constant-time adding of elements, while also giving constant-time random access of elements. As part of your answer, make sure to explain what "amortized" means for the data structure.arrow_forwardImplement a CircularArray class that supports an array-like data structure whichcan be efficiently rotated. If possible, the class should use a generic type (also called a template), andshould support iteration via the standard for (Obj o : circularArray) notation.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education