Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Logo SIKSHAPATH Logo

SIKSHAPATH Navigation

  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
  • About
    1. Asked: November 21, 2021In: Other

      CODECHEF PRACTICE PROBLEM WEEK 6 AND 7:

      Professor
      Professor
      Added an answer on November 21, 2021 at 10:52 am

      CODECHEF PRACTICE PROBLEM WEEK 6 AND 7 SOLUTION :

      CODECHEF PRACTICE PROBLEM WEEK 6 AND 7 SOLUTION :

      See less
      Attachment

        • 0
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    2. Asked: November 20, 2021In: Data Structure

      Write a program to implement Binary Search Tree.

      Professor
      Professor
      Added an answer on November 20, 2021 at 12:02 pm

      #include <iostream> using namespace std; class BST { int data; BST *left, *right; public: BST(); BST(int); BST* Insert(BST*, int); void Inorder(BST*); }; BST ::BST() : data(0) , left(NULL) , right(NULL) { } BST ::BST(int value) { data = value; left = right = NULL; } BST* BST ::Insert(BST* rootRead more

      #include <iostream>
      using namespace std;
      
      class BST
      {
      int data;
      BST *left, *right;
      
      public:
      BST();
      
      BST(int);
      
      BST* Insert(BST*, int);
      
      void Inorder(BST*);
      };
      
      BST ::BST()
      : data(0)
      , left(NULL)
      , right(NULL)
      {
      }
      
      BST ::BST(int value)
      {
      data = value;
      left = right = NULL;
      }
      
      BST* BST ::Insert(BST* root, int value)
      {
      if (!root)
      {
      return new BST(value);
      }
      
      if (value > root->data)
      {
      
      root->right = Insert(root->right, value);
      }
      else
      {
      
      root->left = Insert(root->left, value);
      }
      
      return root;
      }
      
      void BST ::Inorder(BST* root)
      {
      if (!root) {
      return;
      }
      Inorder(root->left);
      cout << root->data << endl;
      Inorder(root->right);
      }
      
      int main()
      {
      BST b, *root = NULL;
      root = b.Insert(root, 50);
      b.Insert(root, 30);
      b.Insert(root, 20);
      b.Insert(root, 40);
      b.Insert(root, 70);
      b.Insert(root, 60);
      b.Insert(root, 80);
      
      b.Inorder(root);
      return 0;
      }
      
      
      See less
        • 0
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    3. Asked: November 19, 2021In: Programming Language

      Java Retrieve the odd numbers till given input number. add and subtract it consecutively and return the result. Input:9 Output:1+3-5+7-9=-3

      Professor
      Professor
      Added an answer on November 20, 2021 at 11:59 am

      import java.util.Scanner; class Main { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); int n; System.out.println("Enter no :"); n = myObj.nextInt(); int sum = 1,i,count=0,sub; for (i = 3; i <= n; i = i + 2) { count++; if (count == 2) { sub = sum - i; sum = sub; coRead more

      import java.util.Scanner;
      
      class Main {
      public static void main(String[] args) {
      Scanner myObj = new Scanner(System.in);
      int n;
      
      
      System.out.println("Enter no :"); 
      n = myObj.nextInt(); 
      
      
      int sum = 1,i,count=0,sub;
      for (i = 3; i <= n; i = i + 2)
      {
      count++;
      if (count == 2)
      {
      sub = sum - i;
      sum = sub;
      count = 0;
      continue;
      }
      sum = sum + i;
      }
      System.out.println("Sum is: " + sum);
      }
      }
      See less
        • 1
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    4. Asked: November 19, 2021In: Programming Language

      Java Create a class with a main( ) that throws an object of class Exception inside a try block. Give …

      Professor
      Professor
      Added an answer on November 20, 2021 at 10:49 am

      import java.io.FileNotFoundException; public class Main { Main(String msg) { msg = "I AM JAVA"; System.out.println(msg); } public static void main(String[] args) throws Exception { try { // Suppose here you are looking for any resource for eg.File // If program is unable to find file throw new FileNRead more

      import java.io.FileNotFoundException;
      
      public class Main {
      Main(String msg) {
      msg = "I AM JAVA";
      System.out.println(msg);
      }
      
      public static void main(String[] args) 
      throws Exception {
      try {
      // Suppose here you are looking for any resource for eg.File
      // If program is unable to find file
      throw new FileNotFoundException();
      } catch (FileNotFoundException e) {
      throw new Exception("File not found");
      } catch (Exception e) {
      System.out.println(e.getMessage());
      } finally {
      // This block will get get executed whether exception occures or
      // not.
      System.out.println("i will get printed");
      }
      
      }
      }
      See less
        • 0
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    5. Asked: November 20, 2021In: Data Structure

      C Program for Depth First Binary Tree Search using Recursion.

      Professor
      Professor
      Added an answer on November 20, 2021 at 10:32 am

      #include <stdio.h> #include <stdlib.h> struct node { int a; struct node *left; struct node *right; }; void generate(struct node **, int); void DFS(struct node *); void delete(struct node **); int main() { struct node *head = NULL; int choice = 0, num, flag = 0, key; do { printf("\nEnterRead more

      #include <stdio.h>
      #include <stdlib.h>
      
      struct node
      {
      int a;
      struct node *left;
      struct node *right;
      };
      
      void generate(struct node **, int);
      void DFS(struct node *);
      void delete(struct node **);
      
      int main()
      {
      struct node *head = NULL;
      int choice = 0, num, flag = 0, key;
      
      do
      {
      printf("\nEnter your choice:\n1. Insert\n2. Perform DFS Traversal\n3. Exit\nChoice: ");
      scanf("%d", &choice);
      switch(choice)
      {
      case 1: 
      printf("Enter element to insert: ");
      scanf("%d", &num);
      generate(&head, num);
      break;
      case 2: 
      DFS(head);
      break;
      case 3: 
      delete(&head);
      printf("Memory Cleared\nPROGRAM TERMINATED\n");
      break;
      default: 
      printf("Not a valid input, try again\n");
      }
      } while (choice != 3);
      return 0;
      }
      
      void generate(struct node **head, int num)
      {
      struct node *temp = *head, *prev = *head;
      
      if (*head == NULL)
      {
      *head = (struct node *)malloc(sizeof(struct node));
      (*head)->a = num;
      (*head)->left = (*head)->right = NULL;
      }
      else
      {
      while (temp != NULL)
      {
      if (num > temp->a)
      {
      prev = temp;
      temp = temp->right;
      }
      else
      {
      prev = temp;
      temp = temp->left;
      }
      }
      temp = (struct node *)malloc(sizeof(struct node));
      temp->a = num;
      if (num >= prev->a)
      {
      prev->right = temp;
      }
      else
      {
      prev->left = temp;
      }
      }
      }
      
      void DFS(struct node *head)
      {
      if (head)
      {
      if (head->left)
      {
      DFS(head->left);
      }
      if (head->right)
      {
      DFS(head->right);
      }
      printf("%d ", head->a);
      }
      }
      
      void delete(struct node **head)
      {
      if (*head != NULL)
      {
      if ((*head)->left)
      {
      delete(&(*head)->left);
      }
      if ((*head)->right)
      {
      delete(&(*head)->right);
      }
      free(*head);
      }
      }
      See less
      Attachment

        • 0
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    6. Asked: November 20, 2021In: Data Structure

      C Program to Find the Largest value in a Tree using Inorder Traversal.

      Professor
      Professor
      Added an answer on November 20, 2021 at 10:29 am

      #include <stdio.h> #include <stdlib.h> struct node { int info; struct node *left, *right; }; struct node *createnode(int key) { struct node *newnode = (struct node*)malloc(sizeof(struct node)); newnode->info = key; newnode->left = NULL; newnode->right = NULL; return(newnode); }Read more

      #include <stdio.h>
      #include <stdlib.h>
      struct node
      {
      int info;
      struct node *left, *right;
      };
      struct node *createnode(int key)
      {
      struct node *newnode = (struct node*)malloc(sizeof(struct node));
      newnode->info = key;
      newnode->left = NULL;
      newnode->right = NULL;
      return(newnode);
      }
      void inorder(struct node *root)
      {
      if(root != NULL)
      {
      inorder(root->left);
      printf(" %d ",root->info);
      inorder(root->right);
      }
      }
      void largest(struct node *root)
      {
      while (root != NULL && root->right != NULL)
      {
      root = root->right;
      }
      printf("\nLargest value is %d\n", root->info);
      }
      /*
      * Main Function
      */
      int main()
      {
      
      struct node *newnode = createnode(25);
      newnode->left = createnode(17);
      newnode->right = createnode(35);
      newnode->left->left = createnode(13);
      newnode->left->right = createnode(19);
      newnode->right->left = createnode(27);
      newnode->right->right = createnode(55);
      /* Sample Tree 1:
      * 25
      * / \
      * 17 35
      * / \ / \
      * 13 19 27 55
      */
      printf("Inorder traversal of tree 1 :");
      inorder(newnode);
      largest(newnode);
      
      /* Creating second Tree. */
      struct node *node = createnode(1);
      node->right = createnode(2);
      node->right->right = createnode(3);
      node->right->right->right = createnode(4);
      node->right->right->right->right = createnode(5);
      /* Sample Tree 2: Right Skewed Tree (Unbalanced).
      * 1
      * \
      * 2
      * \
      * 3
      * \
      * 4
      * \
      * 5
      */
      printf("\nInorder traversal of tree 2 :");
      inorder(node);
      largest(node);
      
      
      struct node *root = createnode(15);
      
      printf("\nInorder traversal of tree 3 :");
      inorder(root);
      largest(root);
      return 0;
      }
      See less
        • 0
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    1 2 3 4 … 26

    Sidebar

    store ads

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 149
    • Best Answers 89
    • This Free AI Tool Translates Entire Books in Minute !
    • AI News: 🎬 Hollywood’s AI Studios, 🎓 OpenAI’s Latest Gift to Educators, 🚚 Class8 Bags $22M, 🧠 Google Gemini’s Memory Upgrade
    • AI NEWS: Legal Action Against OpenAI, $16M Paid, & Elon Musk’s Praise from Investor 🤖💰📑 | AI Boosts Cloud Seeding for Water Security 🌱💧
    • AI News: 🎬AI Video Tool Scam Exposed🤯, 🛰️ AI-Powered Drones to Ukraine 😱, Google’s $20M AI Push, Sam Altman Joins SF’s Leadership Team
    • AI News: 🤝 Biden Meets Xi on AI Talks, 💡 Xavier Niel’s Advice for Europe, ♻️ Hong Kong’s Smart Bin Revolution, 🚀 AI x Huawei

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    SIKSHAPATH

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow Us

    © 2021-24 Sikshapath. All Rights Reserved