Question

Give an algorithm for finding the second largest integer in a finite sequence of integers. Write the algorithm in pseudocode format

Answer #1

The above picture is about the algorithm to print second largest in finite sequence of Integers.

a) Give a recursive algorithm for finding the max of a finite
set of integers, making use of the fact that the max of n integers
is the larger of the last integer in the list and the max of the
first n-1 integers in the list.
Procedure power(x,n):
If (n=0):
return 1
Else:
return power(x,n-1) · x
b) Use induction to prove your algorithm is correct

Devise an algorithm that takes a list of n > 1 integers and
finds the largest and smallest values in the list.

Describe an algorithm that, given a set S of n integers and
another integer x, determines whether or not there exist two
elements in S whose sum is exactly x. Your algorithm must be nlogn.
Evaluate how long each step in the algorithm takes to demonstrate
that it meets this requirement.

The bubble sort algorithm discussed in class is used to sort the
following sequence of integers: 47 29 1 9 5 23 • How many passes
must the algorithm perform to guarantee the entire sequence is
sorted? • What is the list obtained after the first pass? • What is
the list obtained after the third pass? • What is the list obtained
after the final pass?

Given a list of n integers, find the largest integer in the
list. Use Java or C++ please

Use the Euclidean Algorithm to find the smallest nonnegative
integer x, s.t. there exists integers k_1, k_2, such that x = 11k_1
+ 3 and x = 49k_2 + 5.

if you are given a finite set V and a nonnegative integer for
each element in the set such that the sum of the integers is even,
can V be realized as vertices of a graph with the associated
degrees? If so prove it. If not give a counterexample.

1. Given an
n-element array A, Algorithm X executes an
O(n)-time computation for each even
number in A and an O(log n)-time computation for
each odd number in A.
What is the best-case running time of Algorithm X?
What is the worst-case running time of Algorithm X?
2. Given an array,
A, of n integers, give an O(n)-time algorithm that finds
the longest subarray of A such that all the numbers in that
subarray are in sorted order. Your algorithm...

4. Let Z be the set of all integers (positive, negative and
zero.) Write a
sequence containing every element of Z.

Write a function that takes an array of integers and its size as
parameters and prints the two largest values in the array. In this
question, the largest value and the second largest value cannot be
the same, even if the largest value occurs multiple times. In the
first sample, the two largest values are 9 and 8 (even though the
value 9 appears twice). In the second sample, all the values are
equal and the program recognizes this by...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 2 minutes ago

asked 4 minutes ago

asked 6 minutes ago

asked 9 minutes ago

asked 13 minutes ago

asked 25 minutes ago

asked 26 minutes ago

asked 29 minutes ago

asked 39 minutes ago

asked 42 minutes ago

asked 47 minutes ago

asked 47 minutes ago