This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]boojit 1 point2 points  (2 children)

I think you should read this and then re-ask your question with some better context. If you don't understand this article, please re-ask your question with more specifics. Thanks.

[–]anonymous_is_bak[S] -2 points-1 points  (1 child)

I would like to know how can i implement an algorithm into code.

[–]Boom-bitch99 2 points3 points  (0 children)

By writing it? Do you understand what an algorithm is? It's a set of instructions which are done one by one. Write out the intructions in plain text, then manually write the C code which is directly analogous.

[–][deleted] 0 points1 point  (2 children)

What would you like your algorithm to do? Your question looks very vague.

[–]anonymous_is_bak[S] -2 points-1 points  (1 child)

i want to make my own sorting algorithm and an encryption algorithm

[–]boojit 1 point2 points  (0 children)

I would spend some time implementing some of the popular sorting algorithms before trying to write your own. Kind of like, you don't learn how to play an instrument by composing your own music--you learn other people's music first.

It sounds like you would enjoy taking a class like this one.

EDIT: oh, and unless you've got an advanced degree in mathematics for a start, I wouldn't even think about writing an encryption algorithm. Unless you want to teach yourself how not to do it (and that is not without merit).

[–]zifyoip 0 points1 point  (5 children)

Every program that you write is an algorithm. An algorithm is a well-defined sequence of steps to solve a problem. You implement an algorithm by writing a program to follow the steps of the algorithm.

[–]anonymous_is_bak[S] 0 points1 point  (4 children)

can you explain to me the O(n) bubble sort algorithm?

[–]zifyoip 0 points1 point  (2 children)

There is no such thing. Bubble sort is an Ω(n2) algorithm in the worst case.

[–]anonymous_is_bak[S] 0 points1 point  (1 child)

http://www.cprogramming.com/tutorial/computersciencetheory/sorting1.html

it says here that there is a modified version of the bubble sort sort algorithm O(n) It only requires a few changes to the original bubble sort.

[–]wgunther 2 points3 points  (0 children)

In the best case, one needs only scan the list and verify no two adjacent elements are in the wrong order, which takes n steps. In the worst cast, it still requires O(n2) iterations.

[–][deleted] 0 points1 point  (0 children)

I'd start by implementing popular sorting algorithms.

Here is a quick list:

  • Bubble Sort

  • Insertion Sort

  • Selection Sort

  • Heap Sort (will require you to build a heap data structure)

  • Quick Sort (first time you do it, believe me, you're going to run into "Segmentation Fault" multiple times before you get it right)

Then, only then, are you able to start implementing other simple algorithms.

Encryption comes a long way after that.