dancealgorithm 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dancealgorithm/__init__.py +128 -0
- dancealgorithm/__main__.py +8 -0
- dancealgorithm/assignments/DA - Campus/Solution.java +198 -0
- dancealgorithm/assignments/DA - Campus/__init__.py +34 -0
- dancealgorithm/assignments/DA - Flight/Solution.java +204 -0
- dancealgorithm/assignments/DA - Flight/__init__.py +34 -0
- dancealgorithm/assignments/DA - Smart/Solution.java +220 -0
- dancealgorithm/assignments/DA - Smart/__init__.py +34 -0
- dancealgorithm/assignments/DA.txt +29 -0
- dancealgorithm/assignments/FK - Advertisement/Solution.java +141 -0
- dancealgorithm/assignments/FK - Advertisement/__init__.py +34 -0
- dancealgorithm/assignments/FK - Electric/Solution.java +168 -0
- dancealgorithm/assignments/FK - Electric/__init__.py +34 -0
- dancealgorithm/assignments/FK - Emergency/Solution.java +159 -0
- dancealgorithm/assignments/FK - Emergency/__init__.py +34 -0
- dancealgorithm/assignments/FK.txt +26 -0
- dancealgorithm/assignments/GC - Classroom/Solution.java +87 -0
- dancealgorithm/assignments/GC - Classroom/__init__.py +34 -0
- dancealgorithm/assignments/GC - Interference/Solution.java +88 -0
- dancealgorithm/assignments/GC - Interference/__init__.py +34 -0
- dancealgorithm/assignments/GC - University/Solution.java +88 -0
- dancealgorithm/assignments/GC - University/__init__.py +34 -0
- dancealgorithm/assignments/GC.txt +25 -0
- dancealgorithm/assignments/K - Cloud/Solution.java +115 -0
- dancealgorithm/assignments/K - Cloud/__init__.py +34 -0
- dancealgorithm/assignments/K - Disaster/Solution.java +116 -0
- dancealgorithm/assignments/K - Disaster/__init__.py +34 -0
- dancealgorithm/assignments/K - Hospital/Solution.java +115 -0
- dancealgorithm/assignments/K - Hospital/__init__.py +34 -0
- dancealgorithm/assignments/K.txt +38 -0
- dancealgorithm/assignments/LC - Delivery/Solution.java +180 -0
- dancealgorithm/assignments/LC - Delivery/__init__.py +34 -0
- dancealgorithm/assignments/LC - Drilling/Solution.java +197 -0
- dancealgorithm/assignments/LC - Drilling/__init__.py +34 -0
- dancealgorithm/assignments/LC - Flight/Solution.java +180 -0
- dancealgorithm/assignments/LC - Flight/__init__.py +34 -0
- dancealgorithm/assignments/LC.txt +31 -0
- dancealgorithm/assignments/MS - Commerce/Solution.java +162 -0
- dancealgorithm/assignments/MS - Commerce/__init__.py +34 -0
- dancealgorithm/assignments/MS - Commerce/dataset.csv +16 -0
- dancealgorithm/assignments/MS - Customer/Solution.java +144 -0
- dancealgorithm/assignments/MS - Customer/__init__.py +34 -0
- dancealgorithm/assignments/MS - Customer/dataset.csv +16 -0
- dancealgorithm/assignments/MS - Library/Solution.java +162 -0
- dancealgorithm/assignments/MS - Library/__init__.py +34 -0
- dancealgorithm/assignments/MS - Library/dataset.csv +16 -0
- dancealgorithm/assignments/MS.txt +32 -0
- dancealgorithm/assignments/MSG - Emergency/Solution.java +211 -0
- dancealgorithm/assignments/MSG - Emergency/__init__.py +34 -0
- dancealgorithm/assignments/MSG - Logistics/Solution.java +189 -0
- dancealgorithm/assignments/MSG - Logistics/__init__.py +34 -0
- dancealgorithm/assignments/MSG - Skyconnect/Solution.java +204 -0
- dancealgorithm/assignments/MSG - Skyconnect/__init__.py +34 -0
- dancealgorithm/assignments/MSG.txt +28 -0
- dancealgorithm/assignments/QS - Commerce/Solution.java +147 -0
- dancealgorithm/assignments/QS - Commerce/__init__.py +34 -0
- dancealgorithm/assignments/QS - Commerce/dataset.csv +16 -0
- dancealgorithm/assignments/QS - Movie/Solution.java +148 -0
- dancealgorithm/assignments/QS - Movie/__init__.py +34 -0
- dancealgorithm/assignments/QS - Movie/dataset.csv +16 -0
- dancealgorithm/assignments/QS - Online/Solution.java +147 -0
- dancealgorithm/assignments/QS - Online/__init__.py +34 -0
- dancealgorithm/assignments/QS - Online/dataset.csv +16 -0
- dancealgorithm/assignments/QS.txt +33 -0
- dancealgorithm/assignments/__init__.py +65 -0
- dancealgorithm/cli.py +349 -0
- dancealgorithm/config.py +125 -0
- dancealgorithm/downloader.py +330 -0
- dancealgorithm-0.1.0.dist-info/METADATA +199 -0
- dancealgorithm-0.1.0.dist-info/RECORD +74 -0
- dancealgorithm-0.1.0.dist-info/WHEEL +5 -0
- dancealgorithm-0.1.0.dist-info/entry_points.txt +3 -0
- dancealgorithm-0.1.0.dist-info/licenses/LICENSE +22 -0
- dancealgorithm-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
PATH = Path(__file__).resolve().parent
|
|
7
|
+
DIR = PATH
|
|
8
|
+
JAVA_SOLUTION = PATH / "Solution.java"
|
|
9
|
+
DATASET_PATH = PATH / "dataset.csv"
|
|
10
|
+
TITLE = "MS - Commerce"
|
|
11
|
+
|
|
12
|
+
def get_code() -> str:
|
|
13
|
+
if JAVA_SOLUTION.exists():
|
|
14
|
+
return JAVA_SOLUTION.read_text(encoding="utf-8")
|
|
15
|
+
return ""
|
|
16
|
+
|
|
17
|
+
def extract(destination: Optional[str | Path] = None, overwrite: bool = True) -> Path:
|
|
18
|
+
from dancealgorithm.downloader import extract_bundled
|
|
19
|
+
from dancealgorithm.config import get_destination
|
|
20
|
+
target = Path(destination) if destination else get_destination()
|
|
21
|
+
extract_bundled(target, subject_filter=TITLE, overwrite=overwrite)
|
|
22
|
+
return target / PATH.name
|
|
23
|
+
|
|
24
|
+
def open_folder() -> None:
|
|
25
|
+
import os
|
|
26
|
+
if sys.platform == "win32":
|
|
27
|
+
os.system(f'explorer "{PATH}"')
|
|
28
|
+
|
|
29
|
+
def __getattr__(name: str):
|
|
30
|
+
if name in ("code", "java_code", "solution_code"):
|
|
31
|
+
return get_code()
|
|
32
|
+
if name in ("path", "folder", "dir"):
|
|
33
|
+
return PATH
|
|
34
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
tx_id,customer_name,amount,timestamp
|
|
2
|
+
TXN-501,Rajesh Kumar,1299,2024-02-10 09:12:00
|
|
3
|
+
TXN-502,Sunita Menon,4599,2024-02-04 14:35:00
|
|
4
|
+
TXN-503,Deepak Chopra,899,2024-02-15 11:20:00
|
|
5
|
+
TXN-504,Kavita Sen,3450,2024-02-01 16:50:00
|
|
6
|
+
TXN-505,Arjun Das,6200,2024-02-12 18:05:00
|
|
7
|
+
TXN-506,Meera Pillai,2100,2024-02-08 10:40:00
|
|
8
|
+
TXN-507,Suresh Raina,5400,2024-02-14 13:15:00
|
|
9
|
+
TXN-508,Anita Roy,1850,2024-02-06 17:25:00
|
|
10
|
+
TXN-509,Gaurav Bhatt,7300,2024-02-11 12:30:00
|
|
11
|
+
TXN-510,Poonam Yadav,2990,2024-02-03 08:55:00
|
|
12
|
+
TXN-511,Nikhil Bansal,4120,2024-02-13 15:45:00
|
|
13
|
+
TXN-512,Shweta Tiwari,9800,2024-02-02 19:10:00
|
|
14
|
+
TXN-513,Harish Rawat,1650,2024-02-09 11:05:00
|
|
15
|
+
TXN-514,Preeti Jain,5100,2024-02-07 14:15:00
|
|
16
|
+
TXN-515,Varun Kapoor,3750,2024-02-05 16:30:00
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
|
|
5
|
+
public class Solution {
|
|
6
|
+
// 1. Main Function
|
|
7
|
+
|
|
8
|
+
public static void main(String A[]) {
|
|
9
|
+
Scanner sobj = new Scanner(System.in);
|
|
10
|
+
|
|
11
|
+
int iSize = 0;
|
|
12
|
+
|
|
13
|
+
// 5. Read Dataset and Store Records
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
Scanner fobj = new Scanner(new File("dataset.csv"));
|
|
17
|
+
|
|
18
|
+
fobj.nextLine(); // Skip header row
|
|
19
|
+
|
|
20
|
+
while (fobj.hasNextLine()) {
|
|
21
|
+
fobj.nextLine();
|
|
22
|
+
iSize++;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fobj.close();
|
|
26
|
+
|
|
27
|
+
CustomerOrder Arr[] = new CustomerOrder[iSize];
|
|
28
|
+
|
|
29
|
+
fobj = new Scanner(new File("dataset.csv"));
|
|
30
|
+
|
|
31
|
+
fobj.nextLine(); // Skip header row
|
|
32
|
+
|
|
33
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
34
|
+
String sLine = fobj.nextLine();
|
|
35
|
+
String sData[] = sLine.split(",");
|
|
36
|
+
|
|
37
|
+
String sID = sData[0].trim().replace("\"", "");
|
|
38
|
+
String sName = sData[1].trim().replace("\"", "");
|
|
39
|
+
String sAmount = sData[2].trim().replace("\"", "");
|
|
40
|
+
String sTimestamp = sData[3].trim().replace("\"", "");
|
|
41
|
+
|
|
42
|
+
Arr[iCnt] = new CustomerOrder(sID, sName, sAmount, sTimestamp);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fobj.close();
|
|
46
|
+
|
|
47
|
+
// 6. Call Merge Sort
|
|
48
|
+
|
|
49
|
+
MergeSort(Arr, 0, iSize - 1);
|
|
50
|
+
|
|
51
|
+
// 7. Display Sorted Records
|
|
52
|
+
|
|
53
|
+
System.out.println("\nOrders Sorted by Timestamp:");
|
|
54
|
+
|
|
55
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
56
|
+
System.out.println(Arr[iCnt].sOrderID + " " +
|
|
57
|
+
Arr[iCnt].sCustomerName + " " +
|
|
58
|
+
Arr[iCnt].sAmount + " " +
|
|
59
|
+
Arr[iCnt].sTimestamp);
|
|
60
|
+
}
|
|
61
|
+
} catch (Exception e) {
|
|
62
|
+
System.out.println("Error: " + e.getMessage());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
sobj.close();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 2. Customer Order Entity
|
|
69
|
+
|
|
70
|
+
static class CustomerOrder {
|
|
71
|
+
String sOrderID;
|
|
72
|
+
String sCustomerName;
|
|
73
|
+
String sAmount;
|
|
74
|
+
String sTimestamp;
|
|
75
|
+
|
|
76
|
+
CustomerOrder(String sOrderID, String sCustomerName,
|
|
77
|
+
String sAmount, String sTimestamp) {
|
|
78
|
+
this.sOrderID = sOrderID;
|
|
79
|
+
this.sCustomerName = sCustomerName;
|
|
80
|
+
this.sAmount = sAmount;
|
|
81
|
+
this.sTimestamp = sTimestamp;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 3. Merge Function
|
|
86
|
+
|
|
87
|
+
public static void Merge(CustomerOrder Arr[], int iStart, int iMid, int iEnd) {
|
|
88
|
+
int iSize1 = iMid - iStart + 1;
|
|
89
|
+
int iSize2 = iEnd - iMid;
|
|
90
|
+
|
|
91
|
+
CustomerOrder LeftArr[] = new CustomerOrder[iSize1];
|
|
92
|
+
CustomerOrder RightArr[] = new CustomerOrder[iSize2];
|
|
93
|
+
|
|
94
|
+
for (int iCnt = 0; iCnt < iSize1; iCnt++) {
|
|
95
|
+
LeftArr[iCnt] = Arr[iStart + iCnt];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (int iCnt = 0; iCnt < iSize2; iCnt++) {
|
|
99
|
+
RightArr[iCnt] = Arr[iMid + 1 + iCnt];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
int i = 0;
|
|
103
|
+
int j = 0;
|
|
104
|
+
int k = iStart;
|
|
105
|
+
|
|
106
|
+
while (i < iSize1 && j < iSize2) {
|
|
107
|
+
if (LeftArr[i].sTimestamp.compareTo(RightArr[j].sTimestamp) <= 0) {
|
|
108
|
+
Arr[k] = LeftArr[i];
|
|
109
|
+
i++;
|
|
110
|
+
} else {
|
|
111
|
+
Arr[k] = RightArr[j];
|
|
112
|
+
j++;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
k++;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
while (i < iSize1) {
|
|
119
|
+
Arr[k] = LeftArr[i];
|
|
120
|
+
i++;
|
|
121
|
+
k++;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
while (j < iSize2) {
|
|
125
|
+
Arr[k] = RightArr[j];
|
|
126
|
+
j++;
|
|
127
|
+
k++;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 4. Merge Sort Function
|
|
132
|
+
|
|
133
|
+
public static void MergeSort(CustomerOrder Arr[], int iStart, int iEnd) {
|
|
134
|
+
if (iStart < iEnd) {
|
|
135
|
+
int iMid = (iStart + iEnd) / 2;
|
|
136
|
+
|
|
137
|
+
MergeSort(Arr, iStart, iMid);
|
|
138
|
+
|
|
139
|
+
MergeSort(Arr, iMid + 1, iEnd);
|
|
140
|
+
|
|
141
|
+
Merge(Arr, iStart, iMid, iEnd);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
PATH = Path(__file__).resolve().parent
|
|
7
|
+
DIR = PATH
|
|
8
|
+
JAVA_SOLUTION = PATH / "Solution.java"
|
|
9
|
+
DATASET_PATH = PATH / "dataset.csv"
|
|
10
|
+
TITLE = "MS - Customer"
|
|
11
|
+
|
|
12
|
+
def get_code() -> str:
|
|
13
|
+
if JAVA_SOLUTION.exists():
|
|
14
|
+
return JAVA_SOLUTION.read_text(encoding="utf-8")
|
|
15
|
+
return ""
|
|
16
|
+
|
|
17
|
+
def extract(destination: Optional[str | Path] = None, overwrite: bool = True) -> Path:
|
|
18
|
+
from dancealgorithm.downloader import extract_bundled
|
|
19
|
+
from dancealgorithm.config import get_destination
|
|
20
|
+
target = Path(destination) if destination else get_destination()
|
|
21
|
+
extract_bundled(target, subject_filter=TITLE, overwrite=overwrite)
|
|
22
|
+
return target / PATH.name
|
|
23
|
+
|
|
24
|
+
def open_folder() -> None:
|
|
25
|
+
import os
|
|
26
|
+
if sys.platform == "win32":
|
|
27
|
+
os.system(f'explorer "{PATH}"')
|
|
28
|
+
|
|
29
|
+
def __getattr__(name: str):
|
|
30
|
+
if name in ("code", "java_code", "solution_code"):
|
|
31
|
+
return get_code()
|
|
32
|
+
if name in ("path", "folder", "dir"):
|
|
33
|
+
return PATH
|
|
34
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
order_id,customer_name,amount,timestamp
|
|
2
|
+
ORD-101,Aarav Sharma,4500,2024-01-15 10:30:00
|
|
3
|
+
ORD-102,Priya Patel,2800,2024-01-12 14:20:00
|
|
4
|
+
ORD-103,Rohan Verma,7200,2024-01-20 09:15:00
|
|
5
|
+
ORD-104,Ananya Iyer,1500,2024-01-10 16:45:00
|
|
6
|
+
ORD-105,Vikram Singh,8900,2024-01-18 11:10:00
|
|
7
|
+
ORD-106,Sneha Kulkarni,3400,2024-01-14 18:25:00
|
|
8
|
+
ORD-107,Aditya Nair,6100,2024-01-11 12:05:00
|
|
9
|
+
ORD-108,Pooja Mehta,9500,2024-01-19 15:50:00
|
|
10
|
+
ORD-109,Karan Gupta,2100,2024-01-13 17:30:00
|
|
11
|
+
ORD-110,Neha Reddy,5300,2024-01-16 08:40:00
|
|
12
|
+
ORD-111,Siddharth Joshi,4100,2024-01-09 13:20:00
|
|
13
|
+
ORD-112,Divya Rao,7800,2024-01-17 19:15:00
|
|
14
|
+
ORD-113,Amit Deshmukh,3200,2024-01-21 10:05:00
|
|
15
|
+
ORD-114,Ritu Saxena,6700,2024-01-08 11:45:00
|
|
16
|
+
ORD-115,Manish Pandey,4900,2024-01-22 16:00:00
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
|
|
5
|
+
class Solution {
|
|
6
|
+
// 1. Main Function
|
|
7
|
+
// Initially created the main function as the entry point.
|
|
8
|
+
|
|
9
|
+
public static void main(String A[]) {
|
|
10
|
+
int iSize = 0;
|
|
11
|
+
|
|
12
|
+
// 6. Main Logic
|
|
13
|
+
// Read the dataset, basort books and display results.
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// 6.1 Count Number of Books
|
|
17
|
+
|
|
18
|
+
BufferedReader bobj = new BufferedReader(new FileReader("dataset.csv"));
|
|
19
|
+
|
|
20
|
+
bobj.readLine(); // Skip header
|
|
21
|
+
|
|
22
|
+
while (bobj.readLine() != null) {
|
|
23
|
+
iSize++;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
bobj.close();
|
|
27
|
+
|
|
28
|
+
// 6.2 Create Book Array
|
|
29
|
+
|
|
30
|
+
Book Arr[] = new Book[iSize];
|
|
31
|
+
|
|
32
|
+
// 6.3 Read Book Details
|
|
33
|
+
|
|
34
|
+
bobj = new BufferedReader(new FileReader("dataset.csv"));
|
|
35
|
+
|
|
36
|
+
bobj.readLine(); // Skip header
|
|
37
|
+
|
|
38
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
39
|
+
String sLine = bobj.readLine();
|
|
40
|
+
String sData[] = sLine.split(",", -1);
|
|
41
|
+
|
|
42
|
+
String sID = sData[0].trim().replace("\"", "");
|
|
43
|
+
String sName = sData[1].trim().replace("\"", "");
|
|
44
|
+
String sDeadline = sData[3].trim().replace("\"", "");
|
|
45
|
+
|
|
46
|
+
Arr[iCnt] = new Book(sID, sName, sDeadline);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bobj.close();
|
|
50
|
+
|
|
51
|
+
System.out.println("Loaded " + iSize + " book records.");
|
|
52
|
+
|
|
53
|
+
// 6.4 Call Merge Sort
|
|
54
|
+
|
|
55
|
+
MergeSort(Arr, 0, iSize - 1);
|
|
56
|
+
|
|
57
|
+
// 6.5 Display Sorted Books
|
|
58
|
+
|
|
59
|
+
System.out.println("\nBooks Sorted by Return Deadline:");
|
|
60
|
+
|
|
61
|
+
DisplayBooks(Arr);
|
|
62
|
+
} catch (Exception e) {
|
|
63
|
+
System.out.println("Error: " + e.getMessage());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 2. Book Entity
|
|
68
|
+
// Stores book ID, title and return deadline.
|
|
69
|
+
|
|
70
|
+
static class Book {
|
|
71
|
+
String sBookID;
|
|
72
|
+
String sTitle;
|
|
73
|
+
String sDeadline;
|
|
74
|
+
|
|
75
|
+
Book(String sBookID, String sTitle, String sDeadline) {
|
|
76
|
+
this.sBookID = sBookID;
|
|
77
|
+
this.sTitle = sTitle;
|
|
78
|
+
this.sDeadline = sDeadline;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 3. Merge Function
|
|
83
|
+
// Combines two sorted subarrays into one sorted array.
|
|
84
|
+
|
|
85
|
+
public static void Merge(Book Arr[], int iStart, int iMid, int iEnd) {
|
|
86
|
+
int iSize1 = iMid - iStart + 1;
|
|
87
|
+
int iSize2 = iEnd - iMid;
|
|
88
|
+
|
|
89
|
+
Book LeftArr[] = new Book[iSize1];
|
|
90
|
+
Book RightArr[] = new Book[iSize2];
|
|
91
|
+
|
|
92
|
+
for (int iCnt = 0; iCnt < iSize1; iCnt++) {
|
|
93
|
+
LeftArr[iCnt] = Arr[iStart + iCnt];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (int iCnt = 0; iCnt < iSize2; iCnt++) {
|
|
97
|
+
RightArr[iCnt] = Arr[iMid + 1 + iCnt];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
int i = 0;
|
|
101
|
+
int j = 0;
|
|
102
|
+
int k = iStart;
|
|
103
|
+
|
|
104
|
+
while (i < iSize1 && j < iSize2) {
|
|
105
|
+
if (LeftArr[i].sDeadline.compareTo(RightArr[j].sDeadline) <= 0) {
|
|
106
|
+
Arr[k] = LeftArr[i];
|
|
107
|
+
i++;
|
|
108
|
+
} else {
|
|
109
|
+
Arr[k] = RightArr[j];
|
|
110
|
+
j++;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
k++;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
while (i < iSize1) {
|
|
117
|
+
Arr[k] = LeftArr[i];
|
|
118
|
+
i++;
|
|
119
|
+
k++;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
while (j < iSize2) {
|
|
123
|
+
Arr[k] = RightArr[j];
|
|
124
|
+
j++;
|
|
125
|
+
k++;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 4. Merge Sort Function
|
|
130
|
+
// Recursively divides the array and sorts books.
|
|
131
|
+
|
|
132
|
+
public static void MergeSort(Book Arr[], int iStart, int iEnd) {
|
|
133
|
+
if (iStart < iEnd) {
|
|
134
|
+
int iMid = iStart + (iEnd - iStart) / 2;
|
|
135
|
+
|
|
136
|
+
MergeSort(Arr, iStart, iMid);
|
|
137
|
+
|
|
138
|
+
MergeSort(Arr, iMid + 1, iEnd);
|
|
139
|
+
|
|
140
|
+
Merge(Arr, iStart, iMid, iEnd);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 5. Display Function
|
|
145
|
+
// Displays the first 10 books after sorting.
|
|
146
|
+
|
|
147
|
+
public static void DisplayBooks(Book Arr[]) {
|
|
148
|
+
System.out.printf("%-15s %-35s %-25s%n",
|
|
149
|
+
"BOOK_ID", "TITLE", "RETURN DEADLINE");
|
|
150
|
+
|
|
151
|
+
System.out.println("--------------------------------------------------------------------------");
|
|
152
|
+
|
|
153
|
+
int iLimit = Math.min(Arr.length, 10);
|
|
154
|
+
|
|
155
|
+
for (int iCnt = 0; iCnt < iLimit; iCnt++) {
|
|
156
|
+
System.out.printf("%-15s %-35s %-25s%n",
|
|
157
|
+
Arr[iCnt].sBookID,
|
|
158
|
+
Arr[iCnt].sTitle,
|
|
159
|
+
Arr[iCnt].sDeadline);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
PATH = Path(__file__).resolve().parent
|
|
7
|
+
DIR = PATH
|
|
8
|
+
JAVA_SOLUTION = PATH / "Solution.java"
|
|
9
|
+
DATASET_PATH = PATH / "dataset.csv"
|
|
10
|
+
TITLE = "MS - Library"
|
|
11
|
+
|
|
12
|
+
def get_code() -> str:
|
|
13
|
+
if JAVA_SOLUTION.exists():
|
|
14
|
+
return JAVA_SOLUTION.read_text(encoding="utf-8")
|
|
15
|
+
return ""
|
|
16
|
+
|
|
17
|
+
def extract(destination: Optional[str | Path] = None, overwrite: bool = True) -> Path:
|
|
18
|
+
from dancealgorithm.downloader import extract_bundled
|
|
19
|
+
from dancealgorithm.config import get_destination
|
|
20
|
+
target = Path(destination) if destination else get_destination()
|
|
21
|
+
extract_bundled(target, subject_filter=TITLE, overwrite=overwrite)
|
|
22
|
+
return target / PATH.name
|
|
23
|
+
|
|
24
|
+
def open_folder() -> None:
|
|
25
|
+
import os
|
|
26
|
+
if sys.platform == "win32":
|
|
27
|
+
os.system(f'explorer "{PATH}"')
|
|
28
|
+
|
|
29
|
+
def __getattr__(name: str):
|
|
30
|
+
if name in ("code", "java_code", "solution_code"):
|
|
31
|
+
return get_code()
|
|
32
|
+
if name in ("path", "folder", "dir"):
|
|
33
|
+
return PATH
|
|
34
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
book_id,book_title,borrower,return_deadline
|
|
2
|
+
BK-201,Data Structures in Java,Rahul Sen,2024-03-15
|
|
3
|
+
BK-202,Algorithm Design Manual,Aditi Rao,2024-03-08
|
|
4
|
+
BK-203,Operating System Concepts,Sanjay Dutt,2024-03-22
|
|
5
|
+
BK-204,Database Systems,Pooja Hegde,2024-03-05
|
|
6
|
+
BK-205,Computer Networks,Karan Johar,2024-03-18
|
|
7
|
+
BK-206,Theory of Computation,Anil Kapoor,2024-03-11
|
|
8
|
+
BK-207,Artificial Intelligence,Simran Kaur,2024-03-25
|
|
9
|
+
BK-208,Software Engineering,Ravi Shastri,2024-03-02
|
|
10
|
+
BK-209,Compiler Design,Divya Bharti,2024-03-14
|
|
11
|
+
BK-210,Discrete Mathematics,Manoj Bajpayee,2024-03-09
|
|
12
|
+
BK-211,Computer Architecture,Sunil Shetty,2024-03-20
|
|
13
|
+
BK-212,Cloud Computing,Rekha Sharma,2024-03-04
|
|
14
|
+
BK-213,Cyber Security,Pankaj Tripathi,2024-03-17
|
|
15
|
+
BK-214,Machine Learning Basics,Alia Bhatt,2024-03-07
|
|
16
|
+
BK-215,Big Data Analytics,Vijay Verma,2024-03-21
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
==================================================
|
|
2
|
+
1. MERGE SORT
|
|
3
|
+
==================================================
|
|
4
|
+
|
|
5
|
+
ALGORITHM:
|
|
6
|
+
1. Divide the array into two halves using mid = (low + high) / 2.
|
|
7
|
+
2. Recursively sort the left half.
|
|
8
|
+
3. Recursively sort the right half.
|
|
9
|
+
4. Create temporary arrays L[] and R[].
|
|
10
|
+
5. Compare elements and copy the smaller element into the original array.
|
|
11
|
+
6. Copy the remaining elements.
|
|
12
|
+
7. Repeat until the complete array is sorted.
|
|
13
|
+
|
|
14
|
+
RECURRENCE RELATION:
|
|
15
|
+
T(n) = 2T(n/2) + O(n)
|
|
16
|
+
|
|
17
|
+
RECURSIVE ANALYSIS:
|
|
18
|
+
T(n) = 2T(n/2) + cn
|
|
19
|
+
T(n) = 4T(n/4) + 2cn
|
|
20
|
+
T(n) = 8T(n/8) + 3cn
|
|
21
|
+
|
|
22
|
+
General:
|
|
23
|
+
T(n) = 2^k T(n/2^k) + kcn
|
|
24
|
+
|
|
25
|
+
At k = log2(n):
|
|
26
|
+
T(n) = O(n log n)
|
|
27
|
+
|
|
28
|
+
TIME COMPLEXITY:
|
|
29
|
+
Best Case : O(n log n)
|
|
30
|
+
Average Case : O(n log n)
|
|
31
|
+
Worst Case : O(n log n)
|
|
32
|
+
Space : O(n)
|