- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34484 Articles for Programming
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
372 Views
In this Program we need to implement binary search to find the existence of a search sequence in an array. The time complexity of Binary search is O(log(n)).Required steps and pseudocodesBegin BinarySearch() function has ‘arr’ the array of data and ‘n’ the number of values, start and end index, iteration count and b[0] be the element to be searched in the argument list. Increment the iteration counter and compare the item value with the a[mid]. If item < a[mid] choose first half otherwise second half to proceed further. Return index value to main. In main(), ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
252 Views
Self-Organizing list basically updates the list of given range of items on the basis of last searched item. In this method, the sequential searching approach is used. This algorithm shifts the more important data to the beginning of the list. The time complexity of this search technique is O(n).AlgorithmBegin Function FibonacciSearch(). Calculate the mid value using ‘start+fib[index-2]’ expression. If the chosen item is equal to the value at mid index, print result and return to main. If it is lesser than the value at mid index, proceed with the left sub-array. If it is more ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
455 Views
Binary Search and Sequential or Linear Search both are used in computer programming to search an element. The time complexity of Binary Search is O(log(n)) and Sequential Search is O(n).AlgorithmBegin Algorithm for Binary Search: BinarySearch() function with ‘arr’ the array of data and ‘n’ the number of values, start and end index, iteration count and element to be searched in the argument list. Increment iteration counter and compare the item value with the a[mid]. If item < a[mid] choose first half otherwise second half to proceed further. Return iteration value on successful search. EndExample Code#include ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
3K+ Views
Quick sort is based on divide-and-conquer. The average time complexity of this algorithm is O(n*log(n)) but the worst case complexity is O(n^2). To reduce the chances of the worst case here Quicksort is implemented using randomization.Algorithmpartition(int a[], int l, int h)Begin pivot = h Index = l start = l and end = h while start < end do while a[start] pivot do end = end – 1 done if start < end then swap a[start] with a[end] ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
240 Views
Stooge Sort is used to sort the given data. It is a recursive sorting algorithm. Stooge Sort divides the array into two overlapping parts, 2/3 each and Sort the array in three steps by sorting I then II and again I part. The worst case time complexity of this algorithm is O(n^2.7095).AlgorithmBegin Take input of data. Call StoogeSort() function with ‘a’ the array of data and ‘n’ the number of values, in the argument list. Implement Sorting using recursive approach. Divide the array into first 2/3 element as ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
Shaker sort is used to sort the given data. Shaker sort, unlike Bubble sort, orders the array in both directions. The worst complexity of this algorithm is O(n^2).AlgorithmBegin ShakerSort() function has ‘arr’ the array of data and ‘n’ the number of values, in the argument list. // Implement Sorting algorithm using nested for loops. The parent loop will run on ‘i’ from 0 to n-1 and contains two loops inside. The first loop will run on ‘j’ from i+1 to n-1 and use swap() if a[j] < a[j-1]. Decrement n. The second loop will ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
13K+ Views
This is a C++ program to solve 0-1 knapsack problem using dynamic programming. In 0-1 knapsack problem, a set of items are given, each with a weight and a value. We need to determine the number of each item to include in a collection so that the total weight is less than or equal to the given limit and the total value is large as possible.AlgorithmBegin Input set of items each with a weight and a value Set knapsack capacity Create a function that returns maximum of two integers. Create a function which returns the maximum value that can be ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
548 Views
Use the fromArray() method to create a Pair Tuple from Array.Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project ->Properties ->Java Build Path ->Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Pair; public class Demo { public static void main(String[] args) { ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
104 Views
To create a Unit Tuple in Java is quite easy.Let us first see what we need to work with JavaTuples. To work with the Unit class in JavaTuples, you need to import the following package −import org.javatuples.Unit;Let us see an example.Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Unit Class in Java Tuples, then Right Click Project ->Properties ->Java Build Path ->Add External Jars and upload the downloaded JavaTuples jar file.Exampleimport org.javatuples.Unit; public class Demo { public static void main(String[] args) { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
82 Views
To create a Septet Tuple in Java, use the with() method.Let us first see what we need to work with JavaTuples. To work with Septet class in JavaTuples, you need to import the following package −import org.javatuples.Septet;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Septet Class in JavaTuples, then Right Click Project ->Properties ->Java Build Path ->Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Septet; public class Demo { public static void main(String[] args) { ... Read More