Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Questions 1,2,3 are full programs. Can you solve them step-by-step please? Questions 7,10,11,12,13 are multiple choice. Need only a simple explanation! Question 1. ( 6

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Questions 1,2,3 are full programs. Can you solve them step-by-step please?

Questions 7,10,11,12,13 are multiple choice. Need only a simple explanation!

Question 1. ( 6 points) This question involves the use of type Stack and Queue. Here are the class definitions for stacks and queues of integers. class 5 tack {// integer stack: Stack|): // construct empty stack void push(int k)i/( push k on the top of the stack int popll: // delete item on top of the stack \& return a copy of it int top[D: // return a copy of item on top of the stack bool isEmpty(): // true if stack is empty, otherwise false In class Queve 1// integer queve: Queue(1: // construct empty queue void insert(int k ): // insert k at the rear of the queve int removed:// delete item at front of the queue B return a copy of it. int front(): // retum a copy of item at front of the queue bool isempty(): // true if queue is empty, otherwise false l: Write a program that reads a sequence of integers from cin and writes yes on cout if that sequence of integers is a palindrome of even size and writes no if it is not. Recall that a palindrome is a sequence that is the same when read from left to right or from right to left. So, the sequence 441263362144 is a palindrome, while the sequence 441267362144 is not. Question 2. (5 marks) Give a recursive algorithm in pseudocode to compute the product of two positive integers, m and n, using only addition and subtraction. HINT: the expression XY can be also expressed as Y+Y++Y (X times). Question 3. (5 marks) Given two sorted arrays of size m and n respectively, give the program in C/C++ that finds the element that would be at the x-th position of the final sorted array. Examples Input: Array 1 : 200212356449870 Array 2: 8296213219365545992 x=7 Output: 356 Explanation: Final sorted array is: 82,96,200,212,213,219,356,365,449,545,870,992 7 th element of this array is 356. HINT: You can use parts of the mergesort algorithm. 7. What is the time complexity of the following code in terms of big O notation? inti;cinn;i=1; while (i Array[mid) then which of the followings will happen: a) The 'Right' range variable is set to 'mid' -1. b) The 'Left' range variable is set to 'mid' 1. c) The 'Right' range variable is set to 'mid' +1. d) The 'Left' range variable is set to 'mid' +1. 11. The complexity of MergeSort algorithm is (a) O(n) b) O(log n) c) O(n2) d) O(nlogn) 12. The complexity of Binary search algorithm is a) O(n) b) O(logn) (c) O(n2) d) O(nlogn) 13. Which of the following sorting algorithms in the I-th iteration of the algorithm the i-th smallest element is moved to position i? (a)) Selection Sort b) Insertion Sort c) Merge Sort d) Bubble Sort<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

What reward policy would you suggest to the university?

Answered: 1 week ago

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago

Question

2. How were various roles filled?

Answered: 1 week ago