Tuesday, January 20, 2015

Algorithm to determine if a string has all unique characters

// Program to determine if a given string is unique.

#include <iostream>
#include <string>
using namespace std;

bool is_unique(string str) {
 if (str.length() > 256)  // assuming ASCII string (requires 256 bits storage)
  return false;

 bool a[256] = { false };  // create an array of 256 elements, initialize to false

 for(int k = 0; k < str.length(); k++) {  
  int ascii_val = int(str[k]); // get the ascii val of char

  if (a[ascii_val] == true) // chk the ascii_val index of array a.
   return false;  // if it is true, it means we have already
      // seen this char, so return false

  a[ascii_val] = true;    // otherwise set it to true to mark it as
            // a char we have seen already
 }

 return true;
}

int main() {
 string test0 = "";
 string test1 = "Michael";
 string test2 = "Jackson";
 string test3 = "Hello World";
 string test4 = "Australia";
 
 bool a = is_unique(test0);
 bool b = is_unique(test1);
 bool c = is_unique(test2);
 bool d = is_unique(test3);
 bool e = is_unique(test4);

 cout << test0 << " is " << a << endl;
 cout << test1 << " is " << b << endl;
 cout << test2 << " is " << c << endl;
 cout << test3 << " is " << d << endl;
 cout << test4 << " is " << e << endl;

 return 0;
}

Wednesday, August 28, 2013

Technical Communication | Writing for Engineers

Reading a manual for building a bike or a textbooks are a couple of examples of Technical Communication. Graphics are an important aspect in a manual or textbook because it can help your audiences understand or carry out tasks. Technical Communication is produced by either technical professional, who produce professional emails, reports or letter, or technical communicators, who produce manuals or websites. Technical Communication is a very important part of your professional career. Once you start your professional job in your field of engineering, you will be writing email to you bosses, writing lab reports, or proposals. Your advancement at your particular job depends on your technical communication skills because your boss does not someone who can write a scientific report, forgets to write the subject in an email or have grammar mistakes.

According to the book "Technical Communication" by Markel, their are eight "Measure of Excellence in Technical Communication": Honesty, Clarity, Accuracy, Comprehensiveness, Accessibility, Conciseness, Professional Appearance and Correctness. Honesty is the most important because it can mislead your reader. If your write or present forged or fake data or article, you can face legal charges. Writing or presenting clearly is also an important factor because you want your reader or presenter to understand you without a "Huh.." on their face. Being Accurate about your facts is also a factor. You want as many resources as possible to support your data or facts. When you write a paper, you want to be as comprehensive as possible. You can attach your resources that supports your ideas or data to your paper. Accessibility is also a key, you must always keep a digital copy of your paper or provide it using email or web site. Thinking about conciseness can help you reach a variety of reader. If you paper is concise and easy to read, you can reach to busy people. Your paper must also look professional and neat because that attracts most readers. Lastly,their must not be any at all grammatical mistakes, everything must be spelled correctly.

If you can follow "Measure of Excellence in Technical Communication", you can look forward to a professional career where you will have freedom to present your ideas or proposals and they will be respectful either accepted or denied.

Sunday, July 7, 2013

Introduction to Sets | Discrete Mathematics

How to specify Sets?
Set is a collection of elements. For instance, If S is the set of all integers from 1-1000, then the number 500 is an element of the set S. A set is specified by writing elements in braces. For example, {apples, oranges, mango's} is the set whose elements are apples, oranges, mango's. If A is a set, the notation x A means that x is an element of the set A. The notation x A means that x is not an element of the set A.