Question:
What does an algorithm in computing look like?
?
2012-04-12 14:55:27 UTC
Well, i'm planning to do a software engineering course at university in the near future; and i'm just wondering if anybody could find me of an example of a computing algorithm.. idk, in C++ or something?

I've never seen one before and want to know how complicated they look :L

Stupid question i know, but thank you for answering..
Five answers:
Bob M
2012-04-13 02:18:30 UTC
That is a bit of a surprise, you got three answers and all three are wrong. They have written code, not algorithms.



An algorithm is a codeless description of the problem you are solving in a programming project. So as an example lets say we have a project to collect particular values from a database that already exists, the values are related to an input value given by a user.



The way we do it is start with the whole project as a single object. So our first stage algorithm is our project itself.



Algorithm 1 - collect particular values from a database that already exists, the values are related to an input value given by a user..



Now we start to break that down into steps, starting with large steps.



Algorithm 2 -

a) Collect input from user.

b) Collect related items from database.

c) Show result.



Now each of these are broken down further into smaller parts. We have to side step for a moment here. There are programmers who love graphical algorithms, starting at the top of a piece of paper, in pencil because you will change it a lot, you go from a box called 'Start', then go through each step (still large steps at this stage). Then each large step broken to smaller steps until you have programmable steps.



Personally I never use the graphical respresentation, it doesn't get my mind into the right zone for programming. Instead I write algorithms in list form. You can choose which ever works for you, you might even find that a mixture of the two works best. Also, all of my programming languages have a C-like syntax, so over the years I have made my algorithms more C-like. For me it means that when I come to the coding stage the code basically writes itself directly from the algorithm.



So back to our project.



Algorithm 2a - Get input from user.

1) Present the user with a means to input one or more values.

2) Check the input for validity, make sure it falls within the limits of our project and is of the right type.



Alforithm 2a1 - Present user with input form.

Form - UserInput -

----------txtInput - textbox to receive input.

---------btnOK - button to confirm input

--------btnCancel - button to cancel input



Algorithm 2a2

Back code - Validate user input.

Functions

-------TestUserInput(txtInput.text);

-------ReportBackIfUserInputInvalid();



And so it goes on through your project. This system can be used for projects from the huge to the very small. You would often find yourself changing or updating a small piece of code, possibly written by another programmer. Using the algorithm you can be more sure of getting the gist of what the orriginal programmer was doing, what values are available to your code in the part of his project that you are working in.



Do one now, Write an algorithm for tic tac toe, everyone knows that game so you can concentrate on the writing of the algorithm rather than the problem you are solving. Start with the big picture, then brak it down until you have function sized pieces.
Shawn B
2012-04-12 15:03:22 UTC
An algorithm is a set of instructions to perform some purpose. The algorithm can be really small, or very huge.



For example, and algorithm to find the largest of two numbers may look like this:



int biggest(int a, int b)

{

if (a > b)

return a;

else

return b;

}



Or, an algorithm can be huge (thousands of lines of code), like an algorithm to convert a TIFF image into a JPG image.



bool convert_to_jpg(string tiff_file_name, string jpg_file_name)

{

bool success = false;

[ do a LOT of work here, if it succeeds set success=true ]

return success;

}



To make an algorithm easier to comprehend, programmers will break the large problem up into smaller problems. And each of these may be broken up into separate little algorithms. In the example above, the first problem is reading the TIFF file, the next is interpreting the data in the file, next is converting that data to JPG, and the final part is writing the file. Any one of these parts may fail, but the all must succeed for this algorithm to return true.
barb
2016-04-24 09:04:59 UTC
A pleasant atmosphere in and all around the property always helps make life simple. If you have a beautifully designed and landscaped backyard to relax in , you feel up to any sum of challenging function but if you do then you must do it with this manual https://tr.im/dOmKQ , Ideas 4 Landscaping.

Within his function-developed database , you’ll discover larger photographs to assist build an overview of entire , cohesive environments: actually , ‘the massive picture.’ As soon as you’ve determined on a common look , you can browse harmonizing mid-sized characteristics this kind of as decks , fountains , pergolas , pools , gazebos and so on. Then , lastly , comes the tiny tweaks and specific specifics personal to you.

The specifics may well come from your memories but without a doubt with a tiny help from Ideas 4 Landscaping; a favorite flower or flowering tree; an ornament from your childhood – a sundial , say , or a flowering vine , or stepping stones –can be something individual to you , that neither the most professional landscape artist couldn’t perhaps know about but with Ideas 4 Landscaping you put on your own perfect landscaping.

Make your home come to live with Ideas 4 Landscaping.
green meklar
2012-04-12 22:05:12 UTC
Algorithms range from the very simple to the incredibly complicated and esoteric.



Here's the code for a recursive mergesort implementation in C++:



void mergesort(int* a,int n)

{

if(n<=1)

{

return;

}

int m1=n/2;

int m2=n-m1;

int* s1=new int[m1];

memcpy(s1,a, m1*sizeof(int));

mergesort(s1,m1);

int* s2=new int[m2];

memcpy(s2,&a[m1], m2*sizeof(int));

mergesort(s2,m2);

m1--;

m2--;

int ma=n-1;

while(m1>=0 && m2>=0)

{

if(s1[m1]>s2[m2])

{

a[ma]=s1[m1];

m1--;

}

else

{

a[ma]=s2[m2];

m2--;

}

ma--;

}

while(m1>=0)

{

a[ma]=s1[m1];

m1--;

ma--;

}

while(m2>=0)

{

a[ma]=s2[m2];

m2--;

ma--;

}

delete [] s1;

delete [] s2;

}



I tested it and it seems to work. It's not actually as complicated as it looks, there are several places there where quite a few lines of code are used to express a very simple concept. I picked this algorithm because it is relatively straightforward and can be easily encapsulated in a single function. Eventually, though, you will encounter algorithms that aren't quite so tidy.
Quade
2012-04-12 15:08:03 UTC
an algorytmh looks like this



if computer=turned_on{

x+=1;

x-=1;

x=x;

x=y;

y=tig_source_froum_user(134);

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...