Tech Guide Blog

Tech Guide Programming Tutorial Tips Tricks

Archive for the ‘Programming’ Category

Boyer Moore String Searching Algorithm

Posted by Admin On June - 23 - 2009

This time, we will talk about Boyer Moore string searching. It’s not like brute-force, it will search a substring from the back and go forward till the first char of string. For example, we search a substring EXAMPLE within HERE IS A SIMPLE EXAMPLE string. I can’t explain it well, so this below maybe rather confusing.

EXAMPLE
HERE IS A SIMPLE EXAMPLE
's' is not in EXAMPLE substring, jump for EXAMPLE length = 7
       EXAMPLE
HERE IS A SIMPLE EXAMPLE
'e' is not same as 'p', so jump for the last char of EXAMPLE to 'p' EXAMPLE = 2
         EXAMPLE
HERE IS A SIMPLE EXAMPLE
'a' != 'i', jump for distance from 'e' SIMPLE to the front 'e' EXAMPLE sub string = 6
               EXAMPLE
HERE IS A SIMPLE EXAMPLE
'e' is not same as 'p', so jump for the last char of EXAMPLE to 'p' EXAMPLE = 2
                 EXAMPLE
HERE IS A SIMPLE EXAMPLE
compare till end, found.

For the code, it’s a little weird, made by myself with many helps. It just find the index of string if it found the sub string within the string. You can use a table to save all chars shift value.

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <windows.h>

void main()
{
	char string[1000], substring[1000];
	int strvalue[256], i, j, diff = 0, count = 0;

	printf("Input string: ");
	gets(string);
	printf("Input substring: ");
	gets(substring);
	for (i = 0; i < 256; i++)
	{
		strvalue[i] = -1;
	}
	for (i = strlen(substring) - 1; i >= 0 ; i--)
	{
		if (strvalue[substring[i]] == -1)
			strvalue[substring[i]] = i;
	}
	for (i = 0; i < 256; i++)
	{
		if (strvalue[substring[i]] == -1)
			strvalue[substring[i]] = strlen(substring);
	}
	i = strlen(substring) - 1;
	while (true)
	{
		for (j = strlen(substring) - 1; j >= 0 ; j--)
		{
			if (substring[j] == string[i - diff])
			{
				count++;
				diff++;
			}
			else
				break;
			if (count == strlen(substring))
			{
				printf("%d", i - diff + 2);
				getch();
				exit(0);
			}
		}
		diff = strlen(substring) - strvalue[string[i - diff]] - 1 - count;
		if (diff > 0)
		{
			i = i + diff;
			diff = 0;
			count = 0;
		}
		else
			i++;
		if (i > strlen(string) + strlen(substring) + 2)
			exit(0);
	}
}

Popularity: 67% [?]

How to Set Up Listener Oracle 10g

Posted by Admin On May - 24 - 2009

This post is the second part of how to install Oracle Database 10g. After you finished installing the database, you can start by installing the listener. Just open Net Consfiguration Assistant in start menu -> all programs, usually found at Oracle - OraDb10g_home1 (default name in start menu) -> Configuration and Migration Tools -> Net Configuration Assistant. But first you have to set up the Oracle Net Admin (Net Manager), this also in Configuration and Migration Tools.

oracle-net-manager

click to enlarge

Just fill the Oracle home directory with your Oracle home directory like the picture above and SID with your Oracle service name. Save network configuration and exit (File -> Save Network Configuration).

Back to Net Configuration Assistant and you will see the configuration wizard.

click to enlarge

click to enlarge

Choose Listener Configuration -> Add -> fill your listener name -> TCP (Selected Protocols) -> use the standard port number -> no -> next -> done. Now the listener have already configured.

Popularity: 100% [?]

How to Install Oracle Database 10g part 1

Posted by Admin On May - 3 - 2009

These days, who don’t know Oracle? Many firms and DBA use this software to keep them earn money and keep their database that contains many sensitive information. But unfortunately, installing Oracle is a bit difficult, because for the beginner, they don’t know many words, words that they never hear before, and moreover Oracle gave many configurations that I think those are too difficult to understand and not likely too necessary to show those settings configuration, but these may be important for experienced user to do those. I think Oracle should give two options for installation, express and custom like another software.

step1

Setup Wizard

Back to topic, after you insert the Oracle DVD or after you download it, just start install Oracle Database (setup.exe from Database).

This picture above is the first step you install the database, just choose basic installation and choose the installation directory. In this page you have to choose whether you create starter database, created by Oracle itself, or you can create your own database later after the installation, for beginner I suggest you choose to make Oracle starter database, just choose your global database name and password. Many people think this password is for SYS and SYSTEM username, but they’re wrong. These people can’t log on into Manager Console as administrator (SYSTEM) because of this. You have to set SYSTEM password manually later. Just click next and so on until you get firewall warning, just click unblock to javaw.

firewall javaw

Unblock javaw

Just wait until the installation is finished and click exit. I will show you how to create the database in the next post. Hope I have enough power to post it! Any questions?

Popularity: 30% [?]