How to assess runtime of recursive algorithms

Assignment Help Data Structure & Algorithms
Reference no: EM13934179

Data structures Assignment

1 Union of sorted data collections

1.1 Union of sorted arrays

Let A and B be sorted arrays with all elements of A distinct and all elements of B distinct (though elements can occur in both A and B). Design an O(n) algorithm that produces a sorted array C containing all elements of A and B without repetitions. For instance, if A = [1; 2; 5; 7] and B = [2; 5; 10], C = [1; 2; 5; 7; 10].

1.2 Union of sorted linked lists

Solve the same exercise for the case where A and B are linked lists.

2 Intersection of sorted data collections

2.1 Intersection of sorted arrays

With A and B as in exercise 1, design an O(n) algorithm that produces a sorted array containing those elements that occur in both A and B. In the example as above C = [2; 5]

2.2 Intersection of linked lists

Solve the same exercise for the case where A and B are linked lists.

3 Reversing a linked list

In this exercise you are asked to design an algorithm that reverses a linked list. This algorithm takes as input a linked list and returns a linked list where the elements are in the reverse order. For example, if the linked list given as input is (10; 9; 23; 47; 15) then the resulting linked list should be (15; 47; 23; 9; 10).

3.1 Reversing a linked list using a stack

Reverse a linked list using the following approach:


- Traverse the list from the beginning to the end and push each element onto a stack that is initially empty.

- Remove (pop) the elements from the stack one by one and insert them into a new linked list so that each new element is inserted as the last one.

3.2 Reversing a linked list using constant memory

The previous task uses O(n) additional memory (the stack plus extra list). Reverse a linked list in O(n) time using only a constant amount of additional memory. That is, you are not allowed any additional data collections (e.g. arrays, lists, stacks, queues) and can only have several single variables.

Hint: consider moving along the list and reversing the pointers. That is, if the current pointer is from a to b (a:next = b), change it into b:next = a. Make sure that the pointer to the new rst element is correctly set.

4 Recursive algorithms for nding a speci ed pair of elements in an array

In this task, you are asked to design algorithms that use recursion instead of loops. That is, you are not allowed to use for or while loops and have to use the recursion instead.

4.1 Unsorted array: nd two elements di ering by 20

Design a recursive algorithm that checks whether the given array contains two elements whose di erence is 20.

4.2 Sorted array: nd two equal elements in linear time

Design a recursive O(n) algorithm that checks whether the given sorted array contains two equal elements. Remark. In this module we do not systematically learn how to assess runtime of recursive algorithms. One easy way to justify correctness of this particular algorithm is to design rst a non-recursive algorithm and then to transform it into recursive form.

4.3 Sorted array: nd two elements di ering by 20

Design a recursive O(n) algorithm that checks whether the given sorted array contains two elements whose di erence is 20. The remark for the previous exercise applies.

Reference no: EM13934179

Questions Cloud

Companies that sell groceries over the internet : Feasibility Study: Companies that sell groceries over the Internet are called e-grocers. Customers enter their orders, pay by credit card and receive delivery by truck. To determine whether an e-grocery would be profitable in one large city, a pot..
What do you think the outcome should have been : What do you think the outcome should have been for the Phoenix Four?
Determine the required pressure on the diameter piston : Determine the force in hydraulic cylinder AB for the position shown if the tree weighs 6000 lb. Determine the required pressure on the 4.72-in. diameter piston of the cylinder.
Explain the general purpose of the firewall : Explain the general purpose of the firewall above. Your explanation should include a description of the networks the gateway machine is connected to and how it is connected
How to assess runtime of recursive algorithms : Design a recursive O(n) algorithm that checks whether the given sorted array contains two equal elements. Remark. In this module we do not systematically learn how to assess runtime of recursive algorithms.
Critical value from normal distribution : Using the above RSAC and RSPAC, calculate the corresponding krs , krt , kk rs , kk rt k = 1, 2, 3, 4 5, 6, to identify a model describing ηt .Explain your choice of model. Please also provide the new model for STAT S802F - Multivariate and Time Se..
Substantial economic and social impact in australia : Topic:The drug "ice" is currently having a substantial economic and social impact in Australia. Outline the main problems caused, and suggest some measures to reduce the influence of this illicit drug in Australia.
Explain way that group members responded to initial stage : Post by Day 3 a description of the leadership style you observed. Explain how the leader creates safety establishes the norms of the group including confidentiality, and engages members.
We have to bring this new drug to market : We have to bring this new drug to market if we are going to be a player in this industry.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Binary multiplication using booths algorithm

Perform the subsequent 4-bit binary multiplication using Booth's algorithm, assuming signed two's complement integers:

  Determine the number of peaks and valleys in given terrain

Problem: Navigation over a terrain can be an important concept. Usually you want to avoid high areas (peaks) and low areas (valleys) -

  Decryption speed and diffie-hellman

Increase of a single bit in the size of the encryption key doubles the amount of needed computations - Show how the recipient of the message, who knows e, produces the plaintext.

  Examine the time and space complexity of algorithm

Some DNA strings can transform to other strings by breaking into contiguous substrings, reversing some of these substrings, and then reconnecting the substrings in the original order.

  Explain spacewise efficient implementation two-stack data

Structure of such two-stack data type would consist of two arrays and two top pointers. Describe why this may not be a spacewise efficient implementation.

  An undirected graph g is called bipartite

An undirected graph G is called bipartite if its vertices can be partitioned into two sets X and Y such that every edge in G has one end vertex in X and one end vertex in Y

  Discuss the business problem

Provide a clear statement of the aims and objectives of the data analytics study and the possible outcomes in terms of discovered knowledge and its potential application towards solution of the problem. In this section you need to discuss the busi..

  Write psuedocode for classic traversal algorithms

Write psuedocode for one of the classic traversal algorithms(preorder, inorder, and postorder) for binary trees. Assuming that your algorithm is recursive, find the number of recursive calls made

  Create the algorithm to read information through file

Create the algorithm which will read through file and compute numbers of married men, single men, married women and single women.

  What is the role or place of structured methodologies,

What is the role or place of structured methodologies, data, and algorithms? What differs between object-oriented and object-based languages

  Structural and behavioral models

Your analysis phase of the SRS project went well and your team feels good about their Functional, Structural, and Behavioral models. You also discussed the result of your analysis with the School of Prosperity (SoP) administration and they seem to be..

  Compiler to separate the numbers using dashes

write this code using structures.with writing the SSN in one line this ask the compiler to seperate the numbers using dashes.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd