Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add features (examples and information ) #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ClassificationofDataStructure.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions CodingInterviews/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1671624664256</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Binary file added CodingInterviews/bin/com/bst/BST.class
Binary file not shown.
Binary file added CodingInterviews/bin/com/bst/Node.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added CodingInterviews/bin/com/linkedList/ListNode.class
Binary file not shown.
Binary file added CodingInterviews/bin/com/problem1/Cell.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added CodingInterviews/bin/com/problem12/Mirror.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added CodingInterviews/bin/com/problem17/Option.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added CodingInterviews/bin/com/problem2/GCell.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added CodingInterviews/bin/com/problem5/LCSOnes.class
Binary file not shown.
Binary file added CodingInterviews/bin/com/problem6/BinarySearch.class
Binary file not shown.
Binary file added CodingInterviews/bin/com/problem7/LCS.class
Binary file not shown.
Binary file added CodingInterviews/bin/com/problem8/Stair.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// C# program to demonstrate searching operation
// in binary search tree without recursion
using System;

class GFG {

public class Node {
public int data;
public Node left, right;
};

// Function to check the given key exist or not
static bool iterativeSearch(Node root, int key)
{
// Traverse until root reaches to dead end
while (root != null) {
// pass right subtree as new tree
if (key > root.data)
root = root.right;

// pass left subtree as new tree
else if (key < root.data)
root = root.left;
else
return true; // if the key is found return 1
}
return false;
}

// A utility function to create a new BST Node
static Node newNode(int item)
{
Node temp = new Node();
temp.data = item;
temp.left = temp.right = null;
return temp;
}

/* A utility function to insert a new Node with
given key in BST */
static Node insert(Node Node, int data)
{
/* If the tree is empty, return a new Node */
if (Node == null)
return newNode(data);

/* Otherwise, recur down the tree */
if (data < Node.data)
Node.left = insert(Node.left, data);
else if (data > Node.data)
Node.right = insert(Node.right, data);

/* return the (unchanged) Node pointer */
return Node;
}

// Driver code
public static void Main(String[] args)
{
/* Let us create following BST
50
/ \
30 70
/ \ / \
20 40 60 80 */
Node root = null;
root = insert(root, 50);
insert(root, 30);
insert(root, 20);
insert(root, 40);
insert(root, 70);
insert(root, 60);
insert(root, 80);
if (iterativeSearch(root, 15))
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}

// This code has been contributed by 29AjayKumar


/*
Output
No
Time Complexity: O(h), here h is the height of the BST.
Auxiliary Space: O(1), as constant extra space is used.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

import java.util.*;

// Java program to demonstrate searching operation
// in binary search tree without recursion

class GFG {

static class Node {
int data;
Node left, right;
};

// Function to check the given key exist or not
static boolean iterativeSearch(Node root, int key)
{
// Traverse until root reaches to dead end
while (root != null) {
// pass right subtree as new tree
if (key > root.data)
root = root.right;

// pass left subtree as new tree
else if (key < root.data)
root = root.left;
else
return true; // if the key is found return 1
}
return false;
}

// A utility function to create a new BST Node
static Node newNode(int item)
{
Node temp = new Node();
temp.data = item;
temp.left = temp.right = null;
return temp;
}

/* A utility function to insert a new Node with
given key in BST */
static Node insert(Node Node, int data)
{
/* If the tree is empty, return a new Node */
if (Node == null)
return newNode(data);

/* Otherwise, recur down the tree */
if (data < Node.data)
Node.left = insert(Node.left, data);
else if (data > Node.data)
Node.right = insert(Node.right, data);

/* return the (unchanged) Node pointer */
return Node;
}

// Driver code
public static void main(String args[])
{
/* Let us create following BST
50
/ \
30 70
/ \ / \
20 40 60 80 */
Node root = null;
root = insert(root, 50);
insert(root, 30);
insert(root, 20);
insert(root, 40);
insert(root, 70);
insert(root, 60);
insert(root, 80);
if (iterativeSearch(root, 15))
System.out.println("YES");
else
System.out.println("NO");
}
}

// This code is contributed by Arnab Kundu

/*
Output
No
Time Complexity: O(h), here h is the height of the BST.
Auxiliary Space: O(1), as constant extra space is used.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// C++ program to demonstrate searching operation
// in binary search tree without recursion
#include <bits/stdc++.h>
using namespace std;

struct Node {
int data;
struct Node *left, *right;
};

// Function to check the given key exist or not
bool iterativeSearch(struct Node* root, int key)
{
// Traverse until root reaches to dead end
while (root != NULL) {
// pass right subtree as new tree
if (key > root->data)
root = root->right;

// pass left subtree as new tree
else if (key < root->data)
root = root->left;
else
return true; // if the key is found return 1
}
return false;
}

// A utility function to create a new BST Node
struct Node* newNode(int item)
{
struct Node* temp = new Node;
temp->data = item;
temp->left = temp->right = NULL;
return temp;
}

/* A utility function to insert a new Node with
given key in BST */
struct Node* insert(struct Node* Node, int data)
{
/* If the tree is empty, return a new Node */
if (Node == NULL)
return newNode(data);

/* Otherwise, recur down the tree */
if (data < Node->data)
Node->left = insert(Node->left, data);
else if (data > Node->data)
Node->right = insert(Node->right, data);

/* return the (unchanged) Node pointer */
return Node;
}

// Driver Program to test above functions
int main()
{
/* Let us create following BST
50
/ \
30 70
/ \ / \
20 40 60 80 */
struct Node* root = NULL;
root = insert(root, 50);
insert(root, 30);
insert(root, 20);
insert(root, 40);
insert(root, 70);
insert(root, 60);
insert(root, 80);
if (iterativeSearch(root, 15))
cout << "Yes";
else
cout << "No";
return 0;
}


/*
Output
No
Time Complexity: O(h), here h is the height of the BST.
Auxiliary Space: O(1), as constant extra space is used.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// JavaScript program to
// demonstrate searching operation
// in binary search tree without recursion

class Node {
constructor() {
this.data = 0;
this.left = null;
this.right = null;
}
}

// Function to check the given key exist or not
function iterativeSearch(root , key)
{
// Traverse until root reaches to dead end
while (root != null) {
// pass right subtree as new tree
if (key > root.data)
root = root.right;

// pass left subtree as new tree
else if (key < root.data)
root = root.left;
else
// if the key is found return 1
return true;
}
return false;
}

// A utility function to create a new BST Node
function newNode(item)
{
var temp = new Node();
temp.data = item;
temp.left = temp.right = null;
return temp;
}

/* A utility function to insert a new Node with
given key in BST */
function insert(Node , data)
{
/* If the tree is empty, return a new Node */
if (Node== null)
return newNode(data);

/* Otherwise, recur down the tree */
if (data < Node.data)
Node.left = insert(Node.left, data);
else if (data > Node.data)
Node.right = insert(Node.right, data);

/* return the (unchanged) Node pointer */
return Node;
}

// Driver code

/* Let us create following BST
50
/ \
30 70
/ \ / \
20 40 60 80 */
var root = null;
root = insert(root, 50);
insert(root, 30);
insert(root, 20);
insert(root, 40);
insert(root, 70);
insert(root, 60);
insert(root, 80);
if (iterativeSearch(root, 15))
document.write("YES");
else
document.write("NO");

// This code is contributed by todaysgaurav


/*
Output
No
Time Complexity: O(h), here h is the height of the BST.
Auxiliary Space: O(1), as constant extra space is used.
*/
Loading