1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
barxatty [35]
3 years ago
11

Indicate the time efficiency classes of the three main operations (i.e., FindMax, DeleteMax, and Insert) of the priority queue i

mplemented as: 1. an unsorted array 2. a sorted array 3. a binary search tree 4. an AVL tree 5. a heap
Computers and Technology
1 answer:
Sholpan [36]3 years ago
5 0

Answer:

Appropriate explanation to the questions below.

Explanation:

<u>Using an Unsorted Array </u>

An unsorted array will take more time to find data hence, findMax will be slow. Time complexity is O(N). Also if we keep the array unsorted, then insert is O(1) -- ignoring the time to expand the array, but deleteMax is O(N) since we must search the whole array for the largest value.

The empty operation is trivial -- just return true if numItems == 0, so it (and the constructor) are both O(1).

<u>Using an Sorted Array </u>

The findMax operation will be faster as compared to unsorted array as either the array is sorted in descending or in ascending order the time complexity will be O(1). Also if we use an array to store the values in the priority queue, we can either store the values in sorted order (which will make the insert operation slow, and the deleteMax operation fast), or in arbitrary order (which will make the insert operation fast, and the deleteMax operation slow). Note also that we'll need a field to keep track of the number of values currently in the queue, we'll need to decide how big to make the array initially, and we'll need to expand the array if it gets full. Here's a partial class definition:

public class PriorityQueue {    

   private Comparable[] queue;

   private int numItems;

   private static final int INIT_SIZE = 10;    

   public PriorityQueue() {

       queue = new Comparable[INIT_SIZE];

numItems = 0;

   }

}

As mentioned above, if we keep the array sorted, then the insert operation is worst-case O(N) when there are N items in the queue: we can find the place for the new value efficiently using binary search, but then we'll need to move all the larger values over to the right to make room for the new value. As long as we keep the array sorted from low to high, the deleteMax is O(1) -- just decrement numItems and return the last value.

<u>Using a BST </u>

If we use a BST, then the largest value can be found in time proportional to the height of the tree by going right until we reach a node with no right child. Removing that node is also O(tree height), as is inserting a new value. If the tree stays balanced, then these operations are no worse than O(log N); however, if the tree is not balanced, insert and deleteMax can be O(N). As for the linked-list implementation, there is no need for a numItems field.

BST = In avg case it will take o(logn) worst case 0(n)

Using an AVL Tree

AVL Tree:  

  Insertion/deletion/searching: O(log n) in all cases.

But Complexity isn't everything, there are other considerations for actual performance.

For most purposes, most people don't even use an AVL tree as a balanced tree (Red-Black trees are more common as far as I've seen), let alone as a priority queue.

This is not to say that AVL trees are useless, I quite like them. But they do have a relatively expensive insert. What AVL trees are good for (beating even Red-Black trees) is doing lots and lots of lookups without modification. This is not what you need for a priority queue.

<u> </u>

<u>Using a Heap </u>

When a priority queue is implemented using a heap, the worst-case times for both insert and deleteMax are logarithmic in the number of values in the priority queue.

