Skip to main content

Posts

Showing posts from March, 2023

Sieve Erotosthenes program in c++

  #include <bits/stdc++.h> using namespace std ; /* this program is for finding the prime number till the given number */ void primeSieve ( long long n ) {     long long prime [ n + 1 ] = { 0 };     for ( long long i = 2 ; i <= n ; i ++ )     {         if ( prime [ i ] == 0 )         for ( long long j = i * i ; j <= n ; j += i )         {             prime [ j ] = 1 ;         }             }     for ( long long i = 2 ; i <= n ; i ++ )     {         if ( prime [ i ] == 0 )         cout << i << " " ;     }         } int main () {     long long n ;     cin >> n ;     primeSieve ( n );     return 0 ; }

Program to find the number of 1's bit in a number

#include <bits/stdc++.h> using namespace std ; // this is the program to find the number of 1's bit in a number int count1nsBit ( int n ) {     int count = 0 ;     while ( n )     {         n = n & n - 1 ;         count ++ ;     }     return count ; } int main () {     int n ;     cin >> n ;     cout << count1nsBit ( n );     return 0 ; } /* input an output tast are comments */

Matrix search

palindrome

Recusion Tailor

 #include<bits/stdc++> using namespace std; //recursion start block double e(int x,int n) {     static int p=1,f=1;. double r;     if(n==0)     return (1); else { r=e(x,n-1); p=p*x; f=f*n; } return r+p/f; } // recursion function end block // other than recursion 

Basics of Data Structure

  Basic Operations of Data Structures In the following section, we will discuss the different types of operations that we can perform to manipulate data in every data structure: Traversal:  Traversing a data structure means accessing each data element exactly once so it can be administered. For example, traversing is required while printing the names of all the employees in a department. Search:  Search is another data structure operation that means to find the location of one or more data elements that meet certain constraints. Such a data element may or may not be present in the given set of data elements. For example, we can use the search operation to find the names of all the employees who have the experience of more than 5 years. Insertion:  Insertion means inserting or adding new data elements to the collection. For example, we can use the insertion operation to add the details of a new employee the company has recently hired. Deletion:  Deletion means to...

Application of Graph

  Applications of Graphs: Graphs help us represent routes and networks in transportation, travel, and communication applications. Graphs are used to display routes in GPS. Graphs also help us represent the interconnections in social networks and other network-based applications. Graphs are utilized in mapping applications. Graphs are responsible for the representation of user preference in e-commerce applications. Graphs are also used in Utility networks in order to identify the problems posed to local or municipal corporations. Graphs also help to manage the utilization and availability of resources in an organization. Graphs are also used to make document link maps of the websites in order to display the connectivity between the pages through hyperlinks. Graphs are also used in robotic motions and neural networks.

Type of Graph

  Depending upon the position of the vertices and edges, the Graphs can be classified into different types: Null Graph:  A Graph with an empty set of edges is termed a Null Graph. Trivial Graph:  A Graph having only one vertex is termed a Trivial Graph. Simple Graph:  A Graph with neither self-loops nor multiple edges is known as a Simple Graph. Multi Graph:  A Graph is said to be Multi if it consists of multiple edges but no self-loops. Pseudo Graph:  A Graph with self-loops and multiple edges is termed a Pseudo Graph. Non-Directed Graph:  A Graph consisting of non-directed edges is known as a Non-Directed Graph. Directed Graph:  A Graph consisting of the directed edges between the vertices is known as a Directed Graph. Connected Graph:  A Graph with at least a single path between every pair of vertices is termed a Connected Graph. Disconnected Graph:  A Graph where there does not exist any path between at least one pair of vertices is ...

Application of trees

  Some Applications of Trees: Trees implement hierarchical structures in computer systems like directories and file systems. Trees are also used to implement the navigation structure of a website. We can generate code like Huffman's code using Trees. Trees are also helpful in decision-making in Gaming applications. Trees are responsible for implementing priority queues for priority-based OS scheduling functions. Trees are also responsible for parsing expressions and statements in the compilers of different programming languages. We can use Trees to store data keys for indexing for Database Management System (DBMS). Spanning Trees allows us to route decisions in Computer and Communications Networks. Trees are also used in the path-finding algorithm implemented in Artificial Intelligence (AI), Robotics, and Video Games Applications.

lldiv() , A function of library lldiv_t in c++

  lldiv() Return value The lldiv() function returns a structure of type  lldiv_t  which consists of two members:  quot  and  rem . It is defined as follows: struct lldiv_t { long long quot; long long rem; }; Example: How lldiv() function works in C++? # include <iostream> # include <cstdlib> using namespace std ; int main () { long long nume = 998102910012L L; long long deno = 415L L; lldiv_t result = lldiv(nume, deno); cout << "Quotient of " << nume << "/" << deno << " = " << result.quot << endl ; cout << "Remainder of " << nume << "/" << deno << " = " << result.rem << endl ; return 0 ; } When you run the program, the output will be: Quotient of 998102910012/415 = 2405067253 Remainder of 998102910012/415 = 17