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

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

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