Question: Question 5 ( 2 marks ) A . What are the worst - case and best - case running times of the following algorithm? B
Question marks
A What are the worstcase and bestcase running times of the following algorithm?
B Count the number of primitive operations line by line. Show your work.
for i; in; i
time
if ai
forj;j Question marks
Assume a binary tree with integer values in the nodes. In this problem, you will design a lineartime algorithm that finds out existence of a path with given sum. In other words, given a sum, you need find a path from the root to any of the nodes that adds up to the given sum.
A Describe your algorithm in pseudocode.
B Analyze its worstcase running time.
Question marks
Describe a memoryefficient solution to implement four queues in a single array. In other words, all four queues should use the same array for storing elements. The standard enqueue and dequeue methods should be updated to take an extra parameter to identify the queue. For example, the enqueue n element method should add an element to queue number n where n is an integer between and Similarly, the dequeue n method deletes an element from queue number n where n is from to
Question marks
Given a stack of integers, write a pseudocode to check whether each successive pair of numbers in the stack is consecutive or not. The pair can be increasing or decreasing, and if the stack has an odd number of elements, then the element at the top is left out of a pair. For example, if the stack of elements is then the output should be true because each of the pairs and consist of consecutive numbers. Your solution should ensure that the stack is restored to its original state when the algorithm is done.
Note
You should use a queue as an auxiliary data structure.
Question marks
A Does the tree in the following figure have the heap property?
B Show stepbystep process for deleting the max element from the heap.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
