answersLogoWhite

0


Best Answer

You can write any algorithm in any way you like. Many prefer pseudocode or flowcharts, others use prose or more formalized methods.

For example, if you wanted to describe an algorithm to count the number of occurrences of a given item I in a given list L, I would propose the following pseudocode:

let counter be 0.

let the current item C be the first item in list L.

while C == valid {

if C matches I then

increment counter set C to the next item in the list

}

return counter.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write an algorithm to find the number of times a given ITEM occurs in LIST?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Time complexity of selection sort?

Merge sort (or mergesort) is an algorithm. Algorithms do not have running times since running times are determined by the algorithm's performance/complexity, the programming language used to implement the algorithm and the hardware the implementation is executed upon. When we speak of algorithm running times we are actually referring to the algorithm's performance/complexity, which is typically notated using Big O notation. Mergesort has a worst, best and average case performance of O(n log n). The natural variant which exploits already-sorted runs has a best case performance of O(n). The worst case space complexity is O(n) auxiliary.


Program to find the occurrences of a given character in a string in c plus plus?

#include#includesize_t count_char (const std::string& s, const char c){size_t count = 0;size_t offset = 0;while ((offset = s.find(c, offset)) != s.npos){++count;++offset;}return count;}int main(){std::string str {"Hello world!"};std::cout


In the bubble sort algorithm the second loop iterates ---------- for each of the unsorted array elements?

n-1 times


What are factors to consider when choosing sorting method?

There are lots of factors to consider. Some important ones are what are the best, worst, and average times it will take for the sorting method to complete given a certain amount of elements to sort. Also important is how much memory the algorithm will use, what he distribution of the data it is working on is, and whether you want the algorithm to ensure that if stopped part way though sorting that the data is not in a less sorted state than when it started.


What is passes in sorting algorithm?

Assuming you're talking about comparison-based sorting algorithms, the number of passes is the number of comparisons that the algorithm makes internally while sorting. In a programming language, this would be the total number of times the loop executes. This number is defined by the computational complexity (Big-O notation), which defines an upper bound.