Answered step by step
Verified Expert Solution
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
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 (iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started