2. Explain when we can have the best case and when we can have the worst case. Give the complexity of your algorithm in each case. ● Best case: Question 1: 0 Worst case: Given an array, that can contain zeros, positive and negative elements. 1. Write an algorithm that calculates the number of positive elements (>0), the number of negative elements, and the number of zeros. Example: ● -5 Number of positive elements: 2 Number of negative elements: 3 Number of zeros: 3 Algorithm: wwwmmm -7 0 -6 8 0

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

do not plagiarise

2. Explain when we can have the best case and when we can have the worst case. Give
the complexity of your algorithm in each case.
Best case:
0
Worst case:
Question 1:
Given an array, that can contain zeros, positive and negative elements.
1. Write an algorithm that calculates the number of positive elements (>0), the number
of negative elements, and the number of zeros.
Example:
1
Algorithm:
-5
Number of positive elements: 2
Number of negative elements: 3
Number of zeros: 3
-7
0
-6
8
0
Transcribed Image Text:2. Explain when we can have the best case and when we can have the worst case. Give the complexity of your algorithm in each case. Best case: 0 Worst case: Question 1: Given an array, that can contain zeros, positive and negative elements. 1. Write an algorithm that calculates the number of positive elements (>0), the number of negative elements, and the number of zeros. Example: 1 Algorithm: -5 Number of positive elements: 2 Number of negative elements: 3 Number of zeros: 3 -7 0 -6 8 0
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Randomized Select Algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage