Skip to main content

Posts

Showing posts from January, 2024

Midpoint of Linked List

/*     Following is the Node class already written for the Linked List     class Node<T> {         T data;         Node<T> next;              public Node(T data) {             this.data = data;         }     } */ public   class  Solution {           public   static  Node<Integer> midPoint(Node<Integer> head) {          //Your code goes here          if (head == null){              return  null;         }         Node<Integer> slow = head;         Node<Integer> fast = head;          while (fast.next != null && fast.next.next != null){             fast = fast.next.next;             slow = slow.next;         }  return  slow;     } } jab tak fast.next null nhi hai tab tak chlte rhna hai ya fast ke next ka next null nhi hai chalte rhna hai agr inme se koi ek v false ho jata hai to ruk jana hai yaani agar null ho jata hai to condition false ho jayegi

how to reverse a LinkedList

/*     Following is the Node class already written for the Linked List     class Node<T> {         T data;         Node<T> next;              public Node(T data) {             this.data = data;         }     } */ public   class  Solution {                                                                      public   static  void printReverse(Node<Integer> root) {          if (root==null)  return ;         printReverse(root.next);          System.out.print(root.data+ " " );      } } this is recursive call jisme first in last out hoga lets suppose 1 2 3 4 ye ek linkedList hai ab ham printRever(root.next) se function ko recursive call kar rhe jisme sabse phle 1 hoga phir check karega root next hai ? nhi hai to dubara recursive call hoga 2 ko check karega ye v nhi hai 3 ko check karega ye v nhi hai null 4 ko check karega ye v nhi hai null ab jaise hi 4 ho jayega ye oppositve direction me print krna suru kr dega 4 to 3 to 2 to 1 aur is tarh se ye reverse ho

remove consicutive duplicate from LinkedList

  /*     Following is the Node class already written for the Linked List     class Node<T> {         T data;         Node<T> next;              public Node(T data) {             this.data = data;         }     } */ public   class  Solution {      public   static  Node<Integer> removeDuplicates(Node<Integer> head) {          //Your code goes here          if (head == null){              return  null;         }         Node<Integer> temp = head;          //Node<Integer> result = null;          while (temp.next != null) {              if (temp.data .equals(temp.next.data)){ // this is function                 temp.next = temp.next.next;             }  else  {                 temp = temp.next;             }         }          return  head;     } }

Count Nodes of Linked List .

  Problem statement Send feedback Given the head of a singly linked list of integers, find and return its length. public   static  int length(Node head){          while(head != null{               count++;               head = head.next; } } }

Find a Node in Linked List

Question:  Problem statement Send feedback You have been given a singly linked list of integers. Write a function that returns the index/position of integer data denoted by 'N' (if it exists). Return -1 otherwise. Note : Assume that the Indexing for the singly linked list always starts from 0.   /****************************************************************     Following is the class structure of the Node class:     class Node<T> {         T data;         Node<T> next;              public Node(T data) {             this.data = data;         }     } *****************************************************************/ public   class  Solution {      public   static  int findNode(Node<Integer> head, int n) {          // Write your code here.          if (head == null){              return  - 1 ;         }         Node<Integer> temp = head;         int count = 0 ;          while (temp != null){              if (temp.data == n){                  return  coun

Understanding Operators and Expressions in Programming C (Type Casting and Operators) || Programming C Notes Unit 002

Understanding Operators and Expressions in C Question : What is operators on Programming C ? Ans: Operators in C programming are symbols that are used to perform operations on operands. These operations can include arithmetic operations, logical operations, bitwise operations, assignment operations , and more. Operators help in manipulating data and controlling the flow of a program.  DIFFERENT TYPES OF OPERATORS: 1) Arithmetic:  In C language, there are five primary arithmetic operators  Used to perform arithmetic operations such as addition, subtraction, multiplication, division, and modulus. : Addition (+) Subtraction (-) Multiplication (*) Division (/) it will provide u divide value not remainder Remainder after division (%), also known as the modulus operator. These operators perform basic mathematical operations like addition, subtraction, multiplication, division, and finding the remainder of integer division. The symbols +, -, *, and / function similarly to other programming la

Print ith index on Linked List node from scratch

import java.sql.SQLOutput ; import java.util. * ; public class ithIndexPrint { public static void print ( Node < Integer > head , int i ){ while ( head != null && i > 0 ){ head = head . next ; i -- ; if ( i == 0 ){ System . out .println( head . data ) ; } } } public static Node < Integer > takeInput (){ Scanner scan = new Scanner( System . in ) ; Node < Integer > head = null ; Node < Integer > tail = null ; System . out .println( "Enter Node:" ) ; int data = 0 ; while ( data != - 1 ){ //tab tak ham data lenge jab tk -1 na aa jaye data = scan .nextInt() ; // loop me aane ke bad ham data input lenge Node < Integer > newData = new Node< Integer >( data ) ; // us data ka ek node banayenge if ( head == null ){ //agar head hamara blank hai to usme node ka d

Print ith Node on LinkList

  /*     Following is the Node class already written for the Linked List     class Node<T> {         T data;         Node<T> next;              public Node(T data) {             this.data = data;         }     } */ public   class  Solution {      public   static  void printIthNode(Node<Integer> head, int i){          while (head != null && i >  0 ){ //jab tak head null nhi ho jata ya i badha nhi hai 0 se tab tak loop chalana hai             head = head.next;  // this is for go in next Node              i--;              if (i ==  0 ){ //if i == o then print                 System.out.print(head.data);             }         }     } }

Cyber Security and Applied Ethical Hacking

INTRODUCTION Question: What is Hacking? Ans: Hacking refers to an array of activities which are done to intrude some one else's personal information space so as to use it for malicious, unwanted purpose. How to find IP Address ? Some Good proxy servers to prevent IP tracking: 1) Wingate  2) Squid 

Generative AI

Question: What is Generative AI ? Ans: Generative AI is a type of Artificial intelligence technology that can produce various type of content Including text , Imagery audio and synthetic data. AI is a discipline like physics , AI is a branch of computer science that deals with the creation of intelligent agents which are systems that can reason and learn and act autonomously. essentially AI has to do the theory and methods to build machines that thinks and acts like humans . Mahine Learning : in this discipline we have machine learning which is a subfield of AI it is a program  of system that trains a model from input data. Machine learning gives computer the ability to learn without explicit programming..           Two of the most common classes of machine learning models are >>> 1) Unsupervised ML Model 2) Supervised ML Model The key differernt between is that with supervised models we have labels label data is data that comes with a tag like a name a type or a number .. unl

OOPs 2 JAVA

What is OOPS? Ans:Lets say my college has 10 students and each students will have some property like age, name and roll Number. Now every student have these 3 properties , so what I will do in normal term , I'm creating a student 1 and I'll say student1 have these 3 property ,every time when I'll create a student I'll say every student have these 3 property but this is not a efficient solution, we dont want to add that. Instead of this what we will do will create a seperate class or just like a form and template , okay so student ? so whatever student is, his age will be, his name will be, his roll number will be. Now you want to create another students lets use this template to use these copy. So hamne ek blueprint or template banake rakh diya hai which we have going to create actual student object this is just a formula of a student Like uski property. In object oriented programming will say class , This is a class each of these individual instance is a OOPS.

Linked List Data Structure

Question: How to create without generic Int type Node ? Ans:  public class Node { // this is Node class without Generic int data ; // this is for data like array Element Node next ; //Node ek class hai , usi class ka khud ka variable hai, This is Node(Class) Type variable for //Node is basically refer to class , this is for next element Node ( int data ){ // this is constructor bcse user will pass data value and int because we want to create int type data constructor this . data = data ; // this is refer data next = null ; } }  

For each loop in ArrayList

 Print element in ArrayList using for each loop import java.util. * ; public class forEach { public static void main ( String [] args ){ ArrayList < Integer > myList = new ArrayList<>() ; myList .add( 39 ) ; myList .add( 48 ) ; myList .add( 437 ) ; //let me print this with for each loop for ( int elem : myList ){ //this is syntax of for each loop where elem is loop name System . out .println( elem ) ; } } } Note: For each loop me hamesa loop ka name hi print karna hota hai. Like here u can see loop name is elem then will print elem <Integer> is basically Generic , so we need to inform arrayList what type of data we want to store . Where to use for each loop ? Ans: where u want to iterate in Element only , it will help to iterate in all the elements . What for each loop does is ? it will iterate in all elements in 1 syntax. its just for a quick traiversal . u can use this on array also

Introduction to Arraylists

Question: What is Arraylists and why to use Arraylist ? Ans: As you know, an array is one data structure we have been using till now. A major drawback of an array is that we have to specify its size. However, in scenarios where we need an array that can dynamically adjust or increase in size, we can use an ArrayList. if u want to use Arraylist, we have to import arraylist package, just like scanner  import java.util.ArrayList ; //this is arraylist public class ArrayListDemo { } Array list just like a Generic class of oops,  Java me Generic Class ek class hoti hai jise aap ek ya multiple data types ke saath use kar sakte hain. Generic classes allow you to create classes that can work with different types without sacrificing type safety. In other words, a generic class can be parameterized with different data types.   import java.util.ArrayList ; public class ArrayListDemo { public static void main ( String [] args ){ ArrayList < Integer > list1 = new ArrayList<>()

LinkedList 1 Data Structure

Question: What are Data Structures? Ans:  Data structures are specialized formats for organizing and storing data in a computer's memory or storage. They define the way data is organized, stored, and manipulated to efficiently perform specific operations. Different data structures are suitable for different tasks, and choosing the right data structure can significantly impact the efficiency and performance of algorithms and programs. See, data is a central part of whatever system we are building, This is a central part right ? Here are some common types of data structures: Arrays: A collection of elements identified by index or key. Linked Lists: A sequence of elements where each element points to the next element in the sequence. Stacks: A Last In, First Out (LIFO) data structure where elements are added and removed from the same end. Queues: A First In, First Out (FIFO) data structure where elements are added at the rear and removed from the front. Trees: Hierarchical data s