From c012cf13d4421d81060770c3897329d2d25daa50 Mon Sep 17 00:00:00 2001 From: dhruvil15 <76967484+dhruvil15@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:31:02 -0400 Subject: [PATCH 1/2] PreCourse-1 Complete --- .idea/.gitignore | 8 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + Exercise_1.java | 19 +++ Exercise_2.java | 118 ++++++++------ Exercise_3.java | 148 ++++++++++-------- Main.class | Bin 0 -> 964 bytes PreCourse-1.iml | 11 ++ Stack.class | Bin 0 -> 914 bytes out/production/PreCourse-1/.idea/.gitignore | 8 + out/production/PreCourse-1/.idea/misc.xml | 6 + out/production/PreCourse-1/.idea/modules.xml | 8 + out/production/PreCourse-1/.idea/vcs.xml | 6 + out/production/PreCourse-1/Exercise_1.cpp | 54 +++++++ out/production/PreCourse-1/Exercise_1.js | 35 +++++ out/production/PreCourse-1/Exercise_1.py | 24 +++ out/production/PreCourse-1/Exercise_2.cpp | 52 ++++++ out/production/PreCourse-1/Exercise_2.js | 36 +++++ out/production/PreCourse-1/Exercise_2.py | 32 ++++ out/production/PreCourse-1/Exercise_3.cpp | 80 ++++++++++ out/production/PreCourse-1/Exercise_3.js | 49 ++++++ out/production/PreCourse-1/Exercise_3.py | 32 ++++ .../PreCourse-1/LinkedList$Node.class | Bin 0 -> 435 bytes out/production/PreCourse-1/LinkedList.class | Bin 0 -> 1681 bytes out/production/PreCourse-1/Main.class | Bin 0 -> 1090 bytes out/production/PreCourse-1/PreCourse-1.iml | 11 ++ out/production/PreCourse-1/README.md | 11 ++ out/production/PreCourse-1/Stack.class | Bin 0 -> 1056 bytes .../StackAsLinkedList$StackNode.class | Bin 0 -> 467 bytes .../PreCourse-1/StackAsLinkedList.class | Bin 0 -> 1910 bytes 31 files changed, 653 insertions(+), 115 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Main.class create mode 100644 PreCourse-1.iml create mode 100644 Stack.class create mode 100644 out/production/PreCourse-1/.idea/.gitignore create mode 100644 out/production/PreCourse-1/.idea/misc.xml create mode 100644 out/production/PreCourse-1/.idea/modules.xml create mode 100644 out/production/PreCourse-1/.idea/vcs.xml create mode 100644 out/production/PreCourse-1/Exercise_1.cpp create mode 100644 out/production/PreCourse-1/Exercise_1.js create mode 100644 out/production/PreCourse-1/Exercise_1.py create mode 100644 out/production/PreCourse-1/Exercise_2.cpp create mode 100644 out/production/PreCourse-1/Exercise_2.js create mode 100644 out/production/PreCourse-1/Exercise_2.py create mode 100644 out/production/PreCourse-1/Exercise_3.cpp create mode 100644 out/production/PreCourse-1/Exercise_3.js create mode 100644 out/production/PreCourse-1/Exercise_3.py create mode 100644 out/production/PreCourse-1/LinkedList$Node.class create mode 100644 out/production/PreCourse-1/LinkedList.class create mode 100644 out/production/PreCourse-1/Main.class create mode 100644 out/production/PreCourse-1/PreCourse-1.iml create mode 100644 out/production/PreCourse-1/README.md create mode 100644 out/production/PreCourse-1/Stack.class create mode 100644 out/production/PreCourse-1/StackAsLinkedList$StackNode.class create mode 100644 out/production/PreCourse-1/StackAsLinkedList.class diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..bcb5da6c3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..a866e1a9f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Exercise_1.java b/Exercise_1.java index 314a3cb45..e873657f5 100644 --- a/Exercise_1.java +++ b/Exercise_1.java @@ -8,28 +8,47 @@ class Stack { boolean isEmpty() { //Write your code here + return top == -1; } Stack() { //Initialize your constructor + top = -1; } boolean push(int x) { //Check for stack Overflow //Write your code here + if (top >= MAX -1) { + System.out.println("Stack Overflow"); + return false; + } + + a[++top] = x; + return true; } int pop() { //If empty return 0 and print " Stack Underflow" //Write your code here + if (top < 0) { + System.out.println("Stack Underflow"); + return 0; + } + return a[top--]; } int peek() { //Write your code here + if (top < 0) { + System.out.println("Stack is empty"); + return -1; + } + return a[top]; } } diff --git a/Exercise_2.java b/Exercise_2.java index 5a9c4868c..1f6731c04 100644 --- a/Exercise_2.java +++ b/Exercise_2.java @@ -1,52 +1,74 @@ -public class StackAsLinkedList { - - StackNode root; - - static class StackNode { - int data; - StackNode next; - - StackNode(int data) - { - //Constructor here - } - } - - - public boolean isEmpty() - { - //Write your code here for the condition if stack is empty. - } - - public void push(int data) - { - //Write code to push data to the stack. - } - - public int pop() - { +class StackAsLinkedList { + + StackNode root; + + static class StackNode { + int data; + StackNode next; + + StackNode(int data) + { + //Constructor here + this.data = data; + this.next = null; + } + } + + + public boolean isEmpty() + { + //Write your code here for the condition if stack is empty. + return root == null; + } + + public void push(int data) + { + //Write code to push data to the stack. + StackNode newNode = new StackNode(data); + if (isEmpty()) { + root = newNode; + } else { + newNode.next = root; + root = newNode; + } + } + + public int pop() + { //If Stack Empty Return 0 and print "Stack Underflow" //Write code to pop the topmost element of stack. - //Also return the popped element - } - - public int peek() - { + //Also return the popped element + if (isEmpty()) { + System.out.println("Stack Underflow"); + return 0; + } + int poped = root.data; + root = root.next; + return poped; + } + + public int peek() + { //Write code to just return the topmost element without removing it. - } - + if (isEmpty()) { + System.out.println("Stack is Empty"); + return -1; + } + return root.data; + } + //Driver code - public static void main(String[] args) - { - - StackAsLinkedList sll = new StackAsLinkedList(); - - sll.push(10); - sll.push(20); - sll.push(30); - - System.out.println(sll.pop() + " popped from stack"); - - System.out.println("Top element is " + sll.peek()); - } -} + public static void main(String[] args) + { + + StackAsLinkedList sll = new StackAsLinkedList(); + + sll.push(10); + sll.push(20); + sll.push(30); + + System.out.println(sll.pop() + " popped from stack"); + + System.out.println("Top element is " + sll.peek()); + } +} diff --git a/Exercise_3.java b/Exercise_3.java index fb66d329d..8ca4bb60b 100644 --- a/Exercise_3.java +++ b/Exercise_3.java @@ -1,70 +1,84 @@ -import java.io.*; - -// Java program to implement -// a Singly Linked List -public class LinkedList { - - Node head; // head of list - - // Linked list Node. - // This inner class is made static - // so that main() can access it - static class Node { - - int data; - Node next; - - // Constructor - Node(int d) - { - //Write your code here - } - } - - // Method to insert a new node - public static LinkedList insert(LinkedList list, int data) - { - // Create a new node with given data - - // If the Linked List is empty, - // then make the new node as head - - // Else traverse till the last node - // and insert the new_node there +import java.io.*; - // Insert the new_node at last node - // Return the list by head - - } - - // Method to print the LinkedList. - public static void printList(LinkedList list) - { - // Traverse through the LinkedList - - // Print the data at current node - - // Go to next node - } - - // Driver code - public static void main(String[] args) - { +// Java program to implement +// a Singly Linked List +class LinkedList { + + Node head; // head of list + + // Linked list Node. + // This inner class is made static + // so that main() can access it + static class Node { + + int data; + Node next; + + // Constructor + Node(int d) + { + //Write your code here + this.data = d; + this.next = null; + } + } + + // Method to insert a new node + public static LinkedList insert(LinkedList list, int data) + { + // Create a new node with given data + Node newNode = new Node(data); + + // If the Linked List is empty, + // then make the new node as head + if (list.head == null) { + list.head = newNode; + } else { + // Else traverse till the last node + // and insert the new_node there + Node last = list.head; + while (last.next != null) { + last = last.next; + } + // Insert the new_node at last node + last.next = newNode; + } + // Return the list by head + return list; + } + + // Method to print the LinkedList. + public static void printList(LinkedList list) + { + // Traverse through the LinkedList + Node currNode = list.head; + while (currNode != null) { + // Print the data at current node + System.out.print(currNode.data + "->"); + // Go to next node + currNode = currNode.next; + } + System.out.println("Done!"); + } + + // Driver code + public static void main(String[] args) + { /* Start with the empty list. */ - LinkedList list = new LinkedList(); - - // - // ******INSERTION****** - // - - // Insert the values - list = insert(list, 1); - list = insert(list, 2); - list = insert(list, 3); - list = insert(list, 4); - list = insert(list, 5); - - // Print the LinkedList - printList(list); - } + LinkedList list = new LinkedList(); + + // + // ******INSERTION****** + // + + // Insert the values + list = insert(list, 1); + list = insert(list, 2); + list = insert(list, 3); + list = insert(list, 4); + list = insert(list, 5); + + // Print the LinkedList + printList(list); + } } \ No newline at end of file diff --git a/Main.class b/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..f8b45a2bca5a8ee4505b5d7917505fdcbc70682e GIT binary patch literal 964 zcmaJ=?M@Rx6g@)=+pepvd;^)%M5Y96E?}@D)~=Iq>wgn)xspE zF2L5hp%QIElN|z|srCsSS=OxQL8_n-;RT#V|F3mBH|J4X&p_h9R{0J0x$1 zJCqSG%Z6Y`RUJ>f@3iY8*yDAVcH-@Rd^Y!a6a<4=lbyg8+m237z5ONv+X=;&^)+1* zb?S|jDpUdYcZ6!nMwq|~)yuNG()UFp`!$g5ENQh{sR^u^DB^*Eb={SR3`^&?=Xl4m zC5n;!s8QS8Rx;=^d>>SImKd?U<6grR;Zjw~R>v<5D;U_haB#2dixKIAJ&5M1GEK%ED zWSQPsJ^}kd4$;%9!@zSSaS!*&*Qp0|R3Bdb1>@iZ$!Z~O_F(Q8($kU2X!8?S3O!7p z;u_GyjdREa0tHG)V1xdYmo(~|#Qq8^*g_0Bij5(UWwHq(T&1^wNAzWq_ZUy9nE8L~ C`0XA5 literal 0 HcmV?d00001 diff --git a/PreCourse-1.iml b/PreCourse-1.iml new file mode 100644 index 000000000..b107a2dd8 --- /dev/null +++ b/PreCourse-1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Stack.class b/Stack.class new file mode 100644 index 0000000000000000000000000000000000000000..4015edceae5519133d0d9d426ae9d01db8be4ab3 GIT binary patch literal 914 zcmZvZ&rTCj6vn?hGwqZ*rL_E!KZ+Htv{k9qg$s<45R6U0np6qmLWgq2!FFcSPEp>) zg|6JN(TFC-_yE3$JcaSQGZPBY&6zpp-t+sud(N*v-+uyF!p$LQ&`lT?5=aUpnt|PV zEuaUUFCgk^q%dS6ZQ%?ofstK%&#ty@cc_loyRb=9W(YT6uNoh4sNE+F0X`rVei@2KwV%3IlOIX(HjwxC{%0_U9K z0(DH{5|R+O%uGX(k$Yr>T0)osS1`{TC1y3=5&RBUzCdX2VHzJ{=m)H5C^IS&xataH z0-AL%O0Bs4cHBN%`3AF+(~o|n50R;8hY+9GAwotT2LH2+No0`Y`t!`M;#v&Z;EBe{ zyz-FKe}6#cGjjQ}UooX0u$HMj<$>{Hlhm1pF)%klOW=dkm?Cl-W88lcv!PiXVvL8^ zu@I{?cv+dBQ!4Kwi3_JCHjQmcEDQu9=S7&DSe7%(@jYr1gy;CF9>X8RbC@{+zeu + + + + + \ No newline at end of file diff --git a/out/production/PreCourse-1/.idea/modules.xml b/out/production/PreCourse-1/.idea/modules.xml new file mode 100644 index 000000000..a866e1a9f --- /dev/null +++ b/out/production/PreCourse-1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/PreCourse-1/.idea/vcs.xml b/out/production/PreCourse-1/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/out/production/PreCourse-1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/PreCourse-1/Exercise_1.cpp b/out/production/PreCourse-1/Exercise_1.cpp new file mode 100644 index 000000000..381e274d5 --- /dev/null +++ b/out/production/PreCourse-1/Exercise_1.cpp @@ -0,0 +1,54 @@ +#include + +using namespace std; + +#define MAX 1000 + +class Stack { + //Please read sample.java file before starting. + //Kindly include Time and Space complexity at top of each file + int top; + +public: + int a[MAX]; // Maximum size of Stack + + Stack() { //Constructor here } + bool push(int x); + int pop(); + int peek(); + bool isEmpty(); +}; + +bool Stack::push(int x) +{ + //Your code here + //Check Stack overflow as well +} + +int Stack::pop() +{ + //Your code here + //Check Stack Underflow as well +} +int Stack::peek() +{ + //Your code here + //Check empty condition too +} + +bool Stack::isEmpty() +{ + //Your code here +} + +// Driver program to test above functions +int main() +{ + class Stack s; + s.push(10); + s.push(20); + s.push(30); + cout << s.pop() << " Popped from stack\n"; + + return 0; +} diff --git a/out/production/PreCourse-1/Exercise_1.js b/out/production/PreCourse-1/Exercise_1.js new file mode 100644 index 000000000..207189ea0 --- /dev/null +++ b/out/production/PreCourse-1/Exercise_1.js @@ -0,0 +1,35 @@ +class Stack { + //Please read sample.java file before starting. + //Kindly include Time and Space complexity at top of each file +​ + constructor() { + //Initialize your constructor + this.MAX = 1000; + this.top = -1; + this.a = new Array(this.MAX); + } +​ + function isEmpty() { + //Write your code here + } +​ + function push(x) { + //Check for stack Overflow + //Write your code here + } +​ + function pop() { + //If empty return 0 and print " Stack Underflow" + //Write your code here + } +​ + function peek() { + //Write your code here + } +} +​ +let s = new Stack(); +s.push(10); +s.push(20); +s.push(30); +console.log(s.pop() + " Popped from stack"); diff --git a/out/production/PreCourse-1/Exercise_1.py b/out/production/PreCourse-1/Exercise_1.py new file mode 100644 index 000000000..532833f5d --- /dev/null +++ b/out/production/PreCourse-1/Exercise_1.py @@ -0,0 +1,24 @@ +class myStack: + #Please read sample.java file before starting. + #Kindly include Time and Space complexity at top of each file + def __init__(self): + + def isEmpty(self): + + def push(self, item): + + def pop(self): + + + def peek(self): + + def size(self): + + def show(self): + + +s = myStack() +s.push('1') +s.push('2') +print(s.pop()) +print(s.show()) diff --git a/out/production/PreCourse-1/Exercise_2.cpp b/out/production/PreCourse-1/Exercise_2.cpp new file mode 100644 index 000000000..1eb3de9b9 --- /dev/null +++ b/out/production/PreCourse-1/Exercise_2.cpp @@ -0,0 +1,52 @@ +#include +using namespace std; + +// A structure to represent a stack +class StackNode { +public: + int data; + StackNode* next; +}; + +StackNode* newNode(int data) +{ + StackNode* stackNode = new StackNode(); + stackNode->data = data; + stackNode->next = NULL; + return stackNode; +} + +int isEmpty(StackNode* root) +{ + //Your code here +} + +void push(StackNode** root, int data) +{ + //Your code here +} + +int pop(StackNode** root) +{ + //Your code here +} + +int peek(StackNode* root) +{ + //Your code here +} + +int main() +{ + StackNode* root = NULL; + + push(&root, 10); + push(&root, 20); + push(&root, 30); + + cout << pop(&root) << " popped from stack\n"; + + cout << "Top element is " << peek(root) << endl; + + return 0; +} \ No newline at end of file diff --git a/out/production/PreCourse-1/Exercise_2.js b/out/production/PreCourse-1/Exercise_2.js new file mode 100644 index 000000000..2e3216f94 --- /dev/null +++ b/out/production/PreCourse-1/Exercise_2.js @@ -0,0 +1,36 @@ +class StackAsLinkedList { +​ + static stackNode = class { +​ + constructor(d) { + //Constructor here + this.data = d; + this.next = null; + } + } +​ + function isEmpty() { + //Write your code here for the condition if stack is empty. + } +​ + function push(data) { + //Write code to push data to the stack. + } +​ + function pop() { + //If Stack Empty Return 0 and print "Stack Underflow" + //Write code to pop the topmost element of stack. + //Also return the popped element + } +​ + function peek() { + //Write code to just return the topmost element without removing it. + } +} +//Driver code +const sll = new StackAsLinkedList(); +sll.push(10); +sll.push(20); +sll.push(30); +console.log(sll.pop() + " popped from stack"); +console.log("Top element is " + sll.peek()); diff --git a/out/production/PreCourse-1/Exercise_2.py b/out/production/PreCourse-1/Exercise_2.py new file mode 100644 index 000000000..b11492215 --- /dev/null +++ b/out/production/PreCourse-1/Exercise_2.py @@ -0,0 +1,32 @@ + +class Node: + def __init__(self, data): + self.data = data + self.next = None + +class Stack: + def __init__(self): + + def push(self, data): + + def pop(self): + +a_stack = Stack() +while True: + #Give input as string if getting an EOF error. Give input like "push 10" or "pop" + print('push ') + print('pop') + print('quit') + do = input('What would you like to do? ').split() + #Give input as string if getting an EOF error. Give input like "push 10" or "pop" + operation = do[0].strip().lower() + if operation == 'push': + a_stack.push(int(do[1])) + elif operation == 'pop': + popped = a_stack.pop() + if popped is None: + print('Stack is empty.') + else: + print('Popped value: ', int(popped)) + elif operation == 'quit': + break diff --git a/out/production/PreCourse-1/Exercise_3.cpp b/out/production/PreCourse-1/Exercise_3.cpp new file mode 100644 index 000000000..f34d89ac1 --- /dev/null +++ b/out/production/PreCourse-1/Exercise_3.cpp @@ -0,0 +1,80 @@ +#include +using namespace std; + +// A linked list node (changes) +class Node +{ + public: + int data; + Node *next; +}; + +/* Given a reference (pointer to pointer) +to the head of a list and an int, inserts +a new node on the front of the list. */ +void push(Node** head_ref, int new_data) +{ + /* 1. allocate node */ + + /* 2. put in the data */ + + /* 3. Make next of new node as head */ + + /* 4. move the head to point to the new node */ +} + +/* Given a node prev_node, insert a new node after the given +prev_node */ +void insertAfter(Node* prev_node, int new_data) +{ + /*1. check if the given prev_node is NULL */ + + /* 2. allocate new node */ + + /* 3. put in the data */ + + /* 4. Make next of new node as next of prev_node */ + + /* 5. move the next of prev_node as new_node */ +} + +/* Given a reference (pointer to pointer) to the head +of a list and an int, appends a new node at the end */ +void append(Node** head_ref, int new_data) +{ + /* 1. allocate node */ + + /* 2. put in the data */ + + /* 3. This new node is going to be + the last node, so make next of + it as NULL*/ + + /* 4. If the Linked List is empty, + then make the new node as head */ + + /* 5. Else traverse till the last node */ + + /* 6. Change the next of last node */ +} + +// This function prints contents of +// linked list starting from head +void printList(Node *node) +{ + //Your code here +} + +/* Driver code*/ +int main() +{ + Node* head = NULL; + append(&head, 6); + push(&head, 7); + push(&head, 1); + append(&head, 4); + insertAfter(head->next, 8); + cout<<"Created Linked list is: "; + printList(head); + return 0; +} \ No newline at end of file diff --git a/out/production/PreCourse-1/Exercise_3.js b/out/production/PreCourse-1/Exercise_3.js new file mode 100644 index 000000000..d1511f80e --- /dev/null +++ b/out/production/PreCourse-1/Exercise_3.js @@ -0,0 +1,49 @@ +// Java program to implement +// a Singly Linked List +class LinkedList { + constructor() { + this.head = null; + } + // Linked list Node. + static Node = class { + constructor(d) { + this.data = d; + this.next = null; + } + } +​ + // Method to insert a new node + function insert(list, data) { + // Create a new node with given data +​ + // If the Linked List is empty, + // then make the new node as head +​ + // Else traverse till the last node + // and insert the new_node there +​ + // Insert the new_node at last node + // Return the list by head + } +​ + // Method to print the LinkedList. + function printList(list) { + // Traverse through the LinkedList +​ + // Print the data at current node +​ + // Go to next node + } +} + // Driver code + /* Start with the empty list. */ + let list = new LinkedList(); +​ + // ******INSERTION****** + // Insert the values + list.insert(list, 1); + list.insert(list, 2); + list.insert(list, 3); + list.insert(list, 4); + // Print the LinkedList + list.printList(list); diff --git a/out/production/PreCourse-1/Exercise_3.py b/out/production/PreCourse-1/Exercise_3.py new file mode 100644 index 000000000..a5d466b59 --- /dev/null +++ b/out/production/PreCourse-1/Exercise_3.py @@ -0,0 +1,32 @@ +class ListNode: + """ + A node in a singly-linked list. + """ + def __init__(self, data=None, next=None): + +class SinglyLinkedList: + def __init__(self): + """ + Create a new singly-linked list. + Takes O(1) time. + """ + self.head = None + + def append(self, data): + """ + Insert a new element at the end of the list. + Takes O(n) time. + """ + + def find(self, key): + """ + Search for the first element with `data` matching + `key`. Return the element or `None` if not found. + Takes O(n) time. + """ + + def remove(self, key): + """ + Remove the first occurrence of `key` in the list. + Takes O(n) time. + """ diff --git a/out/production/PreCourse-1/LinkedList$Node.class b/out/production/PreCourse-1/LinkedList$Node.class new file mode 100644 index 0000000000000000000000000000000000000000..662c6a4f052dd834f4f60a224d91e0e87fd4058c GIT binary patch literal 435 zcmZ8dO-sW-5PjRGO&Vj<4~^QYc<|8nU=JP@L5gA^vQ}; zlzaVY4GwBHTn`)Y82m_PPa=t=(#PXG5e!zsHD_R0G!7~I=@QN-d}8nJ)16h$nRxIaBH zi!eB2q4Z6zw2dx_|K>AzVU~$vlyap6nOWxjIHFgV=x0pOhJ-LH5HgAinv`2~nvlY1 z{J|U8pu2)SU@L6C5>-N*umy{-O}LF30@SgCEn#?KZ~*5URESJX literal 0 HcmV?d00001 diff --git a/out/production/PreCourse-1/LinkedList.class b/out/production/PreCourse-1/LinkedList.class new file mode 100644 index 0000000000000000000000000000000000000000..64d60fae26c22c01350917ccb28dda991dbdac1b GIT binary patch literal 1681 zcmaJ>+fEx-6kW$2GqxEnF%2OQC?O>E1>&ak?vyk!p`jg{G^V6cAF6|W1QVMXG&7_@ zed%ZP4|wcFG(?Hi$5iT<^aJ`-p{DE1Si%TYjb_ie?7hy~Ywt6E{`=y00JrgV76~Lx z7#33K6BvFhpU84Yx|`+IjmN4P3iRD{Tqj%CF=pW+ z#!pad>;<9PCL?c`1kc+MX~!$y_Z>HEguas75!@vUlb9l0ONLTFtmK&Vw1vx<5xB4| z+p6lhO&LCP!Yz)1P`Y72K;{r*MnVwKaW^Yj%;KtvYZl%@USQ;mLj_Vhnu3Nn4NzE5 zqezz}&sCQ-+MI=X4P{0_9XCtalG?m&;RfEJ^o|=SpKufT9=R%HcPt)x4d7i1@8Nxc zOoXHh!z!JKDXde5DvK4DPt|v~He^{ia%W zG|!>CPnF+v0`={}buGU@e_aJ(P3c?+F?`4K!XWhJPECbdUMooBb9RZCUmWU#okb0G z6RW!Z_XTE;TitP=cx_dV3mvz_vTTN)zbEixZza2qG5S5}wmK@9wLP!ByHh!xT+hmh zz_q;{b%uLy{_*9j^tNFaqAEL`h7+m^OS9s-%CE8_fnxTCmfOUdz|~W!oyFJ$dt&PU zUD<q}AKn?IT*NJN_6I&N8~k zxuS!ALNbC|cnR~-#33@Z;sLBb&|jSU4c0y`>1lob0J&G_*Pr_S>%Zr@mn;6v@MLt< z4ALA=5qO3SuV9Q9brN}Av;yY%+#p9yqsXHs`JcJTERvir;FE}u9`ScUN*VerayNln z+|R){!k7v32nOxoKa9`l`_?7@1O2oz1x?Z}y~6mfIA1!z#0$I$Ji`@^bN2r0zqp($ zJVQyV6H^|iJ|IwvDr87*j6|kMC(q+G)zKKZOEAS$J|!&?(aIokgcJ#lGxRp@blH60 zWm9^Ifk%h9ZkLSbDBGn}Wcwm(Mm8PU=U6zdRxIHXh5Q18uqjdvKAtA8#B0 literal 0 HcmV?d00001 diff --git a/out/production/PreCourse-1/Main.class b/out/production/PreCourse-1/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..0fb9c965fc36b274cced4083eeb5ee045111f0fa GIT binary patch literal 1090 zcmaJ=?M@Rx6g^{07uMBQJ_Qx4f)*-N{6veOHWEn|B`JZZKg_Tl>Co-YW_L>DO?(ag z0SP8PfDdK7vr9q=jq_tZ?!9x)y=UhB`Fs2uz-zp+aRC_%SqFW{F%ScyZX=ckpKSN(#bFXE?LdHxN9XPnekPSO=la|uj%%=h5QLu2u!61gt zz}639E!u>pIs`uACWKN|HX<45x{d^IR}JcjgHeo8T&Ti?du@<19(OQ-YYby;-V!wx zcwBEw-K1Ttd7xuLB>EIIse%w?uuF(HFlphYgCcG*4E11TutJlA9~hAH5T^J$RNgw5 z6p^i|hG59MG7#@O?Hv(q@*STngRb(pzr`bI&L_sKZc556=bFn^y4_AdMoXW2@sOWK zyA(gv!_C0RW4Xy25R_e4oyZfb(vauheiM-=WASBS-jqnnzfnrZI^yBF&`s5d`|*f? zS#d*!p=cDpMyg#T?Yve#hbK0k;+cg-qw;fxsng#egMHN!l~m4D_*L#{6&)~q?^f$1 zFlBqkgN85SDOaghC#;??w##zn;^sjpdW3iDk^awW_hX+x)VS~0r52=)vlav*s`)&Q zMQmY-VftK6y;8M6AAa)xq2@i4y68{crZzIe%+yFA?Pyn_l^M(I5!jE!Jx#N51BV_XFeas8BJ zf@pv$`msd4_>!7wnR;La_wgzr9!I`LV>Ue;K#Ln=TtPk;mPB!hT Igtdb4e^fpON&o-= literal 0 HcmV?d00001 diff --git a/out/production/PreCourse-1/PreCourse-1.iml b/out/production/PreCourse-1/PreCourse-1.iml new file mode 100644 index 000000000..b107a2dd8 --- /dev/null +++ b/out/production/PreCourse-1/PreCourse-1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/PreCourse-1/README.md b/out/production/PreCourse-1/README.md new file mode 100644 index 000000000..1e1abed69 --- /dev/null +++ b/out/production/PreCourse-1/README.md @@ -0,0 +1,11 @@ +# PreCourse_1 + +# All Instructions are already provided in the respective files. + +Exercise_1 : Implement Stack using Array. + +Exercise_2 : Implement Stack using Linked List. + +Exercise_3 : Implement Singly Linked List. + +*After completing the project kindly submit a pull request* diff --git a/out/production/PreCourse-1/Stack.class b/out/production/PreCourse-1/Stack.class new file mode 100644 index 0000000000000000000000000000000000000000..8136af7881a3973c4bec5d42dc24ef90bf529c47 GIT binary patch literal 1056 zcmZvaQBTuQ7>3`|mUYaIu?-NI;zW^cDg#k(Fh)W!Su(_Ay6C*nGAb0ewplxb|Kf#S zdBcrHG%>~>;2)7+VSGMgRG7b1EUx_MX2rjfz{?lw@c1wHDudv`C-R)f?CkA%=S_o;{rorQu*~=tMjtu zzD{5gIUVN=oX3v7}-QW5yEvl)@&m_D}Ie%@+( z!9Md_TYe&tTyY&gFrA=owz`%Is7JKe{%S9%P;3ZjEAFO6Zq;_I2i^9D)p=xYw78O~ zx=piHH#@eR_ZGEa+x7{mhG{I(5q_+h-k$)k>u-}WzVvBREe6~ z?KG|Xw)CV{_pDCS_O0g&bFweU^F-o2Y8B(Sgct-abEaU1BTt+oF;0k6LQQ&Na zF@o=*(kBSzEp+WYH1&WhDvBH>3A_{~jz$!TtGLG5bv^@7jC)al{3(Hz9xz+_0=<-0 zkG>@ikt`{P5Fhwk38@)q{7!L?BIL1d7V}}jvNRQ9gs%nM z=w)CMBukx^8N7+~7f$ON+9vgLC-SJy8R+bIiak%W`jbvh_jQuGG~tWKx<;>$xjx-R e>XfKj=J1cFOwT+$3-m1Zd2)Yy1a8u$;MQ;Z-KdcO literal 0 HcmV?d00001 diff --git a/out/production/PreCourse-1/StackAsLinkedList$StackNode.class b/out/production/PreCourse-1/StackAsLinkedList$StackNode.class new file mode 100644 index 0000000000000000000000000000000000000000..4236c40143a63fa6e7bff6dcd6b6fe350085d81d GIT binary patch literal 467 zcmaJ-O;5r=6r6=ZX)P4+6OqIN2jC!ySB(iF8c7;BV7Qv4Y;>WvNp~^)Ef2)RgFnC@ zWqezW7ZcO$yzT6p*`4?C`SuQAfR>9K@-{3F1r!;oOa9FJ5sx4GllfAFnxS|pW2vtg z@}2I?K?#lx*TW7xhUQfBa5YeYj8|e2NTu5uGfozQ!CG+58Q93EDjs}PiHyaDTwB3E z(hF+qjJh)_!_3L23&eQ+G#BX|pGV|f50a2aGoDKG|3g~(Q7Q&^nyk}M+(^^tUvESj zN+s^k&rCRm(pV^cn<#DLn4$LP9Sq(mjzv0*xKe`roZn11r6f6;oLMvhLYP>Dj8*|P zs&(2;sKfO5y;rbaa|^r2wkW?4mBTJ!9TuTW=)pl575eswIrx@gKQlGv<{BD4ofz#Q QjZBrXn6n<_J*d%Nq4KF3o(x`wWP-3gnVz3qvY&6hnC@rnpS(01WX0w~wT}t@@ zj(bj9;DcH#v^a-Hnn?m`*15<=k`6^E~I=J%9c4`VRohc$7p0Q4KL2 zJ?IrkKQW#fMa!`Finn*4$eJ(EyJXs?e?uTTliyAtj)aD!jy~uD=c>L@Yb<*e({9Lm z#q{VOa~+4%#Y)%NWMJ8J>awJvUts(l9!aE-R;11`;!HWeoh0(0jv)*SXr{N;Z23n4 zrw0kTp4Ty|2*qsq%uiqp;~FmLxQL0jG*yp0Up9HoIUvR1N}$$sig#So_N%@tjb z>G`hF+K~RfQ}^Py&F~^eJ|vWT>^jXH^Hyub@h#oAoK{X+vMFsp#{!9gUR0CV!d(s9 zD)09MCQrW_(|+nSWHGFHSc-L{<~uGQ>o1+JqU{)RxMkRNOL~(P$7vk2O5KU*u)K9~ z>!>BqaPQ1j_#Kxz%ij*MYFJj)^d-xrmu*|RtCrz;k~vBQRa14+@K9i?OW#?vHT)nj z@orbPlTagae0veTUBN$l3CCXk*@S5MoU0;db=Ffjf%uJ!2ySpx$Li7-9QDuvH`&OP zjlF@Ry1c?!`K1akq5TOh_8hV33mT#wL54emq}oAN=+lEp-%WL&pB_gQ?`K|&a-M#J z)Xw+`1~v-E$oz`F!rUup&yk)}K(8=oM(Xeccm81F@2C^9ec;Zh-7 zjF98_srryq9vYzrFiVk_k;ObFnR7*IB#hc7m1WcVG9aa>L?Kj8*fH89?$cRiI@>{F zmLwwokvPT8AV$YeiMv4DYs6jbs6e)j_diMkYglii{M44Z_y+Nv6I`y$rjy5*pG^-1 z;{->lC+?Nk1OV~F?c!@J1>4gHG(mh2E6&vRGs#0#H%6d5Zs9u09T`}}SG0kiS7=`* rl^DL}K7wyh;T)qSg$=IyY5R`5&0xHP`?O_fOY!aw{}1pzenj?P?+1%< literal 0 HcmV?d00001 From f95bfbafc8a74cd9caa5bb974c109da38c3ee979 Mon Sep 17 00:00:00 2001 From: dhruvil15 <76967484+dhruvil15@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:45:13 -0400 Subject: [PATCH 2/2] Add time and Space Complexity --- Exercise_1.java | 2 ++ Exercise_2.java | 3 ++- Exercise_3.java | 18 +++++++++--------- .../PreCourse-1/LinkedList$Node.class | Bin 435 -> 435 bytes out/production/PreCourse-1/LinkedList.class | Bin 1681 -> 1669 bytes out/production/PreCourse-1/Main.class | Bin 1090 -> 1090 bytes out/production/PreCourse-1/Stack.class | Bin 1056 -> 1056 bytes .../StackAsLinkedList$StackNode.class | Bin 467 -> 467 bytes .../PreCourse-1/StackAsLinkedList.class | Bin 1910 -> 1910 bytes 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Exercise_1.java b/Exercise_1.java index e873657f5..404ed95c5 100644 --- a/Exercise_1.java +++ b/Exercise_1.java @@ -1,6 +1,8 @@ class Stack { //Please read sample.java file before starting. //Kindly include Time and Space complexity at top of each file + // Time Complexity: o(1) + // Space Complexity: o(MAX); static final int MAX = 1000; int top; int a[] = new int[MAX]; // Maximum size of Stack diff --git a/Exercise_2.java b/Exercise_2.java index 1f6731c04..926bd970d 100644 --- a/Exercise_2.java +++ b/Exercise_2.java @@ -1,5 +1,6 @@ class StackAsLinkedList { - + // Time Complexity: o(1) + // Space Complexity: o(N) where N being size of the data; StackNode root; static class StackNode { diff --git a/Exercise_3.java b/Exercise_3.java index 8ca4bb60b..99239e444 100644 --- a/Exercise_3.java +++ b/Exercise_3.java @@ -3,8 +3,10 @@ // Java program to implement // a Singly Linked List class LinkedList { - + // Time Complexity: o(1) // Reduce from o(N) to o(1) by introducing tail + // Space Complexity: o(N) where N being size of the data; Node head; // head of list + Node tail; // Tail of the list to improve insertion // Linked list Node. // This inner class is made static @@ -33,15 +35,13 @@ public static LinkedList insert(LinkedList list, int data) // then make the new node as head if (list.head == null) { list.head = newNode; + // first node is both head and tail + list.tail = newNode; } else { - // Else traverse till the last node - // and insert the new_node there - Node last = list.head; - while (last.next != null) { - last = last.next; - } - // Insert the new_node at last node - last.next = newNode; + // link to end + list.tail.next = newNode; + // advance tail + list.tail = newNode; } // Return the list by head return list; diff --git a/out/production/PreCourse-1/LinkedList$Node.class b/out/production/PreCourse-1/LinkedList$Node.class index 662c6a4f052dd834f4f60a224d91e0e87fd4058c..ea728a17586cabf1c46a0a4ddcc2afe33de30f24 100644 GIT binary patch delta 25 gcmdnYyqS4J1|zQs0}F!~11Ezx10RFLuIwT+SX4v$W{RQ`CmvTQIjX*KKi=%F`o z%nBvFWGfm98ZHobWh_Z*ZSIUoBVG%1Kg0tU2Q`%t-Lo`0=wI zW1I`VnkT`Ov))=VM9kpCp*V9%ZZq$)V23RRPUM@pAAFA#q7MzZ;724E zWU=Rxjp~gN$8bKFkG51VD7KN!UX=Cf{x}ng5*EbP%C8a81I0burS@$SvxQB(&omZ_ zAMmV6uPfLjEw?$03-44P!OqA@OXyI?ZV~m+OdnbDReJFy&rmqLbAJGr!r>Za)zx^r z>9X)0U6h4#evx%?J-Je+&i6{o_PlwERq{WP*`U?mB)7|P*rHEkvEr#B! zxVlf5kp}3bF-F6ltvYe1kOmkJ!CLk^*TG`qzakv-4<{y^jJ8fOUB`J@$MN?_Ep2nE zKmk!)lNSo*TY^nn9(3`|nd#}2DcV7xlop{}EHkYL1;rbR;-%V)7H=#`#KgqZTNfrSx^m~H znIF-G3oogZK;p(k6Muq#K!1QM(}?exHqkWw&iBoCzVklwo_Q5%M8ex9IBg+qu6=+&(kH4{S^mWWvxLA>#KX*6LWi7|HXZ`L*iMBe7?xP=L%yaBP;H-%}5 z84E{{_9|jI;|LgQkE>e~VN4-oA&azteDdsJwf3kQMg*D)$1Kca!P^#YaM8jNj(b1E z18wtp&C3Vg#I6ZwBD-=Rh(Z`elqAYZ@P=n;-}PGp)812U*eh%OL5Vv8W4%&(Io+-c z@*PB!QRm-45CSKd&2d#d!)ZgjXA;0NqiU;dCmF3?ehQ~qnF^6l)bLwq{&BfI$c@o9 z%%anR^%Z?i<|C{o5~?g^Td?b2(5Kc?bN^SCP1||LdCk{KA;f%)C#Q%wi5Oi=B2A-a zk>PKikcz{hR+5);hOeQq&f%<2q%vLxnN03kVK;zt?Ay>gh)Ku}^eC79-#oxnwkmvY z#Tc#+x-E?E;xMp{N#=H;x&QM62JP8xxXO(#VVr(|V+P;aBuk9C<5W*mO_2>z5v1+% z7$iSW3gJ_j2y|djKF-lqTj@B|?=kg9>d}{}0T?MXXUOL~|7)KU-X49az9+Tw$W~k;GMhi{Oz0 VdE8`W6H@ZKtZ;N4w{aIEe*qa0YaIXp diff --git a/out/production/PreCourse-1/Main.class b/out/production/PreCourse-1/Main.class index 0fb9c965fc36b274cced4083eeb5ee045111f0fa..ee12098378ab79bfbf83e068846b9022bf27e151 100644 GIT binary patch delta 39 ucmX@aafo9>3p1nD3p1m|273k_28YT2m|Xz6x(HYR diff --git a/out/production/PreCourse-1/Stack.class b/out/production/PreCourse-1/Stack.class index 8136af7881a3973c4bec5d42dc24ef90bf529c47..428bbd16b30154cb7dbc7f4395f02e1b827d011c 100644 GIT binary patch delta 89 zcmZ3$v4CTP2NNUjWKX70UO@&H1`Y;Z24Myv29e3Dnc@Vc7`Paufjk)o5e9h%RR)F0 oQp`EL>J01*8Vvjlnhb&r+LI?UNAns2MT~$V#y}C%$-kLZ0Zg+DyZ`_I delta 89 zcmZ3$v4CTP2NNUrWKX70UVa7^1~vv>20;cP2BFETnc@T`7`PZDfjlV&5e8WXRR+1q nQp`ELstoK5Y7G1g>Ohs6lP5Dr^Xdad41gkrKoR4~znN75M!yW0 diff --git a/out/production/PreCourse-1/StackAsLinkedList$StackNode.class b/out/production/PreCourse-1/StackAsLinkedList$StackNode.class index 4236c40143a63fa6e7bff6dcd6b6fe350085d81d..0f8326cfb71947c03b58100a46d141421d32ee9b 100644 GIT binary patch delta 25 fcmcc2e3^Me2O}>x0}BH$11AF?5b{r+%4i1wNx1~7 delta 25 gcmcc2e3^Me2O}>R0}BHW11AG710Mt5&!Ej9 z$e_z0$)Lxe!k|A{f-RZX6ewc`lraa&SWfO>tCVzL;9ziK;A3!R5Mgj(kYaFS&}8sn Muwd|