Browsed by
Category: Algorithms

Selection Sort Implementation in Java Example

Selection Sort Implementation in Java Example

Selection Sort Implementation in Java Example:   Psudeocode for selection sort: Take an array with N elements (say new long[]{3,3009, 76,172,271,2}) Outer for loop to iterate all the elements in the array. (index starts from 0) Create a currentMinimum variable with index value(initially 0) Create a nested for loop to iterate from innerIndex(index+1) (because till index it is already sorted, initially it is 0, means not sorted) 2.2.1 if array[currentMinimum] > array[innerIndex] then assign currentMinimum = innerIndex; 2.3. Outside of…

Read More Read More

563 total views, 1 views today

Binary Search Implementation in Java Example

Binary Search Implementation in Java Example

Binary search is one of the most important searching algorithm to know and understand for search functionality. In the below we are going to return the array position based on the searching number existence in the array, if it does not exist then we will return -1.   Binary search basically works this way, 1. Numbers should be sorted in the array before beginning with binary search. 2. Check the middle number with the number which need to be searched…

Read More Read More

507 total views, no views today

Singly Linked List Algorithm Implementation Java Example

Singly Linked List Algorithm Implementation Java Example

Linked list is nothing but having the link of the next node with the current node, this gives lot of advantages like directly doing any manipulation on particular node instead of iterating everything for all the operations like we do in arraylist.   Why we need Linked List ?   Array does not help us for these things, so forced to go for linked list.   1. No dynamic size: All the time we can’t mention the correct required size,…

Read More Read More

666 total views, no views today

Reversing a string using Stack Implementation

Reversing a string using Stack Implementation

In our previous post, we saw how to create a custom stack implementation in java.¬†Today we are going to extend the same implementation to perform additional operations like reversing, checking empty or full etc. Approach 1: [Simple & Best Approach]   We have used the same Stack class from this post [Java Stack Implementation Simple Example]¬†with small modification like array type changed from int to char.   Modified Stack Class: [Stack.java] package in.javadomain; public class Stack { char item[]; int…

Read More Read More

586 total views, no views today

Java Stack Implementation Simple Example

Java Stack Implementation Simple Example

Recently I started refreshing the backbone of CS, data structure and algorithms. As part of that I wrote a core stack implementation functionalities like Push and Pop in java. I also wrote isEmpty() method just to make use in loops and stuffs like that.   I want you to try writing the stack(LIFO – Last In First Out behaviour) implementation program yourself with these key points, Create a class named Stack Have an array to push and pop (store and…

Read More Read More

580 total views, no views today