> Hi....Please what are the steps in developing an algorithm to determine how many times a name occurs in a list of names?

Hi....Please what are the steps in developing an algorithm to determine how many times a name occurs in a list of names?

Posted at: 2014-12-18 
I very just begun this course but the answers I come up with are way too confusing......I wouldn't mind a breakdown. Thanks in advance.

It depends on the language you're using but the easiest way would be to use two arrays.

The first array holds the names and the second array holds a value on how many times the name occurs. When you encounter a name, search the first array to see if it exists. If it does, use that array index on your second array to increment the value. If it doesn't, add it to the first array.

When you've run through your data, you can easily figure out how many times each name occurred by using the array index of the name array on the other array.

Feel free to email me if that is still confusing to you. =)

This really depends on the language you're using.

Personally I would look into putting all names into an array and have the name you are searching for as a variable. Then add a second variable that counts how many times that name has occured.

If $array[$a][$b] = $variablewithname Then $countingvariable = $countingvariable + 1

Really hard to show an example without knowing the language. :(

It depends upon the language. Some languages will allow you to compare strings, others require you to compare each individual individual character using arrays - the string is an array ...

In python, the algorithm would look like this (in its simplest form):

#!/usr/bin/python

#python 2.7

names = ('Alan', 'Brian', 'Chris', 'David', 'Chris')

name = raw_input("Enter name: ")

count = 0

for n in names:

....if name == n:

.... .... count += 1



print '{} appears {} times in the list.'.format(name, count)

# Note: I've used "...." to represent tabs which Yahoo! Answers removes.

asadq

I very just begun this course but the answers I come up with are way too confusing......I wouldn't mind a breakdown. Thanks in advance.