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

  Define wan and provide an example of typical wan setup

Define a WAN and provide an example of a typical WAN setup and describe the components. Provide a picture, chart, or image if possible.

  Algorithm to concatenate string in single binary search tree

Create algorithm which concatenates T1 and T2 into single binary search tree. Worst case running time must be O(h).

  Write a programming for sorting

write a programming for sorting

  How to store and reference data in an array list

How to store and reference data in an array list and How to delete data from the ArrayList

  Explain types of information systems

Question 1. Explain five types of information systems, and give an example of each. Question 2. Describe three common reasons for a systems request. Try and find one not listed in the text.

  Program to implement a stack and a queue

Write a C/C++ program to implement a stack and a queue as applications of LL.

  Design and implement an efficient algorithm of an intergers

Design and implement an efficient algorithm that gives a set of S of an intergers and another x, determines whether or not there exist two elements in S whose sum is exactly x

  What is the average queue occupancy

What is the average queue occupancy - What is the average delay of a bit in the queue?

  Threat model to describe risk of attack vector

Construct a simple threat model that describes the risk this represents: attacker(s), attack vector, vulnerability, assets, and likelihood of occurrence, likely impact, and plausible mitigations.

  What do you mean by query tree what is meant by the

question 1 how does a query tree represent a relational algebra expression?question 2 what is query tree? what is meant

  What is the running time of your algorithm

Give an ef?cient algorithm to determine if there exists an integer i such that Ai = i in an array of integers A1

  Explain the need for complex data structures

Explain the need for complex data structures. Explain the design and application of arrays to program logic and data manipulation.

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