1. Given the unsorted array write the pseudo code so sort it and find a specific element x a. Find (array, x) //first sort the array //search for element x using binary search
Q: Write a program to implement Heap sort. Also implement one of the slow sorts (Bubble, Insertion...).…
A: Program:- #include <iostream>using namespace std; void max_heapify(int a[], int i, int n)…
Q: Decide whether the following sentences are True or False? 1) Operations on the Fibonacci algorithm…
A: As per our guidelines we are supposed to answer only three suparts kindly repost other parts as a…
Q: Now consider implementing a stack as a class that relies on a vector, keeping track of the current…
A: Stacks using Vectors : Vectors are same as unique clusters with the capacity to resize itself…
Q: Question3. Using the Stack class implemented in JAVA, write a JAVA code to do the following: a.…
A: Algorithm: Step1: Receive the array input from user. Step2: Create a stack. Step3: Push values of…
Q: s is an initially empty circular array-based STACK of size 8, where top has a value of -1 at…
A: 1. -1 2. "P" 3. -1 4. -1
Q: Figure Q2(a) shows a series of operations for a stack, s1. Determine the content of s1 using an…
A:
Q: Write an algorithm for implementation of both stack and queue operations using array
A: Insert queue operations using array.if ((FRONTQ == 0) and (REARQ == N - 1)) // Condition for…
Q: Write a Python program to mpletment stack uperations after crenting a stack with at leist 20…
A: Note: we are only allowed to solve one question in one post. I am solving the first on here. To get…
Q: (e) Suppose you are implementing a list of stacks. Let's say you decide to implement both the…
A: Stack is an abstract data type which is used to store the elemenets with a bounded capacity. It is a…
Q: Assume you are using a array-based queue and have just instantiated a queue of capacity 10. You…
A: option A is correct i.e., 0
Q: (1) implement the following functions of a Queue using an integer array: • queue_init(): Make the…
A: Objective: This program would create a queue with methods, queue_init() empty() enqueue(val)…
Q: 1 4 Using an array of size 5, we want to implement a queue using circular arrays. What will be the…
A: What will be the contents of the array after executing below operations? enqueue(1) -> 1 is…
Q: Problem 2 Assume you implement a Queue using a circular array of size 4. Show the content of the…
A: Now first understand what is circular array . The circular array is something into which after the…
Q: 2. Consider a priority queue which can hold arrays of different lengths. In this queue enqueue…
A: It is defined as a script, which contains a set of commands exactly as you would type them at the…
Q: Stack manipulation: a) The following operations are performed on a stack: PUSH A, PUSH B, POP, PUSH…
A: ANSWER:-
Q: 1. Write a program which should implement a stack using static array of size 10 (10 elements array),…
A: Let's understand step by step : Static array : Static array is an array where its size is…
Q: 2. Given the following stack A = { 29,18,10,15,20,9,5,13,2,4,15} Create a queue by taking the…
A: The Queue by taking the elements from the top of the stack and adding them is: - Queue Q =…
Q: TAIL-RECURSIVE-QUICKSORT(A, p,r) 1 while p ) pivot.
A: Below we saw the stack operation done:
Q: 2 of 5 Assume a circular array-based implementation of the Queue, if Q=[7, 8, 3, 6] front =3,…
A: Assume a circular array-based implementation of the Queue, if Q=[7, 8, 3, 6] front =3, capacity =4,…
Q: 1. Suppose you have an array arr includs the following integer element (15, 1, 6, 12, -3, 4, 8, 21,…
A: Since no language is specified in the problem, this problem is solved using Java. It is the stack…
Q: 2. Consider your ID as an array of 9 elements. Example ID: 201710340. You have to use your own ID.…
A: Hey there I am writing the required solution for the above-mentioned question. Please do find the…
Q: Stack is Abstract Data Type. Change the following Infix expression to Postfix expression and…
A: Actually, c++ is a powerful general purpose language.
Q: 0 1 2 3 456 7 30 20 15 16 13 10 12 2 What will the contents of this array look like after one…
A: Given a sequence of numbers and it has to sorted using heap sort. The output will be sorted array…
Q: The pointer start points to the first element of a singly-linked list L. Write a recursive algorithm…
A: The, answer has given below:
Q: d element without removing it. • int Size(): Returns the number of elements stored in the stack. •…
A: given - Write a program to implement a Stack using array. In order to implement the stack,…
Q: Rewrite the procedure DFS (depth first search), using a stack to eliminate recursion
A: To search a graph or tree data structures, the Depth-first search (DFS) algorithm can be used. DFS…
Q: 1. Write a program to create a stack data structure (do not use the built-in stack class) using…
A: Solution: Given,
Q: Let S1 and S2 be two stacks. 1. It is possible to keep two stacks in a single array, if one grows…
A: Create a data structure twoStacks that represents two stacks. Implementation of twoStacks should use…
Q: Q4: Consider a stack of size 5. Consider the senesce of operations performed on the stack. Push…
A: The algorithm to perform the push operation is shown below. void push(int item){ if(top ==…
Q: Stack stores elements in an ordered list and allows insertions and deletions at one end. The…
A: Code in step 2:
Q: Towers of Hanoi. There is a story about Buddhist monks who are playing this puzzle with 64 stone…
A: Tower of Hanoi is implemented below using C++ with well defined comments. Kindly check it out.…
Q: id stack::do(){ for(int i=0li<=topindex/2;i++){ T temp=entry[i]; entry[i]=entry[topindex-i-1];…
A: Correct answer is Option(a) Reverses the stack Explanation: First, we start from i=0 to…
Q: Question #7. SORTED LIST NOT UNSORTED C++ The specifications for the Sorted List ADT state that the…
A: The, code has given below:
Q: Using C++ The specifications for the Sorted List ADT state that the item to be deleted is in the…
A: The, code has given below:
Q: 3. Complete the following table that shows a series of stack operations and their effects on…
A: 3) Comple the following table that shows the stack operation 4) Coding to define the enqueue and…
Q: public ArrayList depthFirstTraversal(int[][] adjacency_matrix, int source) { //A matrix and a source…
A: Complete answer is given below .
Q: to be the top element of the stack. E.g. given the stack elements (from bottom to top): 90, 70, 80,…
A: Please find the code below:
Q: N.b array size to be used is ten. a)enqueue() i.e enqueue the list; Two,three,four,five,six,seven…
A: as per guidelines If the questions asked are interlinked, answer first 3 subparts #include…
Q: The pointer start points to the first element of a singly-linked list L. Write a recursive algorithm…
A: The algorithm for this will be straightforward , keep callign the method replace by pasing the next…
Q: Q#1: The algorithm Enqueue may fails even though there is memory space available. One way to avoid…
A: Hi there, Please find your solution below, I hope you would find my solution useful and helpful. Can…
Q: Design a function bool validateStackSequences(const std::vector& v) that takes an int vector with…
A: Function:- A function is defined as a group of statements that can perform a specific task.
Q: Problem 2 (Stacks): Consider the fundamental theorem of arithmetic, which is stated as follows:…
A: 1. First declare a variable - iterate=2 and input a variable - number (to find its prime factors.)…
Q: B) Write a recursive function to find summation of the first n positive numbers (for example, if n=5…
A: #include <stdio.h>int SummationNum(int n);int main() { int num; printf("Enter an…
Q: A. 0 1 2 3 4 5 6 7 2 20 15 16 13 10 12 30 0 B. 1 2 3 4 5 6 7 20 15 16 13 10 12 2 C. 0 1 23 4 5 20 16…
A: Given a sequence of numbers, sort them using heap sort. After sorting one element and rebuilding the…
Q: Consider the following code segment , The variable q is an object of type Queue, the variable s is…
A: Solution: Given, for (int i = 30; i <= 40; i ++) { if(i % 3 == 0)…
Q: PROGRAM: Your program should apply linked lists and have the following variables and functions. . An…
A: Solution - Programming language - C All solution steps are included in in program code as comments.…
Q: Create a class mystack using vector to store integers in a stack. Add the following methods - ADD()…
A: Important concept related to the question: Stack: Stacks are a form of container adapter that works…
Q: Stack is Abstract Data Type. Change the following Infix expression to Postfix expression and…
A: Actually, Stack is Abstract Data Type.
Q: Stack s- new Stack(); s. push(10); s. push(20); s.push(30); s.push(40); // Stack created with…
A: I give the code in java as per your requirement along with code and output screenshot
1. Given the unsorted array write the pseudo code so sort it and find a specific element x
a. Find (array, x)
//first sort the array
//search for element x using binary search
2. Given the following stack A = { 29,18,10,15,20,9,5,13,2,4,15}
Create a queue by taking the elements from the top of the stack and adding them to a queue
3. what are the worst-case, average-case, and best-case complexities of insertion-sort, merge-sort, and quiksort
4. Given the following array A = {3,13,89,34,21,44,99,56,9}
Illustrate the execution of the sorting algorithms on the given array:
* Merge-sort
* Quicksort (using the median-of-three pivot) algorithms
* Selection Sort algorithm
For each fundamental iteration or recursion of the algorithm, write the content of the array.
5. Evaluate the following postfix expression made using a stack: 234*5*-
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
- Stack stores elements in an ordered list and allows insertions and deletions at one end. The elements in this stack are stored in an array. If the array is full, the bottom item is dropped from the stack. In practice, this would be equivalent to overwriting that entry in the array. And if top method is called then it should return the element that was entered recently.Please develop well-documented pseudo code that finds all consecutive similar elements of a given array (of any size n) by using either a stack or a queue. The code must display the start indices where the values start to repeat, as well as the values of these elements. For instance, given the following array A: (22, 9, 61,61, 61, 21, 0, 9, 9, 9, 9, 35, 81,81, 9, 5, 5), the code should find and display something similar to the following (pls notice that this is just an example. The solution must not refer to this particular example): Value 61 is repeated 3 times starting at Index 2 Value 9 is repeated 4 times starting at Index 7Value 81 is repeated 2 times starting at Index 12Value 5 is repeated 2 times starting at Index 15 a) Briefly justify the motive(s) behind your design. b) What is the Big-O time complexity of your solution? Explain clearly how you obtained such complexity. c) What is the Big-Ω time complexity of your solution? Explain clearly how you obtained such complexity. d)…//21.3 * 3.1 / ( 14 + (6+2.1)^3) } //TODO public void convertToPostFix() { //create a stack of operators. //create Vector postFix //Go through inFix from 0 to size-1 //if current element is operand add it to postFix //if operator then as long as top of stack is operator of higher or equal //precedence pop it from stack and add it to postFix //push operator to stack //if open parenthesis push it to stack //if close parenthesis as long as top of stack is not open parenthesis, pop from //stack and add it to postFix. //pop the open parenthesis from stack (don't add it to postfix) //empty stack into postFix. } //TODO public double evaluate() { double result; return result; } private boolean isDigit(char c) { if(c >= '0'…
- Stack, Queue and Deque5.1. Understand the basic operations for Stack, Queue and DequeExample: Suppose that Queue q is implemented by a circular array data with the size 3. Please drawthe state of the Queue q and circular array data after each of the following steps.1) Queue q = new Queue();2) q.enqueue(5);3) q.enqueue (2);4) q.enqueue (9);Towers of Hanoi. There is a story about Buddhist monks who are playing this puzzle with 64 stone disks. The story claims that when the monks finish moving the disks from one post to a second via the third post, time will end. Eschatology (concerns about the end of time) and theology will be left to those better qualified; our interest is limited to the recur- sive solution to the problem. A stack of n disks of decreasing size is placed on one of three posts. The task is to move the disks one at a time from the first post to the second. To do this, any disk can be moved from any post to any other post, subject to the rule that you can never place a larger disk over a smaller disk. The (spare) third post is provided to make the solution possible. Your task is using c++ write a recursive function that describes instructions for a solution to this problem. We don’t have graphics available, so you should output a sequence of instructions that will solve the problem. Hint: If you could…Stacks are an important data structure in their own right and they may be implemented in several ways. Implement a stack as an array and i. Write functions to perform the following operations on it. With each operation explain the time complexity associated with it when performeda. Push() b. pop() c. size() d. peek()ii. Briefly explain any two problems when stacks are implemented as an array.
- C++Create 1 million integers randomly and store them in an array. Find the 100 smallest integers and print them. Use a Priority Queue implemented by Heap using array, and print the execution time too.void stack::do(){ for(int i=0li<=topindex/2;i++){ T temp=entry[i]; entry[i]=entry[topindex-i-1]; entry[topindex-1-i]=temp;} } Assume the stack is array based. What is this method do? a. swap the first item with last item b. doesn't do any thing c. replace each item with next item value d. reverse the stackpublic ArrayList<Integer> depthFirstTraversal(int[][] adjacency_matrix, int source){//A matrix and a source index is passed in//The traversal will be performed on this matrix and begin from the source index //Stack is created//This stack will be used to process nodes in LIFO order when an unvisited node is foundStack<Integer> stack = new Stack<>();int numNodes = adjacency_matrix.length; //boolean array is created//This array will have a slot for each node//Whenever an unvisited node is visited it's slot in this array will be markedboolean[] visited = new boolean[numNodes]; //This variable will hold the index of the element currently being analyzedint element; //The result of the traversal will be stored in this arraylistArrayList<Integer> traversal = new ArrayList<Integer>(); //Since the source index is passed in it has already been visitedvisited[source] = true; //The source index is added to the queue to continue processing itstack.push(source); while…
- Write a program to sort a stack such that the smallest items are on the top. You can use an additional temporary stack, but you may not copy the elements into any other data structure (such as an array). The stack supports the following operations: push, pop, peek, and is Empty.Write a program to sort a stack such that the smallest items are on the top. You can usean additional temporary stack, but you may not copy the elements into any other data structure(such as an array). The stack supports the following operations: push, pop, peek, and is EmptyTrue or False For each statement below, indicate whether you think it is True or False. provide a description of your answer for partial credit in case you are incorrect. 1) Given a stack implemented as an array, and the following functions performed: Push(A), Push (B), Push(C), Pop(), Push(D), Push(E), Pop(), Push(F) a. The array will be [A][B][D][F] and the “top” of the stack will be at index 3 where [F] is b. The next element that will be removed when Pop is called will be A c. If we Push(G), [G] will be inserted at index 0