import java.io.File; import java.io.IOException; public class RecursiveFileDisplay { public static void main(String[] args) { File currentDir = new File("."); // current directory displayDirectoryContents(currentDir); } public static void displayDirectoryContents(File dir) { try { File[] files = dir.listFiles(); for (File file : files) { if (file.isDirectory()) { System.out.println("directory:" + file.getCanonicalPath()); displayDirectoryContents(file); } else { System.out.println(" file:" + file.getCanonicalPath()); } } } catch (IOException e) { e.printStackTrace(); } } }
Tripleone
Saturday, April 9, 2016
Display all filenames in a directory
HashTable and collisions
What is an good Hashfunction?
- Evenly distributed
- Easy to compute
- Less collision
lambda (load factor) = N elements / T(table size)
How to Handle collisions?
Separate Chaining
The idea is to keep a list of all elements that hash to the same value. Have a linked list and add the element at the beginning for the linked list.
Advantages -
- Better space utilization for larger items
- Simple collision handling - search in linked list
- Overflow - Can store more elements in the hashtable than the number of of cells.
Open Addressing
Linear Probing - In case of a collision problem to the next place until, we find an empty space.
Other techniques are Qudratic probing and double hashing.
Disadvantages
Linear Probing - In case of a collision problem to the next place until, we find an empty space.
Other techniques are Qudratic probing and double hashing.
Disadvantages
- As long as the table is enough, a free cell can be found.
- Worst even if the table is empty but blocks of occupied cells are formed - Primary Clustering
Acceptable if the Lambda < 0.5
Lambda here is average number of probe for all searches and insertions
Quadratic Probing - Similar to linear probing, instead the collision function f(i) = i^2. This helps to get away from primary clustering.
Double Hashing
- The second hash function should never be equated to zero
Tuesday, April 5, 2016
Tuesday, March 9, 2010
What a Definition !!!
TripleOne : Who is an allrounder ?
Nag : Batsman kante bowling baaga vesevadu , bowler la kante batting baaga chese vadu
All : Roflmao............
Nag : Batsman kante bowling baaga vesevadu , bowler la kante batting baaga chese vadu
All : Roflmao............
Confused Mind
16 th January , a black friday. I almost completed my Biogen MSL project and was about to leave after getting issued a new laptop and then I get a news from our HR that today would be my last day at Kuliza , as an permanent employee and from now on I will be serving on notice period. They took over my laptop / other works and handed over me a heavy cheque. A small conversation with CEO in which he tells me that this is very much normal scenario in a software industry and since you have good background you will land up in good company in the near future 3 - 4 weeks. My face turned red, as obvious came out with a grin thinking nothing much to do with crooks . Btw all this happened in a span of 3 hrs.
Now then , blah blah blah ......... blah blah blah........ 1 month of unsuccessfull interviews / aptitude tests took the pulp out of me and now the frustration is into higher levels. Hang on , all this makes upto just Phase -1.
Now then , blah blah blah ......... blah blah blah........ 1 month of unsuccessfull interviews / aptitude tests took the pulp out of me and now the frustration is into higher levels. Hang on , all this makes upto just Phase -1.
Subscribe to:
Posts (Atom)