Friday, February 13, 2015

Excellence In Programming

Introduction

Whether you are a seasoned expert on programming or a newbie, sometimes you need
to redo the basic. This small document is written for redoing the whole thing,
and doing it right, and doing it right in the first attempt.
This book is language independent. Whatever language you are comfortable with -
solve the questions.
The initial programs are quite simple and it lets you spend some time with
basics and slowly picks up pace.
This book is and will be always in construction. I request all the readers to
send me reviews, questions and answers on pinnacle-mentors@googlegroups.com.
Whenever you encounter or solve a small programing question - convert it to a
question and send that to me. I will give proper credits and add the question.

Use the repository https://github.com/abrrba/pinnacle-blogs for checking-in the code.



Loops

Print the following patterns.
  1. ********
    
    ********
    
    ********
    
    ********
    
    ********
    
  2. *****
    
    ****
    
    ***
    
    **
    
    *
    
  3. *
    
    **
    
    ***
    
    ****
    
    *****
    
  4. ####*
    
    ###**
    
    ##***
    
    #****
    
    *****
    
  5.     *
    
       **
    
      ***
    
     ****
    
    *****
    
  6. ***********
    
    ***** *****
    
    ****   ****
    
    ***     ***
    
    **       **
    
    *         *
    
    **       **
    
    ***     ***
    
    ****   ****
    
    ***** *****
    
    ***********
    
  7.     *
    
       ***
    
      *****
    
     *******
    
    *********
    
     *******
    
      *****
    
       ***
    
        *
    
  8. *********
    
    *******
    
    *****
    
    ***
    
    *
    

Arrays

  1. Find the sum of all the elements stored in the array?
  2. Find the product of all the elements stored in the array? What can be the possible problems here.
  3. Find the maximum and minimum element of an array.
  4. Find the average of the array.
  5. Find the median of the array.
  6. Find the element which has occurred for the maximum number of times in an array. Similarly find the element which has occurred minimum number of times.
  7. Fill an array with the multiples of 3, then remove the numbers which are divisible by 5. Fill the empty spaces so generated with -1.
  8. Fill an array with random elements.
  9. How will you solve the second problem of the basic level.
  10. Sort the elements stored in the array using all the sorting methods like Bubble Sort, Insertion Sort, Selection Sort, Merge Sort, Quick Sort.
  11. Write a program to multiply two 2-D Arrays.
  12. Write a program to find the sum of a 2D array
  13. Write a program to find the transpose of a 2D Array.
  14. Write a program to find the inverse of an array.
  15. Write a program to find all the prime numbers in a range of 1 to N. N is the user input.
  16. Write a program to find the factorial of a given number.
  17. Write a program to find the sum of al the numbers till N ( N is the user input).
  18. Print the geomatric progressoion, Take the relevant input.
  19. Print the arthimatic progression, take the relevant input.
  20. Write a program to convert the epoch to date.
  21. Write a program to print the spiral of numbers.
  22. Write a program to print the sum of all the numbers in a 2 D array.
  23. Write a program to print the multiplication of all the elements in a 2 D array.

Character/Sorting Arrays

Write a program for
  1. Finding the character which is alphabetically highest, use ASCII values.
  2. Find wether a string is a palindrome or not.
  3. Concat the same string to itself. (Eg. HelloWorld -> HelloWorldHelloWorld) #. Insert the word “Hello” in the middle of the words in an sentence. (Eg. How are You? to How Hello are Hello You hello?)
  4. In the above program do not use too much of extra space, do not use a new array.
  5. Find if the other string is a substring of the other string.
  6. Find the number of words in a string. (use space as a word separator).
  7. In the above program, make sure that multiple spaces are counted as one ” ” is counted as ” “
  8. Parse a string and find the number of vowels, spaces, special characters.
  9. Parse a string and reverse all the words in the string.
  10. Reverse the characters of string.

Data Structures - Bitmap

  1. Make a library for bitmap. The function calls will be void * init_bitmap(size_of_bitmap). set_bit(int), unset_bit(int), check_bit(int).
  2. Use the bitmap to check for the characters present in a string.
  3. Use the bitmap to check for the numbers in a array of integers (1 to N).

Data Structures - Arrays

  1. Implement a small dictionary application where the users can search for the meaning of a word. use linear search.
  2. Sort the elements and do not binary search. Implement the above dictionary, find the runtime.
  3. Sort the elements and do binary search, check the runtime.

Data Structures - Trees

  1. Implement a binary tree.
  2. Implement a binary search tree.
  3. Implement a binary search tree library.
  4. Using the binary search tree library, make a dictionary. Check the runtime for searching the words
  5. If your language support tree as data strutures use the feature and implment a dictionary, See the difference between the runtime. Find out why there is a diference.

Data Structures - Hashing

  1. Implement hashing - use a simple hashing function, make sure that you can handle collisions.
  2. Using the above code of hashing, insert the elements of the dictionary in your hash. Check the number of collisions. How can you reduce the collisions.
  3. Now with a better algorithm for hashing, test the dictionary words and see the number of collisions.
  4. Check the runtime, when you are using your new function.
  5. Now use the hsearch() for creating a hash, Now check the runtime.
  6. Now use the SHA1 hashing for creating a hash, now check the runtime.

Files

  1. Reverse all the characters in a given file. Use the above written code for string reverse.
  2. Reverse all the sentences in a file. Use the above written code. (I love you to you love I).
  3. Learn how to read/write a file using C/Java Programming (fopen, fread, fwrite). Write a simple data base application where you save the name, birthDate of students. make another table to save the marks in maths, chemistry, and physics of the students.
  4. In the above program, generate the following reports. Number of students failed/passed in the subjects. Topper and the lowest scorer. Find the number of students whose aggregate is more than 90%, 80%. List the students.
  5. If you can easily generate graphs (like in Java) then use graphs to show the results. This will make your looping concepts better.
  6. Use a file to save the word and the meaning. Whenever user searches for a word, read the file, line by line and then check for the element. Observe the runtime.
  7. Use a file to save the word and the meaning, but this time, read the whole file, take the whole contents in ram and then search for the contents.
  8. Read the same file, now save the contents in a Hashing table and then search. See the amount of code you could reuse which you wrote earlier. Can that be improved. How? Re-implement the above written code if required.
  9. Read the same file, save the contents in a tree and then search. See the amount of code you could reuse which you wrote earlier. Can that be improved. How? Re-implement the above written code if required.
  10. Read the same file and save the contents in an array and then search. See the amount of code you could reuse which you wrote earlier. Can that be improved. How? Re-implement the above written code if required.
  11. Observe the difference in the run time of the above 3 approaches of writing a dictionary.


Read About

  1. Sieve of Eratosthenes
  2. Rabin-Karp algorithm

More Problems

  1. Find the Prime numbers using Sieve of Eratosthenes
  2. Find the substring using Rabin-Karp algorithm.