strstr() vs Knuth Morris Pratt - strstr

Can someone please help me understanding which one is more efficient strstr() or KMP as recently I was doing a question on SPOJ and found that strstr() was in one way or other faster than KMP..
someone please explain the mystery behind this..

You are comparing apples with pears, strstr() is a function to find substrings, KMP is an algorithm to do it, so strstr() could theoretically be implemented using KMP. You need to find out which algorithm is the strstr() in question implementing to give a statement.
Take a look at this answer and the comments on it.

Related

SCIP: Find a feasible but not optimal solution to a large LP

I asked this on the soplex mailing list, but no answer yet:
http://listserv.zib.de/pipermail/soplex/2022-August/000001.html
I tried scip, and it took 30sec. Maybe because it performs pre-solve.
Is there an easy way to achieve my objective:
Specify an initial solution (something that I have, which is better than a random init), and use the solver for a limited time to find a better feasible solution
https://math.stackexchange.com/questions/4510587/find-a-feasible-but-not-optimal-solution-to-a-large-lp
Reply from the mailing list:
http://listserv.zib.de/pipermail/soplex/2022-August/000002.html
To find only a feasible solution, you can just remove the objective function. This will terminate as soon as feasibility is attained. Then, you could plug in this solution as a starting basis - I don't think this is going to help much, though.

Difference between Merkle–Damgård and sponge-function used in KECCAK

Hello to the nice Stackoverflow community!
I have difficulties understanding the difference between the Merkle–Damgård construction and the sponge-function used in KECCAK.
The Merkle–Damgård Construction takes in the message-blocks iteratively, but as of what I've found in descriptions, doesn't a sponge function do the same? Illustrations of both look quite similar and I just don't find an explanation I really understand.
Can someone explain the difference somewhat easier?
So I expanded my search for sources using youtube videos. If someone has the same question, I think it is very well explained in this Video:
https://www.youtube.com/watch?v=IUI5C9stAEM
The explanation starts at minute 18. Hope this helps someone.
Have a nice day!

How to go about learning R-tree?

I'm currently taking part in a "Data modeling" course. And for my final project, I need to make a research about "R-tree index for spatial searching". However, I'm not at all familiar with many concepts concerning the subject matter (spatial data, multi-dimentional data,...).So, I read the wiki and as I encountered new concepts, I tried to learn them on the way.
However, I don't think this top-down approach is a very efficient way to go about this. Thus, I'd really appreciate it if anybody can suggest a way/lists of things that I need to read up in advance, in order to understand R-tree, and hopefully make some kind of implementation out of it.
Start with the original paper and check out (shameless self promotion) a basic R-Tree implementation in Java.

Does anyone have a SlickGrid wrapper for Haxe?

I am using the Haxe multi-platform programming tool (http://haxe.org) which, among other things, can generate JavaScript output. I would like to know if anyone has already done a "wrapper" library to interface Haxe with SlickGrid.
Doesn't look like one exists yet... sorry!
Unless someone has made one but just not shared it. Could be worth asking on the haxe mailing list / google group? You'll get a wider audience than on stack overflow.
If it looks like no one has done it, you can write your own... it's probably quite do-able. And not too hard either. I'd be happy to help you figure it out as you go... cause I might want to use it one day too :)
If you do decide to take that route I think the best option is to post on the mailing list, and we can help you out from there. There's also a document on the wiki with some instructions:
http://haxe.org/doc/js/extern_libraries
This stuff is always a bit daunting when you first get started, but don't be afraid to ask for help and hopefully you'll be up and running in no time.

How to explain to a high school hacker that indenting and verbose variable names are good things?

He is good programmer (won some competitions) but he absolutely ignores formatting.
He consider i, j, k beautiful... I hope he won't find out about existence of goto keyword.
Write some code in his "style" and then ask him to read it and explain to you what it is doing.
What's good for the goose and all...
I told my students (post-secondary) that they had the choice of writing code well or of me writing their assignments in the same sort of way that they wrote their code. I told them I would write the following program:
take the text of the assignment
lookup a number of the words in a thesaurus and replace them with obscure versions
remove all punctuation
remove all whitespace
convert everything to lower case
insert random whitespace
capitalize random letters
They could then have the assignment... hey its "right" (all of the words are there) good luck understanding what the assignment is though.
Oddly the complaints stopped at that point :-)
I also compared it to English. We use paragraph breaks, capitalizations, etc... as a convention. When someone chooses not to follow the conventions it makes reading much harder.
tell him about python :)
Make him maintain somebody else's code that's written the way he writes. Then make him maintain somebody else's code that was written with good style.
A combination of FORTRAN77 and Python should sort him out.
Code maintainability
Stuff I didn't care in high school neither :)
Write a bunch of "his" code and ask him to find a particular piece of code.
Give him some badly written code with a bug in it and ask him to find the bug.
Well, if he plans to do this for a living just explain that he will have a very rough life on a real team if he doesn't at least make some effort to follow the team standards. If he doesn't plan to do it for a living, don't worry about it.
You also might determine if there is anyone(s) that he admires. If there is then there is a pretty good chance that they follow standards.
I would point out that having clean code is a sign of a organized and intelligent mind. However, the real killer will be when he writes a large amount of code. I doubt you will be able to convince him because more than likely he is getting excited about the logic of the app and not the process. It will take experience to teach him a harsh lesson. So here are my suggestions.
Give him a project full of messy unformatted poorly named code and let him suffer.
Encourage him to work on a project with a large code base and let him see how well he remembers his own variable names after the 1,000th source file.
You probably can't.
Some people just don't get it.
I use self-describing variable names both at work and in private where noone tells me to. I also got some appreciation at work for using long and understandable names.
If a guy does not do it neither for himself or for your project then you've got that kind of guy. Show him some docs on the source code style policy. Explain why this is important.
You begin to use the right naming convention after you've got some experience and you see how and why this was useful. Without experience it's just an abstract talk.
P.S. Sometimes I get stuck with variable names because I'm not sure if this particular name does conform to the common linguistic style I use in the current project or how would the name scale on the high litterature language. The problem of using bool b1 vs. bool IsSomePropertyAvailable has never come up since the first university years.
I'm pretty sure you can misconfigure a code beautifier to present such horrible output. Obfuscaters are common, and do essentially the same thing (short useless variable names, no indenting, poor use of whitespace).
Give him the assignment of taking an existing program with his style and adding a trivial feature.
Also, take code he wrote 6 months or more ago and give the same assignment.
-Adam
Maybe he's not ignorant, maybe he's just inspired by Kernighan & Pike.
i,j,k is fine for loops.
I personally prefer using 1 letter vars in iterations...
foreach ($test as $t)
{
}
beautiful :D