Earn Higher Grades With Instant Assignment Help.Ask Question!

Data structures & Algorithms
(5/5)

Given an array of integers (not necessarily sorted), return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Problem 1: Two Sum

Problem Description: Given an array of integers (not necessarily sorted), return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

For example, if you are given an array [2, 7, 11, 9] with a target 9, then you will return [0, 1] since the first two numbers add up to 9. It is important that you solve this problem using divide and conquer and recursion. That is, you must divide the original problem into subproblems, recursively solve the subproblems, and then combine the solutions to the subproblems to obtain the solution to the original problem.

 Your solution should take O(n log n) time. If you don’t use divide and conquer and recursion then you will not get any points for this assignment. The following has to be given.

Submission should contain a code file, and a pdf (report)

(a) Give the pseudocode for your solution. Also explain in English why your solution works. (30 points)

 (b) Show correctness of your algorithm and analyze its complexity. (20 points).

(c) Code up your solution in C++ Your code should be well commented. Your code should compile, otherwise no points. (50 points) 

 Hints: • Figure out how to efficiently check for the solution if the input is sorted.

  • Figure out a way of solving the problem in O(n log n) time by using divide and conquer. The main idea is to use an approach like MergeSort.
  • Return only the two distinct indices (assume there is exactly one solution)
Attachments:
(5/5)

Expert's Answer

22 Times Downloaded

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

22 Times Downloads

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
645 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
770 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
872 Answers Hire Me