Question

A Queue is a linked list with pointers to both the head of the list as well as the tail (or the last element) of the list. Given a queue Q, Q.head gives the head of the queue and Q.tail gives the tail of the queue. Give O(1) time algorithms for the following tasks. Enqueue • Input: A queue Q of distinct integers and a queue element a not in Q. 1 • Output: Q with the element a added to the end of the list. Dequeue • Input: A queue Q of distinct integers. • Output: If the queue is not empty, the algorithm should return the first element of the queue and remove it from the queue. Otherwise, the algorithm should just return NIL.

Given an array A of real numbers, an index i is said to be a local minimum in A if A[i] is smaller than all of its neighbouring elements in A. For example, if A = (5, 7, 3, 10, 12, 2, 19, 10, 13, 4), then the indices 0, 2, 5, 7, and 9 are all the local minima in A. We want to solve the following problem: • Local minimum – Input: an array A of real numbers – Output: any one local minimum of A Give an algorithm for this problem that runs in O(log n) time.

Answer #1

1. Define the problem Closest-Pair as follows. • Input: an array
A consisting of distinct numbers. • Output: the numbers x, y in A
such that |x − y| is as small as possible. Design an O(n log n)
time algorithm for this problem
. Define the List-Delete problem as follows. • Input: A linked
list L of distinct integers and an element a of L. • Output: L with
the element a deleted. Design an O(1)-time algorithm for the...

The language is Java.
Using a singly-linked list, implement the four
queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this
assignment, enqueue() will be implemented in an unusual manner.
That is, in the version of enqueue() we will use, if the element
being processed is already in the queue then the element will not
be enqueued and the equivalent element already in the queue will be
placed at the end of the queue. Additionally, you must implement a
circular queue....

Restricted structures such as stack and queue are fast, but they
do not support access in the key field mode.
Group of answer choices
True
False
Big O analysis evaluates an algorithm based on its _________
performance.
Group of answer choices
A. average-case
B. best-case
C. worst-case
Which of the following algorithms is the fastest in speed?
Group of answer choices
A. Polynomial time algorithm
B. Linear time algorithm
C. Exponential time algorithm
The following code gives an implementation of...

You must alter the Queue class you created in L5 to make it a
CIRCULAR Queue class . Call your class Queue. it must be a template
class.
public class Queue {
}
I have put a driver program in the module . It is called
CircularQueue.java
This driver program should then run with your Queue class (no
modifications allowed to the driver program).
Your Queue class should have at least the following methods: one
or more constructors, enqueue, dequeue,...

The main goal is to implement two recursive methods, each is
built to manipulate linked data structures. To host these methods
you also have to define two utterly simplified node classes.
1.) Add a class named BinaryNode to the
project. This class supports the linked representation of binary
trees. However, for the BinaryNode class
Generic implementation not needed, the nodes will store integer
values
The standard methods will not be needed in this exercise except
the constructor
2.) Add a...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 20 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago

asked 2 hours ago

asked 3 hours ago

asked 4 hours ago

asked 4 hours ago

asked 4 hours ago