For the insert operation, we start by adding a value to the end of the array (constant time, assuming the array doesn't have to be expanded); then we swap values up the tree until the order property has been restored. In the worst case, we follow a path all the way from a leaf to the root (i.e., the work we do is proportional to the height of the tree). Because a heap is a balanced binary tree, the height of the tree is O(log N), where N is the number of values stored in the tree.

The deleteMax operation is similar: in the worst case, we follow a path down the tree from the root to a leaf. Again, the worst-case time is O(log N).

You might be interested in
design a relational database in EER for bike helmets and their reviews. a bike helmet has a name and color attributes. a bike co
Law Incorporation [45]

Answer:something you gotta do on your own

Explanation:

7 0
3 years ago
The code int *p; declares p to be a(n) ____ variable. new
Pavel [41]
Int* p; defines a pointer variable.
8 0
3 years ago
What two actions does the RETI instruction perf orm? Why must these two actions be done in a single instruction, as opposed to a
Bas_tet [7]

Answer:

In assembly language, two instructions control the use of the assembly language procedure.

  • CALL
  • RET

CALL pushed the control to the return address onto the stack and transferred the control.

RET instruction returns the address that placed on the stack by a call instruction.

Explanation:

Action RET instruction

  • The RET instruction pops the address and returns off the stack, which is pointed by the stack pointer.
  • The stack is LIFO in memory at a particular location, and the pointer points offset from the stack location.

RET instruction does its job by consulting the register and memory state at the point when it is executed.

In RET instruction, only register and memory state is executed. Call instruction must save that address that figure out in a register and memory location.

5 0
3 years ago
The basic difference between RAM and ROM memory is: Question 5 options: A) RAM is nonvolatile while ROM is volatile. B) RAM is r
schepotkina [342]

The basic difference between RAM and ROM memory is RAM is read/write while ROM Is read-only.

Explanation:

  • A ROM, non-volatile memory, does not use to store data, but RAM is volatile and requires power to store data.
  • ROM is not given usually as a specification, but RAM is typically specified when buying a computer.
  • We can write data only once in ROM. However, once it is written, we can read it any number of times. RAM is the main memory in a computer, and read from and write to it much faster than other storage types. RAM is used to store files in use on the computer.

Hence the basic difference between RAM and ROM memory is RAM is read/write while ROM Is read-only.

6 0
3 years ago
Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number
sineoko [7]

Answer:

// using c++ language

#include "stdafx.h";

#include <iostream>

#include<cmath>

using namespace std;

//start

int main()

{

 //Declaration of variables in the program

 double start_organisms;

 double daily_increase;

 int days;

 double updated_organisms;

 //The user enters the number of organisms as desired

 cout << "Enter the starting number of organisms: ";

 cin >> start_organisms;

 //Validating input data

 while (start_organisms < 2)

 {

     cout << "The starting number of organisms must be at least 2.\n";

     cout << "Enter the starting number of organisms: ";

     cin >> start_organisms;

 }

 //The user enters daily input, here's where we apply the 5.2% given in question

 cout << "Enter the daily population increase: ";

 cin>> daily_increase;

 //Validating the increase

 while (daily_increase < 0)

 {

     cout << "The average daily population increase must be a positive value.\n ";

     cout << "Enter the daily population increase: ";

     cin >> daily_increase;

 }

 //The user enters number of days

 cout << "Enter the number of days: ";

 cin >> days;

 //Validating the number of days

 while (days<1)

 {

     cout << "The number of days must be at least 1.\n";

     cout << "Enter the number of days: ";

     cin >> days;

 }

 

 //Final calculation and display of results based on formulas

 for (int i = 0; i < days; i++)

 {

     updated_organisms = start_organisms + (daily_increase*start_organisms);

     cout << "On day " << i + 1 << " the population size was " << round(updated_organisms)<<"."<<"\n";

     

     start_organisms = updated_organisms;

 }

 system("pause");

  return 0;

//end

}

Explanation:

6 0
2 years ago
Other questions:
  • Which of the following STEM discoverers is known for creating complex computational physics to develop computer models to simula
    7·1 answer
  • The ____ aggregate function finds the largest value
    10·1 answer
  • What type of device is the keyboard?<br><br> Output<br> Input<br> Monitoring<br> Software
    7·2 answers
  • What is a column in a table
    10·2 answers
  • What is one reason the number of DUIs has dropped?
    7·1 answer
  • By
    7·1 answer
  • Think back on the Font Tester App. Can you think of an example of another app or feature of an app which would use a loop to con
    14·1 answer
  • How is science and technology used in the society​
    11·1 answer
  • What is considered appropriate dress for men and women in the workplace? Select all that apply.
    6·2 answers
  • Write if true or false
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!