Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2836 of 3366
335 Views
This program represents a graph using incidence list and the time complexity of this algorithm is O(e).AlgorithmBegin Take the input of the number of vertex ‘v’ and edges ‘e’ and also take the input of ‘e’ pairs of vertexes of the given graph in e[][]. For each edge print the corresponding vertex involved in that connection. EndExample Code#include using namespace std; int main() { int i, v, e, j, c; coutv; coute; int edge[e][2]; for(i = 0; i < e; i++) { cout
347 Views
In this article, we will understand how to generate a graph for a given fixed-degree sequence. The degree of each node is given in the form of an array. The graph generated will be an undirected graph where the degree of each node will correspond to the given degree array. Example The following example generates a graph and adjacency matrix for the given degree sequence: Input: Degree Sequence: {3, 2, 3, 2} => Degree(Node a) = 3, Degree(Node b) = 2, Degree(Node c) = 3, Degree(Node d) = 2 ... Read More
709 Views
A Directed Acyclic Graph or DAG is a directed graph (a graph where each edge has a direction) that has no cycles present i.e. if we traverse along the direction of the edges then no closed loops are formed along any path. A DAG is always topologically ordered, i.e. for each edge in the graph, the start vertex of the edge(u) occurs earlier in the sequence than the ending vertex(v) of the edge i.e.(u {B C} B -> {Isolated Vertex} C -> {Isolated Vertex} D -> {B E} E -> {C} Steps to Generate Random Directed Acyclic Graph The ... Read More
1K+ Views
The peak element in an array is an element that is greater than its neighbor elements i.e., its left and right element. If the peak element is the starting element, then it should be greater than the next element (second element). If the peak element is the last element, then it should be greater than its previous value i.e., the second last element. In this article, we have an array of integers. Our task is to use the binary search algorithm to find the peak element present in the given array. Example Here are two examples to understand the ... Read More
304 Views
The binary search works on the divide and conquer principle as it keeps dividing the array into half before searching. For applying the binary search algorithm, the given array should be sorted. Since the array is sorted we do not need to search the minimum element in the array. In this article, the given array has strictly decreasing elements in the left sub-array till it reaches the minimum element and the right sub-array has strictly increasing elements. For example: {40, 30, 20, 10, 25, 35}. In this example, the array is decreasing till it ... Read More
525 Views
The binary search works on the divide and conquer principle as it keeps dividing the array into half before searching. For applying the binary search algorithm, the given array should be sorted. Since the array is sorted we do not need to search the maximum element in the array. Here, the given array is a Bitonic array. A bitonic array is an array in which the left sub-array has strictly increasing elements till it reaches the peak element and the right sub-array has strictly decreasing elements. For example: {10, 20, 30, 40, 35, 25}. In this example, the array is ... Read More
998 Views
Linear search is a sequential searching algorithm where we traverse every element within the input array and compare it with the key element to be found. The minimum element refers to the smallest element in the array. In this article, we have an array of integers. Our task is to find the minimum element in that array using linear search. Here are the three approaches you can use to find the minimum element: Using Value Using Index Using Pointer Using Value In this approach, ... Read More
425 Views
In this article, we have a sorted array of integers. Our task is to perform a uniform binary search to search for a target element. What is Uniform Binary Search? The uniform binary search is an improved version of the binary search algorithm where we use a pre-computed lookup table instead of calculating the middle element every time. The lookup table has elements that are powers of 2, starting from the larger value to 0, to decide the step for next iteration. The time complexity for uniform binary search is O(log n).Consider the following example scenarios to understand the ... Read More
563 Views
In this C++ program we implement a Divide and Conquer approach using Fibonacci numbers. Using Fibonacci numbers, we calculate mid of data array to search the data item. The time complexity of this approach is O(log(n)).AlgorithmBegin Assign the data to the array in a sorted manner. Take input of the element to be searched. Call FibonacciSearch() function. 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 ... Read More
452 Views
In this article, we have an unsorted array. Our task is to find the kth maximum element of that array using C++. Here is an example to understand the meaning of k. If k =2, you can say the second highest value, for k =3, the third highest value. The approaches that we will be using are mentioned below: Using Sorting Using Max Heap Using Min Heap Using Quick Select Using Binary Search Tree Using ... Read More