Describe the structure and pseudo-code for an array-based implementation of the vector ADT that achieves O(1) time for insertions and removals at rank 0, as well as insertions and removals at the end of the vector. Your implementation should also provide for a constant-time elemAtRank method.
//C++ program
#include<iostream>
using namespace std;
class Vector{
private:
int *arr;
int size;
int start;
public:
Vector(int n){
size = n;
arr = new
int[size];
start=n;
}
void insert(int data){
if(start==-1){
cout<<"Vector full ";
return;
}
arr[--start] =
data;
}
int remove(){
if(start==size){
cout<<"vector empty\n";
}
else{
int data =
arr[start++];
return
data;
}
}
void elementAtRank(int rank){
if(rank<0||rank>=(size-start)){
cout<<"Out of bound\n";
return;
}
cout<<arr[(start+rank)];
}
void print(){
for(int
i=start;i<size;i++){
cout<<arr[i]<<" ";
}
}
};
int main(){
Vector v(5);
v.insert(1);
v.insert(2);
v.insert(3);
v.insert(4);
v.insert(5);
v.print();
v.elementAtRank(4);
}
Describe the structure and pseudo-code for an array-based implementation of the vector ADT that achieves O(1) time for i...
4. In an array-based implementation of the ADT list, what is the best case performance of the contains method? a. O(1) b. O(log n) C. O(n) d. O(nº) 5. In an array-based implementation of the ADT list, what is the worst case performance of the contains method? a. O(n) b. O(n) C. O(log n) d. 0(1) 6. In an array-based implementation of the ADT list, what is the performance of the contains method when the entry is not in the...
6. In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is full? O(1) O(n) O(n log n) O(n2) Undefined 7. In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is not full? O(1) O(n) O(n log n) O(n2) Undefined 8. The efficiency for recursively traversing a chain of linked nodes is O(1) O(n) O(n2) it cannot be proven...
In class, we discussed the priority queue (PQ) ADT implemented using min-heap. In a min-heap, the element of the heap with the smallest key is the root of the binary tree. On the other hand, a max-heap has as root the element with the biggest key, and the relationship between the keys of a node and its parent is reversed of that of a min-heap. We also discussed an array-based implementation of heaps. In this assignment, your task is to...
/* * Purpose: Test an implementation of an array-based list ADT. * To demonstrate the use of "ListArrayBased" the project driver * class will populate the list, then invoke various operations * of "ListArrayBased". */ import java.util.Scanner; public class ListDriver { /* * main * * An array based list is populated with data that is stored * in a string array. User input is retrieved from that std in. * A text based...
Create a Java code that includes all the methods from the
Lecture slides following the ADTs
LECTURE SLIDES
Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....
Complete an Array-Based implementation of the ADT List including a main method and show that the ADT List works. Draw a class diagram of the ADT List __________________________________________ public interface IntegerListInterface{ public boolean isEmpty(); //Determines whether a list is empty. //Precondition: None. //Postcondition: Returns true if the list is empty, //otherwise returns false. //Throws: None. public int size(); // Determines the length of a list. // Precondition: None. // Postcondition: Returns the number of items in this IntegerList. //Throws: None....
In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n) for(int i=n-1; i >=0; i--){ for(int k=0; k < i*n; k++){ // do something that takes O(1) time } }
In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n) int *a = new int [10]; // new is O(1) int size = 10; for (int i = 0; i < n; i ++) { if (i == size) { int newsize = 3*size/2; int *b = new int [newsize]; // new is O(1) for (int j = 0; j < size; j ++)...
I need this in Net beans and not Python. Part 1 - Pseudo-code Design and write the pseudo-code for the following Problem Statement. Problem Statement A company gives its employees an that will provide one of 3 results based on the following ranges of scores: Score Message on Report 90-100 Special Commendation 70-89 Pass Below 70 Fail Design a single If-Then-Else structure using pseudo-code which displays one of these messages based a score input by a user. Be sure your...
i
need the solution in pseudo code please.
4 Dynamic Programmii Consider the following problem based on the transformation of a sequence (or collection) of coloured disks. Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, cl. For example, the colour mapping might be: O-red, 1-yellow, 2-blue, 3-pink,. c-black For a given sequence of coloured disks eg.,0,1,2,3,4), at each time step (or iteration) you are only...