Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91605069

Have any Question?


Related Questions in Computer Engineering

Question using the apple company identify all the social

Question: Using the Apple company, identify all the social media platforms it currently uses. List all the social media platforms. List five different KPI's you could use to measure the engagement on each platform. Expla ...

Access your browsers security settings and configure the

Access your browser's security settings and configure the browser to refuse all cookies or to prompt you before allowing a cookie. Restart the browser; then visit several different Web sites. Be sure to visit popular sit ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Small business e-commerce portalscheck out small business

Small Business e-Commerce Portals Check out Small Business Center and the other e-commerce portals mentioned. Then answer the questions. Note: Small Business Center and Entrabase.com are interesting sites that offer a wi ...

Question summarize the human-computer interface hci of

Question : Summarize the human-computer interface (HCI) of Microsoft Word 2013 and Visio 2013. Explain the importance of HCI and usability of the software. Be sure to note any commonalities between the applications and n ...

What are the best practices to follow for microsoft windows

What are the best practices to follow for Microsoft Windows network security. Which two would you start with and why?

A manager has a 250 million portfolio that consists of 40

A manager has a $250 million portfolio that consists of 40% stock and 60% bonds. The beta of the stock position is 1.4. The modified duration of the bond position is 5. The manager wishes to achieve an effective mix of 7 ...

What is tf-idf weighting justify it using zipfs curve and

What is tf-idf weighting? Justify it using Zipf's curve and Luhn's proposal.

In system analysisdiscuss and give suggestions or comments

In system analysis Discuss and give suggestions or comments for the following questions: 1. Discuss about the project plan (activities and scheduling) 2. What are the new tools and strategies used in project plan or mana ...

Scenario you have been asked to develop a company policy on

Scenario: You have been asked to develop a company policy on what should be done in the event of a data breach, such as unauthorized access to your company's customer database. What sort of process would you use to devel ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As