in Algorithms concepts…
Question 1:
Given an array, that can contain zeros, positive and negative
elements.
0
1
-5
-7
0
-6
8
0
Number of positive elements: 2
Number of negative elements: 3
Number of zeros: 3
Algorithm :
Question 2:
Give an algorithm to calculate the sum of first n numbers. For
example, if n = 5, then the ouput should be 1 + 2 + 3 + 4 + 5 = 15.
Give three solutions for this problem. The first solution with a
complexity O(1), the second solution with a complexity O(n), and
the third solution with a complexity O(n2).
Solution 1:
Solution 2:
Solution 3:
Question 3:
Given this algorithm:
i=1;
sum
=
0;
while
(i < m)
{
j=n;
while
(j > n/2)
{
print(i,j)
j
= j - 1;
}
i
= i
+1;
}
in Algorithms concepts… Question 1: Given an array, that can contain zeros, positive and negative elements. 0 1 -5 -7 0
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
in Algorithms concepts… Question 1: Given an array, that can contain zeros, positive and negative elements. 0 1 -5 -7 0
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!