-2
$\begingroup$

Many computer science problems can be solved by more than one algorithm. Usually those algorithms have different problem-solving approaches and therefore different strengths and weaknesses.

My impression is that some developers focus on choosing the most efficient algorithm when they are for example participating in programming competitions to increase their chances of winning, but this does not always translate to real world applications.

Bad choices (e.g. always using bubble sort for a sorting operation instead of something more efficient) will eventually slow down the application. But most of the time, what with computers being so fast, better choices don't seem to make a discernible difference. How can we help teach developers that these choices ultimately do matter, and that they should aim for more efficient algorithms?

$\endgroup$
  • $\begingroup$ I've edited and re-opened the question. A. Biswas, if I've modified your intention, feel free to roll back the edit. (I tried to stick with what I believed you were asking) $\endgroup$ – Ben I. Dec 14 '17 at 23:45
  • $\begingroup$ The example given seems to me to correspond to a different question (how to explain to people the importance of using library functions rather than writing everything from scratch?) $\endgroup$ – Peter Taylor Dec 18 '17 at 11:02
3
$\begingroup$

Any programming is a two step process: deciding how to solve the problem, then implementing that as code on a particular system: choosing or designing an algorithm is the first step.

There are great ways to illustrate how the choice of algorithm matters. An introductory one might be search - comparing random, linear and binary algorithms to, for example, find a missing number, or a word in a (printed) dictionary, or a book in a (physical) library.

Another might be exploring different sorting algorithms, for example bubble sort and quicksort using this CS Unplugged activity.

Mathematics provides a rich source of contexts, for example asking students to think of an algorithm for finding the greatest common divisor (i.e. highest common factor) for a couple of numbers. Have them try their algorithms out on paper before coding them and then testing with some big test numbers.

$\endgroup$
  • 1
    $\begingroup$ This slightly compounds the misapprehension posed by the question that algorithms are only the special functions. So, your two step process is an algorithm (not a very useful one maybe). Honestly, I think the question is too general as it stands. $\endgroup$ – Sean Houlihane May 24 '17 at 17:10
  • $\begingroup$ Algorithms as systematic, replicable, automatable ways to solve problems? $\endgroup$ – Miles May 24 '17 at 17:54
  • $\begingroup$ Yes. Like a machine learning algorithm might be keep trying random stuff till you get a better result... Not just stuff that you find on github if you need to copy it (or have to memorise for an exam). $\endgroup$ – Sean Houlihane May 24 '17 at 18:00
0
$\begingroup$

The importance of algorithms is that it is a form of automation. For example, calculating the Fibonacci Sequence would take a long to time to find n number, but if you create a program that finds that n number, you save a lot of time.

Algorithms, used properly and with caution, can change your program from a 0 to a 100.

You can think of an algorithm as a recipe that describes the exact steps needed for the computer to solve a problem or reach a goal. Your recipe would the procedure and the input would be inputs by the user. It's like a flowchart:

Flow chart

$\endgroup$
0
$\begingroup$

A good way to talk about algorithms is as a series of simple steps that can be repeated. It's similar to the role of a function or routine. Here, everyday examples can be helpful, for example something like autocorrect. Autocorrect is a series of steps repeated over and over.

  1. Select the last word typed
  2. Check how similar it is to the other words that the computer knows
  3. Check how often the user has used each of these words
  4. Suggest the most similar and most used word
  5. If the user types a space, make the correction

It will repeat these steps every time a character is typed. When writing code, it's clearly easier to write:

function check_last_word(text) {
  word = text.last_word
  similar_words = get_similar_words(dictionary, word)
  corrected_word = get_most_used_word(word_usage_data, similar_words)
  text = text - text.last_word + corrected_word
}

when text_is_changed? {
  check_last_word(text)
}

As compared to:

word = text.last_word
similar_words = get_similar_words(dictionary, word)
corrected_word = get_most_used_word(word_usage_data, similar_words)
text = text - text.last_word + corrected_word
sleep until text_is_changed?
word = text.last_word
similar_words = get_similar_words(dictionary, word)
corrected_word = get_most_used_word(word_usage_data, similar_words)
text = text - text.last_word + corrected_word
sleep until text_is_changed?
word = text.last_word
similar_words = get_similar_words(dictionary, word)
corrected_word = get_most_used_word(word_usage_data, similar_words)
text = text - text.last_word + corrected_word
sleep until text_is_changed?
word = text.last_word
similar_words = get_similar_words(dictionary, word)
corrected_word = get_most_used_word(word_usage_data, similar_words)
text = text - text.last_word + corrected_word
sleep until text_is_changed?
word = text.last_word
similar_words = get_similar_words(dictionary, word)
corrected_word = get_most_used_word(word_usage_data, similar_words)
text = text - text.last_word + corrected_word
sleep until text_is_changed?

And so on. This is not actually an example of an algorithm, but it acts as a good example to show why having a series of repeatable steps is better than simply going through each step each time.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.