Every work day when quitting time approaches (around 05:00 PM) I check my to-do list. One thing I had for the day was to check is there is a method in a Java class to shuffle the contents of an array. This is a nice mechanism to have in your toolbox. For example, if you want to load a binary tree search (BST) and the data is sorted, the tree will basically load like a linked list. In a BST you can typically find an element in O(log(n)). But if the elements were inserted sorted, the search is performed in O(n) which is slower than O(log(n)). In such cases you can just shuffle the array and then load the BST. Continue reading “Shuffle Array – Java”
Let’s define the requirements for this algorithm. We are given two sets of integers. The idea is to check if the sets are permutations of each other. If they are, return YES; otherwise return NO.
First let’s make sure we agree with the definition of permutation. For the sets to be permutations we must have the same number of elements in both sets. Each set must have the same counts for each entry. For example if the sets are:
1 2 3 4 5 6
6 5 4 3 2 1
Then we would return YES. Both sets have the same length (six in this case) the numbers are the same on both sets, and the count of each number matches (one in this case).
7 6 5 0 9 7
7 6 1 0 9 7
Given that 5 is in the first set, but not in the second and 1 is in the second, but not in the first, these are not permutations of each other so we would return NO. Continue reading “Is Permutation”
A few minutes ago my wife called me up to the kitchen to help her. She needed Grand Maniere for an Italian nonna’s apple cake she was making. In addition to the apples, she likes to add raisins soaked in liquor. She decided to use Grand Maniere because she found a large bottle in the liquor cabinet. She could not remove the cork so she called me for help. As I was attempting to open the bottle I asked if she remembered when we got it. It seems that we bought the bottle when we lived in Maryland; that was many years ago.
The cork disintegrated when I was opening the bottle. The bottle was standing up and with the years the cork dried up. We keep our wines in an angle in our cellar, but the hard liquor in our cabinet is standing right side up. We seldom consume hard liquor. The Grand Maniere smelled fine and my wife was able to soak the raisins. Each time she fixes this dessert she tries to make it a little different. In my opinion, apples, raisins and walnuts go very well together. Will let you know in my next post how this cake turned out. Continue reading “Java Streams”
Time flies when you are having fun; at least that is how the saying goes. Today is Saturday and I am on my second and last block of the day. After breakfast I prepared the pizza dough and put it in a bowl covered with plastic film for it to rise. During the break between blocks my wife and I checked the dough. It is touching the plastic. It has tripled its size.
For lunch we are going to make and bake a few small and thin pizzas. We are going to mix and match toppings and are expecting to have a few leftover pizzas. Tomorrow we are going to make “baba” (an Italian yeast cake). Will have a few and the rest with the pizzas will be delivered to my oldest son. Continue reading “Priority Queue”
UPDATE – Added a couple classes and implemented reverse method to reverse the linked list in segments. I will leave this post and move on to a different subject on the next one.
It is a cold Sunday in the Twin Cities of Minneapolis and St. Paul. The forecast called for a winter storm starting last Friday around noon ending Saturday afternoon. The forecast called for 6 to 9 inches of fresh snow and wind blowing up to 45 mph. Due to the forecast, people visiting the area last week or people with plans for the weekend decided to move their schedules and leave the Twin Cities earlier. Airports were crowded and flights were overbooked. When all was said and done, the Twin Cities received about 6 inches of fresh snow. Some places further out received considerable higher amounts (e.g., Hovland, MN 16.5 inches).
Continue reading “Stacks to Reverse Order”
Earlier this morning I spoke with my friend Gustavo. We know each other for most of our lives. We started kindergarten together. Today we are both married to our respective spouses and have kids and grand kids. We get on Skype about once a month always on a Friday at 06:00 AM and have a great time catching up.
He studied geology and currently owns a company that was started by his dad. He bought out his siblings and with time has grown his company quite a lot. Last time we got together was for a geology convention last year in the Twin Cities of Minneapolis and St. Paul. We had a great time with our spouses dining, dining and doing tourist things. The only thing of the trip they did not like was the snow. The show was in February and there was a lot of snow and of course cold temperatures. Continue reading “Finding Intersection”
It is Sunday at 07:36 AM in the Twin Cities of St. Paul and Minneapolis. I try to get in at least a couple of 2-hour blocks each weekend day. I can see from my home office that the day is still dark although sunrise occurred at 07:14 AM.
Lately I have not posting much due to the fact that I am working on software that I would like to have finished by the end of this week. I like the project because the requirements were quite vague. In addition, the hardware when I received it had a couple issues. After contacting the vendor I had to wait a week before I could take the unit to be repaired. It just took a few hours for me to drive to the OEM’s office, have it looked at and repaired and get back home. Very knowledgeable technical support! Continue reading “Java Static Initializer Block”
It is a gloomy Tuesday in the Twin Cities of Minneapolis and St. Paul. It rained last night. It is quite damp. It is a typical fall day in this part of the country. The only difference is that in the past two years the lawns are green instead of being brown. I do not know for sure the cause for the climate change which is a very controversial topic, but for sure something is changing.
I am going to quickly cover some operations with Lists in Java. Will use lists on my next post. I need a refresher given that lately I have been working with C/C++ and after a few weeks (which in this case included a two week holiday) of not working with a programming language I tend to stumble with the syntax. It all gets back after a day or so of concentrating on the specific language. Continue reading “Java Collections List”
Lately I have been quite busy with work and have not had time to write posts for this blog. Today I woke up shortly after 04:00 AM. Typically I go back to sleep until my alarm goes off, but today I had the desire to get up and so some on-line reading. I found the article Understanding Software Design Patterns by Bryant Son. The article deals with three design patterns: Singleton, Factory and Observer. Given that I have generated at least one post Singleton Threads using the Singleton pattern, I spent time reading the article and experimenting with it. I will cover the last two patterns in a different post. Continue reading “Understanding Software Design Patterns”