How recursion terminate in array

Assignment Help Programming Languages
Reference no: EM1368467

A majority element in an array, A, of size N is an element that appears more than N/2 times (thus, there is at most one). For example, the array 3, 3, 4, 2, 4, 4, 2, 4, 4 has a majority element (4), whereas the array 3, 3, 4, 2, 4, 4, 2, 4 does not. If there is no majority element, your program should indicate this. Here is a sketch of an algorithm to solve the problem:

First, a candidate majority element is found (this is the harder part). This candidate is the only element that could possibly be the majority element. The second step determines if this candidate is actually the majority. This is just a sequential search through the array. To find a candidate in the array, A, form a second array, B. Then compare A1 and A2. If they are equal, add one of these to B; otherwise do nothing. Then compare A3 and A4. Again if they are equal, add one of these to B; otherwise do nothing. Continue in this fashion until the entire array is read. Then recursively find a candidate for B; this is the candidate for A (why?).

a. How does the recursion terminate?

b. How is the case where N is odd handled?

Reference no: EM1368467

Questions Cloud

Calculate net present value of benefits : Corporation A is planning the purchase of a new machine that would lower cash outflow. The cost of the machine is 30,000. The annual reduction in cash flows is:
Draw a proposed catalytic cycle : Draw the enantiomer of proline which would give rise to the absolute stereochemistry and draw a proposed catalytic cycle for the transformation and how does the catalyst activate the substrate
Write problems and issues associated with internet databases : Over 70% of web applications use database to store persistent data. Write some of the problems and issues associated with internet databases?
Strategy for internalizing positive externalities : Some real estate economists have argued that anchor stores in shopping malls create significant externalities for overall sales.
How recursion terminate in array : Continue in this fashion until entire array is read. Then recursively determine a candidate for B; this is  candidate for A (why?). How does the recursion terminate?
Question on opportunity cost : Think about the trade off in work and leisure during a given day, and from day to day. During a given day, does opportunity cost of work rise, decline, or remain constant with each additional hour of work?
Explain the managers will e-mail their weekly reports : Explain The managers will e-mail their weekly reports to you on Monday of the following week and You will then produce the summary report. Explain the process for doing this and Give a sample formula to total the number of mini-gizmos produced by ..
Describe why analyst needs to understand how people think : Describe why an analyst requires to understand how people think, how they learn, how they react to change, how they communicate, and how they work.
Explain and contrast the dynamics between dominant cultures : Explain and Contrast the dynamics between dominant cultures and subcultures either in a work setting or in society.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write implementation of counter class

Write the implementation (.cpp file) of the Counter class. Here is the full specification of the class: A data member counter of type int.

  Create a class-how to cash goods-give change to customers

Write class called Cashier that directs a cashier how to cash goods and give change to customers. Typical cashier operations are as follows.

  Distinguish class templates and program with heading

Clearly distinguish each class templates and their program with heading. Elaborate each step and give it without errors. Develop classes or class templates for the following.

  Write program to read ten numbers-display distinct numbers

Write a program that reads in ten numbers and displays distinct numbers (i.e., if a number appears multiple times, it is displayed only once).

  Illustrate whether program will fit in address space

Will this program fit in address space? If page size were 512 bytes, would it fit? Remember that page may not contain parts of two different segments.

  Program to create professor rating class

Write down program to create Professor Rating class comprising of professor ID and three ratings. Three ratings are utilized to estimate easiness.

  Write statement that calls add to compute sum of sales

Add is a method that accepts two int arguments and returns their sum. Write a statement that calls add to compute the sum of euroSales and asiaSales and that stores this value in eurasiaSales .

  Write program for real estate agent

Write a program for a real estate agent. The program should perform the following tasks: ask users for the average house price for the each of past 5 years for a single family residence of 1500 square feet.

  Explaining the situation in program

Which of the following best explains the situation after Line 1 has been executed?

  Write subclass for constructor accepting a double

Write a (non-abstract) subclass, ApartmentHouse, containing: a constructor accepting a double, passed to the superclass constructor, and an int used to initialize numberOfApartments

  Implement class to simulate growth of roach population

Implement a class RoachPopulationthat simulates the growth of a roach population. The constructor takes the size of the initial roach population.

  Develop computerized pot hole tracking and repair system

Department of public works for city has decided to develop computerized pot hole tracking and repair system. As pot holes are reported to customer service.

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