Wednesday, October 17, 2012

Day 2 -- Learn Introduction to Computer Science and Programming


As we discussed in our earlier article about Basics of Computation,

If you have missed the Day-1: 

Please Visit: http://itsmyslife.blogspot.in/2012/10/first-day-at-introduction-to-computer.html

Today we discuss about, Problem Solving.


Q: What is computer science?

A: Most of them believe that Computer Science is nothing but Programming.

This is the most Common Misconception.

 

Q: What is Programming?

A: Programming is a tool of computer science, to analyze large amounts of data.

 

Example – Phone Book

In old days, Before Mobiles were not developed: All of us used to store the Phone Contacts in a Phone Book.

If we want to search for “Karthikeyan”, we have to flip each page and search until the Contact is found.

This is an inefficient method.

Now we can reduce our search time, by flipping to the middle of the Phone Book.

Let divide the problem into two.

We know ‘K’ doesn’t lie in the right part of the book, let’s throw away this part.

Now we start searching in the left part of the book and Now again flip to the middle of the Left Part of the Phone Book.

We know ‘K’ lies in the right part of this book; let’s throw away the left part.

So now we again start searching the right part.

As we continue tearing the book in half and throwing away part of it, we will eventually be left with a single page on which the name “Karthikeyan” appears.


Approach – To Solve a Problem

In the graph below, the first steep line (n in red) represents the approach of turning one page at a time.

The second steep line (n/2 in yellow) represents a slightly improved approach of turning two pages at a time.

The curve (log n in green) represents our “tear and throw away” approach. As the size of the problem grows, the time to solve that problem doesn’t grow nearly as fast.


 In the context of this problem, n is the number of pages in the phonebook. As we go from 500 to 1000 to 2000 pages in the phonebook, we need only tear the phonebook in half one or two more times.

Algorithm : Counting Number of Students in a class


Let’s solve this problem...
  1. Everyone in the class should stand up and the first person should think of the number ‘1’
  2. Now pair off with second person – (example: number - 2) standing beside to first person, add the first number with second and adopt the sum as the new number to the second person.
  3. Now the first person should sit down, the second person should go back to step 2

With this algorithm, it’s very easy to break the problem into small pieces.

Binary Numbers

Everyone has studied in the schools, that computer deals with 0’s and 1’s.

These 0’s and 1’s comprise binary numbers system.

Binary means “Two”...Every solution to a problem represents in binary numbers.

In Real World, If the Switch of the Bulb is OFF – Then it represents 0 and

If the Switch of the Bulb is ON – Then it represents 1.

ASCII

As we have seen, Binary is used to represent the numbers.

We now represent the alphabetic characters in numbers.

ASCII is American Standard Code for Information Interchange. It is an encoding system.

For example, an uppercase “A” is represented by the number 65 and a lowercase “a” is represented by the number 97.


Byte
A byte is a sequence of 8 bits.

----------------------------------------------------
Continued...

Happy Learning..Happy Programming :)

1 comment: