This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "Hello World"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({super.key, required this.title}); | |
final String title; | |
@override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int fib(int n) { | |
int sum=0; | |
if(n<=1){ | |
return n; | |
} | |
return fib(n-1)+fib(n-2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int fact(int n) | |
{ | |
if (n < = 1) // base case | |
return 1; | |
else | |
return n*fact(n-1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedHashSet; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
import java.util.Set; | |
public class BreadthFirstSearch { | |
Set<String> breadthFirstTraversal(Graph graph, String root) { | |
Set<String> visited = new LinkedHashSet<String>(); | |
Queue<String> queue = new LinkedList<String>(); | |
queue.add(root); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedHashSet; | |
import java.util.Set; | |
import java.util.Stack; | |
public class DepthFirstTraversal { | |
static Set<String> depthFirstTraversal(Graph graph, String root) { | |
Set<String> visited = new LinkedHashSet<String>(); | |
Stack<String> stack = new Stack<String>(); | |
stack.push(root); | |
while (!stack.isEmpty()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.JavaFundermentals.JavaFundermentals.graph; | |
import ch.qos.logback.core.subst.Node; | |
import java.util.LinkedList; | |
public class GraphList { | |
LinkedList<Integer>[] adj; | |
private int V; | |
private int E; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.JavaFundermentals.JavaFundermentals; | |
//Adjacency Matrix undirected graph | |
public class Graph { | |
private int V; //number of vertices in the graph | |
private int E; //number of edges in the graph | |
private int[][] adjMatrix;//two dimentional array | |
public Graph(int nodes) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TernarySearch { | |
public static int search(int arr[], int l, int r, int key) { | |
while (r >= l) { | |
//find the value of mid1 and mid2 | |
int mid1 = l + (r - l) / 3; | |
int mid2 = r - (r - l) / 3; | |
//check if key is present at any of the mid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.JavaFundermentals.JavaFundermentals.search; | |
///Given a sorted array arr[] of n elements, write a function to search a given element x in arr[] and return the index of x in the array | |
public class BinarySearch { | |
public static int search(int arr[], int x, int low, int high) { | |
if (high >= low) { | |
int mid = low + (high - low) / 2; | |
//check if element is present at the middle position | |
if (arr[mid] == x) | |
return mid; |
NewerOlder