Skip to content

Instantly share code, notes, and snippets.

@mercykip
mercykip / index.php
Created January 15, 2023 12:21
hello world php
<?php
echo "Hello World";
?>
@mercykip
mercykip / printtimer.java
Created October 14, 2022 11:38
print statement after 10 seconds
import 'dart:async';
import 'package:flutter/material.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
class Solution {
public int fib(int n) {
int sum=0;
if(n<=1){
return n;
}
return fib(n-1)+fib(n-2);
}
int fact(int n)
{
if (n < = 1) // base case
return 1;
else
return n*fact(n-1);
}
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);
@mercykip
mercykip / DepthFirstTraversal.java
Created August 21, 2022 15:02
This is a sample code from baeldung for performing dfs
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()) {
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;
@mercykip
mercykip / Graph.java
Created August 20, 2022 05:20
Creating an adjacent matrix and printing to console.
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) {
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
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;