Algorithms

An algorithm is a self-contained step-by-step set of operations to be performed. Algorithms exist that perform calculation, data processing, and automated reasoning. Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing "output" and terminating at a final ending state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,

I am practicing some algorithm to merge 2 existing arrays.
Here are the requirements I created:
1. no Linq allowed.
2. no concat, copyTo. Array.Sort() method allowed.
3. result should be sorted by ascending order.

I actually completed the coding, but there must be much better solution.
I also had to create Sort method to sort the result array.
Is there anyway I can sort while merging?

Currently I am Merging and then Sorting.


 
static void Main(string[] args)
        {

            int[] a = { 1, 2, 3 };
            int[] b = { 1, 2, 3 };

            int[] result = Sort(MergeTwoArrays(a, b));
            foreach (var item in result)
            {
                Console.Write(item+ " ");
            }           

            Console.Read();
        }

        public static int[] MergeTwoArrays(int[] a, int[]b)
        {
            int aLength = a.Length;
            int bLength = b.Length;
            int totalLength = aLength + bLength;
            int[] c = new int[totalLength];

            for (int i = 0; i < a.Length; i++)
            {
                c[i] = a[i];
            }
            int k = a.Length;
            for (int i = 0; i < b.Length; i++)
            {
                c[k] = b[i];
                k++;
            }
            return c;
        }

        public static int[] Sort(int[] a)
        {
            int i, j, temp, minIndex;
            for (i = 0; i < a.Length; i++)
            {
                minIndex = i;
    

Open in new window

0
Become a CompTIA Certified Healthcare IT Tech
LVL 12
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

I've been using the Azure ML Studio and it is great.

I get the basics of what ML is and what it does. But now I'd like to learn it in more detail - understand the deeper issues, the math behind it, what the different algorithms do and so on.

But I don't know where to go for this. Most of the introductions to ML use Python and TensorFlow. Ideally I'd like to stick to Azure ML Studio but I just can't find anything that tells me about the theory of ML rather than how to use Azure ML Studio.

I'm talking about books or courses - I think ideally a book but either would be fine.

This book might be promising:

Predictive Analytics with Microsoft Azure Machine Learning 2nd Edition Paperback – 19 Aug 2015
by Valentine Fontama (Author), Roger Barga (Contributor), Wee Hyong Tok (Contributor)

But I'm concerned it doesn't give the background - the reviews seem to indicate this.

Let me know if you have read a good book or completed a good course that explains the math of ML and would be something I could use with the Azure ML Studio.

Thanks!
0
Need to search find closest match in array of strings

I have a static list of about 500 strings containing things like:

VS Credit Voucher Proc-CR Trans 2
VS Credit Voucher Proc-OB Prepaid Trans 2

but am reading from OCR and get the strings from the faxed reports looking like:

VS Credit Voucher Proc-CR Trans 2
VS Crect Voucher Proc-OBPrepaid Trar 2

I need to do a lookup for the best match for each as it appears in the in the static list.

And of course, there needs to be a threshold where NO MATCH is a possibility.

How shall I store the static list? How can I do a search in the list that is resource efficient?

I would sort that list of 500, clearly. But what are the mechanics of the lookup?

I am writing a C# Win Forms (64 bit) application and could include a database, if I could include that into my EXE, to avoid a distinct installation step.

What search algorithm?
 
Thanks.
0
I am considering whether the starting position for the pattern vis-a-vis the searched text,  (i.e. the LAST CHARACTER of the pattern be aligned) ought to initially coincide with the first appearance of that LAST CHARACTER in the searched Text, *provided that appearance is equal to or more than the length of the Pattern*, since otherwise the index would have occurred too early in the sequence to be valid.

Consider this illustration from the B-M paper :

Search starting alignment
The B-M algo would 'mismatch' the final T from the 'pat' with the F from the 'string', and move the pattern past the F, to align the A with the I. Whereas the first contending T in the pattern and the string is at index 17 in the string, rather than the standing comparison being done at index 7.
0
Are there any comments anyone would like to make that would flatter or support any particular approach to String search methodology and algorithms ? Are there any algorithms which can be applied to several search conditions and requirements ? All comments welcomed. Thanks, k.
0
Implement an algorithm as method to take a BST and convert it to a mirror tree where left and right subtrees are interchanged.
and print BST each level in separate line
All coding should be in Python
0
Dear experts,

I have learnt about GeoGebra app while learning about One note from one of the Youtube videos.

I have tried it and i see that produces good charts. But it does not the values used in the x variable to calculate the Y value.

In the attached screen dump I have shown the table calculated by me. the function graph has been copy[-pasted from Geogebra.

CAn you someone please guide me to a app/url which plot the function and shows the table.

Thank you
WhatsApp-Image-2018-04-13-at-07.07..jpeg
0
Explain Big O notation, Binary Search and Logarithms, C#

I am curious to learn more about Big O, Binary Search and huge data sets.

What sorting and searching methods maximize performance for millions of records?

Is Binary Search still used here?

Thanks

https://codingticks.wordpress.com/2013/07/21/a-beginners-guide-to-big-o-notation/
0
Need exercises on the Big O Notation

I have engineering optimization on various software projects in the past, but need to pass a test which will evaluate my skills solving the Big O Notation.

I will need to code in C# with arrays, data sets and the like as a way to show I can optimize code.

Any exercises I could play around with?

Thanks.
0
I have found this below function for deleting a node from Linked List from the book named [DATA STRUCTURE AND ALGORITHMS MADE EASY](https://www.amazon.in/Data-Structures-Algorithms-Made-Easy-ebook/dp/B01N4OA309?tag=googinhydr18418-21)


The code is:-
void DeleteFromLinkedList(struct ListNode **head, int position){
int k=1;
struct ListNode *p, *q;
if(*head==NULL){
printf("List Empty");
return;
}
p=*head;
//from the beginning
if(position==1){
*head=(*head)->next;
free(p);
return;
}

else{
//Traverse the list until arriving at the position from which we want to delete
while((p!=NULL) && (k<position)){
k++;
q=p;
p=p->next;
}
if(p==NULL) //At the end
printf("Position does not exist");
else{  //From the middle
q->next=p->next;
free(p);
}
}
}

Open in new window


Now my question is what is the meaning of
(k<position)

Open in new window

here what is the purpose of using this
 (k<position)

Open in new window

and wh at is the use of
intk=1;

Open in new window


please explain me in detail the above code.
0
PMI ACP® Project Management
LVL 12
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

I'd like to write a Lambda function that fetches a (1) CloudWatch Metric (that is already being monitored at every 5 minutes), (2) divides that value by 300 seconds and (3) pushes to CloudWatch as a Custom Metric.

The CloudWatch metrics already being monitored are "Volume Read Ops" and "Volume Write Ops" on a could different active EBS volumes.

I have no every on using Java or Python for this.

Thanks for your help or pointing me in the right direction.
0
I need to prove that certain patterns were engineered and not random events and have been told that Neural Networks can be used to help make this determination.

What kinds of tools and algorithms should I be looking at?

Any sample projects that have done something similar?
0
If we consider the included image, namely that the structure of the binary data obtained after treatment seems to be completely regular and more repeated in similar parts until the end of the file, can we consider being able to definitively free ourselves from identical elements within each slice and thus no longer need to store them?
Re-Scheduling the Binary Structure of a File to Reduce its Final Volume

Thank in advance for your opinion .. ... .....

Best regards,
0
C++03 using VS 2010. (Assume no boost available.)

I would like to find the missing points in the below diagram using C++03 std lib. The x's represent a set of given points, and the o's are the missing points.

x----o--x----x---o
|    |  |    |   |
o----o--x----o---x
|    |  |    |   |
o----x--x----o---x
|    |  |    |   |
x----o--x----o---o
|    |  |    |   |
x----x--o----o---o
|    |  |    |   |
o----o--x----o---o

Open in new window

I am given a set of points Pi = (Xi, Yi). The coordinates are of type double. If I were to draw a grid (consisting of horizontal and vertical lines) going though every point, I may have some missing points as shown above.

The result should be a std container having the (X, Y) points that are missing.

I suspect that http://www.cplusplus.com/reference/algorithm/set_difference/ or some variation might be useful. So getting the entire list of potential points somehow is probably also useful. Although speed is always a plus, it is not essential.

Any code suggestions?

BTW - there are NOT going to be any tricky points - like a point very far away from the main set of points.
BTW - I've been using axis indices to represent the actual axis coordinate values (but don't worry about that if it complicates the code).

I can probably do this using brute force using a 2D array; so the purpose of this question is to use std lib algorithm functions to simplify the code and hopefully improve performance.
0
I am learning the BigO notation and I have a question which is related to homework:

def __str__(self):
return str(self.list)

Open in new window


If I cast an object, does Python iterate over it?
That is, would I have a O(n) here or is it just O(1)?

Thanks for your help
0
Consider algos/softwares that take keywords in one document and match them (possibly a kind of set intersection) with keywords in N other documents, possibly producing a match ranking.

a. Is there a specific name for this?
b. Are there implementations in Java and PHP?

Example use cases would be
  • patients submitting a list of symptoms and then software looking for matches against known conditions
  • applicants submitting skillsets and looking for potential job matches
  • dating websites
0
Hello,

       I am running through the securing TCP/IP of the N10-06 certification and having difficulty understanding the use of Hash. I get the process of using the algorithm to change the data, but what I don't understand is how that is applied and how it is decrypted on the receiving side to get the data. I have read that it is a One-Way system and cannot be decrypted, but if that is the case how does the recipient decrypt it? Is there a public key sent with the hash and what portion of my computer actually does the decryption. I've been Googling on this a while and reading Mike Myers book as well as Professor Messers video on it, but I am only getting vague descriptions on the intent and concept but not how its staged and executed. Does anyone have any sage advice on this?

Thanks!
0
Dear Experts,

Actually trying to analyze the machine learning logics behind in algorithms, for example the KNeighborsClassifier():

import pandas
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier()
print(model)

Open in new window


Could you please advise would it be possible to list the content of an algorithm in Python and with which syntax concretely? The above print(model) of course just provides some overall information about the algorithm, but not the content

Thanks in advance,
0
This could be an easy question and in fact, this is simple. But just wondering what's the proper algorithm for lucky draw chances?

Let's say in every new deposit amount of X get a no of chances of Y. Providing X = $1000, Y = 1

If there's a customer A credited $10000, he got 10 chances in this month.
If there's a customer B credited $2000, he got 2 chances in this month.
If there's a customer C credited $100, he got 0 chances in this month.
If there's a customer D credited $3500, he got 3 chances in this month.

By end of this month, how do I use a proper algorithm to pick a lucky draw winner? That's to pick a winner among this 15 chances.

One of the approaches is to create multiple chances in a temp table, and then random a position to pick the winner. But my question is what if the total no of chances is a very big number? Will the process of populating this temp table become slow?

Thank you.
0
Exploring SQL Server 2016: Fundamentals
LVL 12
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

A question about making puzzles for bridges (also known as Hashiwokakero or Hashi).  https://en.wikipedia.org/wiki/Hashiwokakero

Is there an algorithm to generate a puzzle given the size of grid?  Please provide algorithm or link to one if it exists.
0
Issue :SSL Certificate Signed Using Weak Hashing Algorithm      

An SSL certificate in the certificate chain has been signed using a
weak hash algorithm.      The remote service uses an SSL certificate chain that has been signed
using a cryptographically weak hashing algorithm (e.g. MD2, MD4, MD5,
or SHA1). These signature algorithms are known to be vulnerable to
collision attacks. An attacker can exploit this to generate another
certificate with the same digital signature, allowing an attacker to
masquerade as the affected service.

Note that this plugin reports all SSL certificate chains signed with
SHA-1 that expire after January 1, 2017 as vulnerable. This is in
accordance with Google's gradual sunsetting of the SHA-1 cryptographic
hash algorithm.

Note that certificates in the chain that are contained in the Nessus
CA database (known_CA.inc) have been ignored.      

Contact the Certificate Authority to have the certificate reissued.      

http://tools.ietf.org/html/rfc3279
http://www.nessus.org/u?e120eea1
http://technet.microsoft.com/en-us/security/advisory/961509

      
Plugin output:The following certificates were part of the certificate chain sent by
the remote host, but contain hashes that are considered to be weak.

|-Subject             : CN=XXX
|-Signature Algorithm : SHA-1 With RSA Encryption
|-Valid From          : Sep 30 12:06:43 2016 GMT
|-Valid To            : Sep 28 12:06:43 2026 GMT
0
The Original Data Sheet in the attached spreadsheet shows x, y coordinates and the corresponding true z values.
The Interpolation Sheet shows a different set of x, y coordinates (some overlapping), and the interpolated values imported from two different algorithms - bilinear and bicubic interpolation. There is also a column called z_truth.

My goal is to determine whether bilinear or bicubic interpolation is better.
It may be that for this initial data set that one sometimes does better than the other and vice versa.

To get a sense of how the interpolated data matched against the original data, I started copying rows from the Original Data Sheet to the Interpolation Sheet placing x, y coordinates from one near the other. If the coordinates match exactly, then there is only one copy. Otherwise, there are two copies where the original x, y coordinate falls between two x,y coordinates in interpolated sheet.

Currently, I am just going one row at a time from the Original Data Sheet and copying it to one or two locations in the Interpolation Sheet. This is taking too much time. I was wondering whether this copying could be automated.

If you could also help me with some metric to identify whether bilinear or bicubic interpolation is closer to the true values, I would appreciate that.

(I am now aware that my choice of original true value coordinates may not be so great; but this is a (good?) first start.

Thanks,
Paul
Compare_2d_Interpolations.xlsx
0
I will be given a set of X/Y points and their corresponding Z values. Z = f(X, Y), but I do not know the function f. The points will be clustered together and I don't expect pathological conditions. The local maximums and minimums will have extra sample points to help make the interpolation better. The goal is to come up with a smooth surface that represents the function f as close as possible.

The analyst providing me with the set of points of known XYZ points will also give me an XY rectangular grid; and at all the intersection points of horizontal and vertical lines, I need to provide a z-value.

One thought I had was to consider a point and look at 4 quadrants, and take the closest point in each quadrant, and using those 4 points or more to try to interpolate. Prefer to be able to use a curved surface to get the results rather than linear planes. One rule is that the final results will match the given XYZ points . The given points are known as anchor points or knots.

I am just looking for something functional. I am not interested in speed.

 I am not allowed to use binaries, so I will have to build from source code in Linux or Windows.

Thanks in advance.
Paul
0
I have here what I think is a classical O.R. (operations research) problem. I'm looking to formulate it mathematically and look at the options available to solve it.

We have a list of say 100 recipes.

These recipes combined use 400 ingredients.

The quantity of ingredients required for all the recipes could be defined by a matrix dimension 100 x 400.

We can combine recipes into meal plans, so that the ingredients required for a meal plan is the total of the ingredients required for each recipe in the meal plan.

Each ingredient has an associated cost, that varies depending on the quantity bought.

Say the cost variations can be expressed with no more than 5 cost buckets per ingredient. Eg.

Bucket, Cost / kg
< 1kg, £4.00
1-5kg, £3.50
5-20kg, £3.00
20-100kg, £2.80
> 100kg, £2.50

The ingredient costs can be expressed in two matrices each of dimension 400 x 5:
a) One matrix 400 x 5 giving the buckets for each ingredient
b) Another matrix 400 x 5 giving the unit costs per ingredient and bucket number (1 to 5)

A given meal plan will have a given ingredient requirement, with associated total cost determined via the above matrices.

Suppose we constrain the number of meals in the meal plan to say 4 meals, and these 4 meals must be different recipes. For simplicity (!) we have no other constraints for now.

Our objective is to choose our meal plan (4 meals) such that the total cost is minimised.

Questions:
1. How do we formulate this problem?
0
There are huge amount of different slot machines available online, like in the given list here bettingcasinoslots.com. All of them powered by own random generated algorithm. So I would like to know if there some strategies to play slots? I mean when you are playing for money and you want to make even a little profit and it would be great it the strategy does not include loosing money. Researches and publications are appreciated too.
0

Algorithms

An algorithm is a self-contained step-by-step set of operations to be performed. Algorithms exist that perform calculation, data processing, and automated reasoning. Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing "output" and terminating at a final ending state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input.

Top Experts In
Algorithms
<
Monthly
>