Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

An array is called a winner if it has two entries which together add up to a third entry, i.e. if A[i] + A[j] = A[k]for some i,j,k, where i≠j≠k. a)Write an algorithm (pseudocode preferred) to...

1 answer below »

An array is called a winner if it has two entries which together add up to a third entry, i.e. if A[i] + A[j] = A[k]for some i,j,k, where i≠j≠k.

a)Write an algorithm (pseudocode preferred) to determine if a given array A is a winner. Your algorithm should not use any additional data structures.

b)Analyze the running time of your algorithm using Big-O notation.

Answered 92 days After Jun 07, 2022

Solution

Ashok answered on Sep 08 2022
76 Votes
Problem statement
Algorithm:
The aim of the algorithm is to find three a
ay elements that satisfy the A[I] +A[j] = A[k] where I ≠ j ≠ k
Step 1: start with the first element of the a
ay (I.e., index 0) A[k]
Step 2: find the element that is smaller than the cu
ent element A[j] by traversing all the elements in the a
ay
Step 3: find the difference between the A[k] and A[j]
Step 4: if there is an element in the a
ay A[I] that satisfies the condition A[I] = A[k] - A[j] then declare the a
ay as winner, find an element in the a
ay that satisfies the condition by traversing all the elements of the a
ay
Step 5: if there are no matching elements in the a
ay that satisfy the condition A[I] +A[j] = A[k] where I ≠ j ≠ k then a
ay is not winne
Pseudocode
    bool isA
ayWinner(int a
ay[], int size)
{
for (int k = 0; k < size; k++)
{
int num1 = 0;
int num2 = 0;
Check for the two numbers,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here