Reversing a singly linked list in a single pass

Today I’d like to give codes and solution to reverse a singly linked list in a single pass and not using superfluous storage.

Off course there is a solution if you duplicate list, put all values into a vector or array, and other not efficient ways to accomplish this task. Recursive solutions could also be proposed. But iterative solution is the best way to solve this problem. Because if you use recursive method, there will be superfluous, and not necessary method calls and extra stack storage will be used for each local variables, and it won’t be best shot because if number of nodes in linked list is too much then you’ll probably exhaust your stack memory.

Continue reading

Spliting a singly linked list into two sub-lists from the middle node in one pass

This is a puzzle like problem for linked lists. We’ll use similar solution for our code in Finding The Half Of Linked List in Single Traversal. But we’ll add some spice to the code in order to convert solution to be applied to this problem.

Ok let’s have a look to our proposed solution. Continue reading

Word Generation from Custom Alphabet – Base 26 Operations

Recently I’ve developed a brute force password cracker tool (can be found in post BruteForcer). I think it deserves to mention some design characteristics of the application. I’ll mention Alphabet Generation in other words base 26 operations that is used and needed for many programmers.

Alphabet to Generate

Our generator should output strings based on the alphabet that we provide. For instance if our alphabet was:

Alphabet = “ABC” Continue reading

BruteForcer – Simple Yet Powerful Brute Force Password Cracker

I’m very forgetful these days. Even though I could not remember what I ate yesterday or what I wore, I have password protected everything. As a result, most of the times I have ended up with a locked zip, tar.gz or other file. Yesterday I had same experience and I decided to write a brute force python application to crack my password protected file.

Unfortunately I knew that it would take time for the app to crack with brute force technique, but I could use some tricks to improve performance. For instance I can limit the alphabet to attack (most of you use same pattern, special characters, password scheme for encryption) which would save time significantly.

Continue reading

Price List Application (Flask, SQLAlchemy, pyQT4)

My elder brother needed an application to manage price lists of his wholesalers and dealers. Products’ prices that he is following are subject to change daily because exchange rates may change daily and it may be very hard to find optimal price for a product if it can be obtained from multiple dealers. So I decided to help him with an software solution. Price lists and displays support utf-8 (as they can be seen in screenshots – Russian language price lists are used for tests).

Continue reading

Greatest Common Divisor (GCD) of Big Numbers – A Recursive Approach (C++)

In this post I will provide mathematical background and C++ implementation of greatest common divisor (GCD) calculation of big numbers problem. Problem can be described as:

You have two numbers to calculate their GCD. First number is very big, let say 250 digits long. Other number is not so long, maybe less than 6 digits. How  do you calculate GCD of these two numbers. Continue reading