Algorithm to find the sum of contiguous

Assignment Help Data Structure & Algorithms
Reference no: EM131407860

Q1. You are given a one dimensional array that may contain both positive and negative integers. Give an O(n log n) algorithm to find the sum of contiguous (ie. next to one another, in sequence) sub-array of numbers which has the largest sum. For example, if the given array is [-2, -5, 6, -2, -3, 1, 5, -6], then the maximum sub array sum is 7 (the sub array is marked in boldface). Argue that your algorithm is correct.

You get as input n distinct positive integers a1, . . . , an. Give an O(n log n) algorithm to count the number of pairs i < j where ai > 2aj.

Q2. You are given two arrays, A and B, each of which contains n integers. The elements in each array are guaranteed to already be in sorted order in the input, i.e.

A[0] ≤ A[1] ≤ . . . ≤ A[n - 1],

and also

B[0] ≤ B[1] ≤ . . . ≤ B[n - 1].

Give as fast an algorithm as you can for finding the median value of all the 2n numbers in both A and B. (We define the median of 2n numbers to be the average of the nth smallest and nth largest values.) Argue that your algorithm is correct and give its running time.

Q3. You are given an array X of n elements. A majority element of X is any element occurring in more than n/2 positions. The only access you have to the array is to compare any two of its elements for equality; hence you cannot sort the array, etc. Design an O(n log n) divide-and-conquer algorithm to find a majority element in X (or determine that no majority element exists).

Q4. You are given a 2k x 2k board with one missing cell. Give an O(22k)-time algorithm for filling the board with "L-shaped" tiles. (See Figure 1 below.)

371_Figure.png

5. Consider you get as input a very sparse undirected weighted graph G = (V, E), in particular for which [E] - [V] = 20. Give an O(|V|) time algorithm for finding a minimum spanning tree on G and prove your algorithm correct.

Note - Question 1 has 2 different separate questions (Part A and B) with 2 different solutions.

Reference no: EM131407860

Questions Cloud

The ethical frontiers of robotics : Write an essay in response to Noel Sharkey's "The Ethical Frontiers of Robotics." This assignment asks you to relate your own ideas to those in Sharkey's article.
What was last year’s dividend per share : One week after Granddad's Kitchen split its stock 3-for-1, it paid a dividend of $0.55 per new share. The dividend payment was 10 percent greater than last year's presplit dividend. What was last year's dividend per share?
What is the inventory turnover : Big Bang Fireworks normally purchases $120,000 of inventory each day. Each item normally remains in inventory 18 days before it is sold.
What is the company''s accounts receivable turnover : A + Airplanes normally sells $125,000 of its product on credit each day, and it takes an average of 40 days to collect the credit sales.
Algorithm to find the sum of contiguous : You are given a one dimensional array that may contain both positive and negative integers. Give an O(n log n) algorithm to find the sum of contiguous (ie. next to one another, in sequence) sub-array of numbers which has the largest sum
What is the average balance in accounts receivable : If CLS can reduce its DSO to 45 days, what impact would this change have on its accounts receivable balance?
Find the median number of goals : The table below shows information about the number of goals scored by a football club in eahc of its last 45 games. find the median number of goals. Show your working clearly.
Professional or academic journal : The selected article must be from a professional or academic journal, at least two pages in length, and published within the last five years. Be sure that the article is specific to occupational safety and health as some search terms may result in..
Identify the potential market segments : Using the following list of products, identify the potential market segments of each product based on demographics, psychographic, and behavioral differences. Prepare a brief report and explain the segmentation variables associated with each examp..

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Creating code for a class called arrayqsn

Create all the code for a class called ArrayQsn. This class will contain 2-techniques. The first technique runningSumMean accepts an array of ints as a parameter, and will return the mean of the values as a double.

  Use substitution method to show

Use substitution method to show that the solution of T(n) = T(n/2)+1 is O(Ig n).

  Discuss the major steps of the genetic algorithm

Discuss the major steps of the genetic algorithms. Based on your experience and your textbook reading, what are suitable problem areas for the application of genetic algorithms?

  How is different node insertion into doubly linked list

How is different node insertion into doubly linked list vs. node insertion into singly linked list? just a short description.

  1 n vehicles occupy squares 1 1 through n 1 ie the bottom

1. n vehicles occupy squares 1 1 through n 1 i.e. the bottom row of an n times n grid. the vehicles must be moved to

  Determine order of operations for seq search algorithm

Determine the order of operations for this Seq Search algorithm. Best case and worse case and why - Find the order of operations for this Search algorithm. Prepare a proper algorithm for this problem and how to complete it.

  Explain good algorithms to solve character pathfinding

You are working on the new computer game. One of implementation problems you are trying to solve is character pathfinding. What algorithms would be good to use and explain why?

  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).

  Algorithm-decide whether language recognized by dfa is empty

Give an algorithm to decide whether the language recognized by a DFA is empty. Given two DFAs M1 and M2, give an algorithm to decide whether L(M1)subset or equal to L(M2).

  Describe the scope of the project and control measures

Describe the scope of the project and control measures - describe the goals and objectives of the project and include a high-level overview of all project deliverables.

  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.

  How to analyse spectrum of a digital signal using dft method

To learn how to analyse spectrum of a digital signal using DFT method. To learn how to perform I/O operations using interrupt method and program/implement them using the evaluation toolkit

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