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,28 @@
|
|
|
1
|
+
==================================================
|
|
2
|
+
5. MULTISTAGE GRAPH (DYNAMIC PROGRAMMING)
|
|
3
|
+
==================================================
|
|
4
|
+
|
|
5
|
+
ALGORITHM:
|
|
6
|
+
1. Represent the graph using a cost matrix.
|
|
7
|
+
2. Initialize all costs to INF.
|
|
8
|
+
3. Set destination cost = 0.
|
|
9
|
+
4. Process vertices backwards from the last stage.
|
|
10
|
+
5. Check all outgoing edges of the current vertex.
|
|
11
|
+
6. Calculate the cost of every possible path.
|
|
12
|
+
7. Store the minimum cost and next vertex.
|
|
13
|
+
8. Follow next[] to display the optimal path.
|
|
14
|
+
|
|
15
|
+
RECURRENCE RELATION:
|
|
16
|
+
Cost(i) = min { C(i,j) + Cost(j) }
|
|
17
|
+
|
|
18
|
+
BASE CONDITION:
|
|
19
|
+
Cost(destination) = 0
|
|
20
|
+
|
|
21
|
+
RECURRENCE:
|
|
22
|
+
Uses iterative Dynamic Programming (backward approach).
|
|
23
|
+
|
|
24
|
+
TIME COMPLEXITY:
|
|
25
|
+
Best Case : O(V^2)
|
|
26
|
+
Average Case : O(V^2)
|
|
27
|
+
Worst Case : O(V^2)
|
|
28
|
+
Space : O(V) auxiliary space
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
|
|
5
|
+
class Solution {
|
|
6
|
+
// 1. Main Function
|
|
7
|
+
// Entry point of the program.
|
|
8
|
+
|
|
9
|
+
public static void main(String A[]) {
|
|
10
|
+
int iSize = 0;
|
|
11
|
+
|
|
12
|
+
// 6. Main Logic
|
|
13
|
+
// Read product dataset, sort records and display results.
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// 6.1 Count Number of Products
|
|
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 Product Array
|
|
29
|
+
|
|
30
|
+
Product Arr[] = new Product[iSize];
|
|
31
|
+
|
|
32
|
+
// 6.3 Read Product 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 sSortKey = sData[3].trim().replace("\"", "");
|
|
45
|
+
|
|
46
|
+
Arr[iCnt] = new Product(sID, sName, sSortKey);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bobj.close();
|
|
50
|
+
|
|
51
|
+
System.out.println("Loaded " + iSize + " products.");
|
|
52
|
+
|
|
53
|
+
// 6.4 Call Quick Sort
|
|
54
|
+
|
|
55
|
+
QuickSort(Arr, 0, iSize - 1);
|
|
56
|
+
|
|
57
|
+
// 6.5 Display Top 10 Products
|
|
58
|
+
|
|
59
|
+
System.out.println("\nBest Selling Products:");
|
|
60
|
+
|
|
61
|
+
DisplayProducts(Arr);
|
|
62
|
+
} catch (Exception e) {
|
|
63
|
+
System.out.println("Error: " + e.getMessage());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 2. Product Entity
|
|
68
|
+
// Stores product ID, name and sorting parameter.
|
|
69
|
+
|
|
70
|
+
static class Product {
|
|
71
|
+
String sProductID;
|
|
72
|
+
String sProductName;
|
|
73
|
+
String sSortKey;
|
|
74
|
+
|
|
75
|
+
Product(String sProductID, String sProductName, String sSortKey) {
|
|
76
|
+
this.sProductID = sProductID;
|
|
77
|
+
this.sProductName = sProductName;
|
|
78
|
+
this.sSortKey = sSortKey;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 3. Swap Function
|
|
83
|
+
// Exchanges two product records in the array.
|
|
84
|
+
|
|
85
|
+
public static void Swap(Product Arr[], int iFirst, int iSecond) {
|
|
86
|
+
Product temp = Arr[iFirst];
|
|
87
|
+
|
|
88
|
+
Arr[iFirst] = Arr[iSecond];
|
|
89
|
+
|
|
90
|
+
Arr[iSecond] = temp;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 4. Partition Function
|
|
94
|
+
// Places the pivot element at its correct position.
|
|
95
|
+
|
|
96
|
+
public static int Partition(Product Arr[], int iLow, int iHigh) {
|
|
97
|
+
double dPivot = Double.parseDouble(Arr[iHigh].sSortKey);
|
|
98
|
+
|
|
99
|
+
int i = iLow - 1;
|
|
100
|
+
|
|
101
|
+
for (int j = iLow; j < iHigh; j++) {
|
|
102
|
+
double dValue = Double.parseDouble(Arr[j].sSortKey);
|
|
103
|
+
|
|
104
|
+
if (dValue >= dPivot) {
|
|
105
|
+
i++;
|
|
106
|
+
|
|
107
|
+
Swap(Arr, i, j);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
Swap(Arr, i + 1, iHigh);
|
|
112
|
+
|
|
113
|
+
return i + 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 5. Quick Sort Function
|
|
117
|
+
// Recursively sorts products around the pivot element.
|
|
118
|
+
|
|
119
|
+
public static void QuickSort(Product Arr[], int iLow, int iHigh) {
|
|
120
|
+
if (iLow < iHigh) {
|
|
121
|
+
int iPivot = Partition(Arr, iLow, iHigh);
|
|
122
|
+
|
|
123
|
+
QuickSort(Arr, iLow, iPivot - 1);
|
|
124
|
+
|
|
125
|
+
QuickSort(Arr, iPivot + 1, iHigh);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 7. Display Function
|
|
130
|
+
// Displays the first 10 products after sorting.
|
|
131
|
+
|
|
132
|
+
public static void DisplayProducts(Product Arr[]) {
|
|
133
|
+
System.out.printf("%-15s %-35s %-20s%n",
|
|
134
|
+
"PRODUCT_ID", "PRODUCT_NAME", "SALES_VOLUME");
|
|
135
|
+
|
|
136
|
+
System.out.println("--------------------------------------------------------------------------");
|
|
137
|
+
|
|
138
|
+
int iLimit = Math.min(Arr.length, 10);
|
|
139
|
+
|
|
140
|
+
for (int iCnt = 0; iCnt < iLimit; iCnt++) {
|
|
141
|
+
System.out.printf("%-15s %-35s %-20s%n",
|
|
142
|
+
Arr[iCnt].sProductID,
|
|
143
|
+
Arr[iCnt].sProductName,
|
|
144
|
+
Arr[iCnt].sSortKey);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -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 = "QS - 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
|
+
product_id,product_title,price,sales_volume
|
|
2
|
+
PRD-301,Wireless Earbuds,1999,14500
|
|
3
|
+
PRD-302,Smart Fitness Watch,2499,18200
|
|
4
|
+
PRD-303,Bluetooth Speaker,1499,9800
|
|
5
|
+
PRD-304,Fast Charging Powerbank,1299,21500
|
|
6
|
+
PRD-305,Gaming Mechanical Keyboard,3499,7600
|
|
7
|
+
PRD-306,Ergonomic Optical Mouse,799,16400
|
|
8
|
+
PRD-307,USB-C Multiport Hub,1199,11200
|
|
9
|
+
PRD-308,Noise Cancelling Headphones,4999,8900
|
|
10
|
+
PRD-309,Laptop Cooling Pad,899,13100
|
|
11
|
+
PRD-310,HD Webcam 1080p,1899,15300
|
|
12
|
+
PRD-311,Ring Light with Tripod,999,12400
|
|
13
|
+
PRD-312,Portable SSD 1TB,6499,6200
|
|
14
|
+
PRD-313,Smartphone Gimbal,5999,4800
|
|
15
|
+
PRD-314,Wireless Mouse Pad,499,23000
|
|
16
|
+
PRD-315,True Wireless Earphones,2999,10100
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
|
|
5
|
+
class Solution {
|
|
6
|
+
// 1. Main Function
|
|
7
|
+
// Entry point of the program.
|
|
8
|
+
|
|
9
|
+
public static void main(String A[]) {
|
|
10
|
+
int iSize = 0;
|
|
11
|
+
|
|
12
|
+
// 6. Main Logic
|
|
13
|
+
// Read movie dataset, sort records and display results.
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// 6.1 Count Number of Movies
|
|
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 Movie Array
|
|
29
|
+
|
|
30
|
+
Movie Arr[] = new Movie[iSize];
|
|
31
|
+
|
|
32
|
+
// 6.3 Read Movie 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 sSortKey = sData[3].trim().replace("\"", "");
|
|
45
|
+
|
|
46
|
+
Arr[iCnt] = new Movie(sID, sName, sSortKey);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bobj.close();
|
|
50
|
+
|
|
51
|
+
System.out.println("Loaded " + iSize + " movies.");
|
|
52
|
+
|
|
53
|
+
// 6.4 Call Quick Sort
|
|
54
|
+
|
|
55
|
+
QuickSort(Arr, 0, iSize - 1);
|
|
56
|
+
|
|
57
|
+
// 6.5 Display Top 10 Movies
|
|
58
|
+
|
|
59
|
+
System.out.println("\nMovies Sorted by Vote Count:");
|
|
60
|
+
|
|
61
|
+
DisplayMovies(Arr);
|
|
62
|
+
} catch (Exception e) {
|
|
63
|
+
System.out.println("Error: " + e.getMessage());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 2. Movie Entity
|
|
68
|
+
// Stores movie ID, title and sorting parameter.
|
|
69
|
+
|
|
70
|
+
static class Movie {
|
|
71
|
+
String sMovieID;
|
|
72
|
+
String sTitle;
|
|
73
|
+
String sSortKey;
|
|
74
|
+
|
|
75
|
+
Movie(String sMovieID, String sTitle, String sSortKey) {
|
|
76
|
+
this.sMovieID = sMovieID;
|
|
77
|
+
this.sTitle = sTitle;
|
|
78
|
+
this.sSortKey = sSortKey;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 3. Swap Function
|
|
83
|
+
// Exchanges two movie records in the array.
|
|
84
|
+
|
|
85
|
+
public static void Swap(Movie Arr[], int iFirst, int iSecond) {
|
|
86
|
+
Movie temp = Arr[iFirst];
|
|
87
|
+
|
|
88
|
+
Arr[iFirst] = Arr[iSecond];
|
|
89
|
+
|
|
90
|
+
Arr[iSecond] = temp;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 4. Partition Function
|
|
94
|
+
// Places the pivot element at its correct position.
|
|
95
|
+
|
|
96
|
+
public static int Partition(Movie Arr[], int iLow, int iHigh) {
|
|
97
|
+
String sPivot = Arr[iHigh].sSortKey;
|
|
98
|
+
|
|
99
|
+
int i = iLow - 1;
|
|
100
|
+
|
|
101
|
+
for (int j = iLow; j < iHigh; j++) {
|
|
102
|
+
double dValue1 = Double.parseDouble(Arr[j].sSortKey);
|
|
103
|
+
double dValue2 = Double.parseDouble(sPivot);
|
|
104
|
+
|
|
105
|
+
if (dValue1 >= dValue2) {
|
|
106
|
+
i++;
|
|
107
|
+
|
|
108
|
+
Swap(Arr, i, j);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Swap(Arr, i + 1, iHigh);
|
|
113
|
+
|
|
114
|
+
return i + 1;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 5. Quick Sort Function
|
|
118
|
+
// Recursively sorts movies around the pivot element.
|
|
119
|
+
|
|
120
|
+
public static void QuickSort(Movie Arr[], int iLow, int iHigh) {
|
|
121
|
+
if (iLow < iHigh) {
|
|
122
|
+
int iPivot = Partition(Arr, iLow, iHigh);
|
|
123
|
+
|
|
124
|
+
QuickSort(Arr, iLow, iPivot - 1);
|
|
125
|
+
|
|
126
|
+
QuickSort(Arr, iPivot + 1, iHigh);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 7. Display Function
|
|
131
|
+
// Displays the first 10 movies after sorting.
|
|
132
|
+
|
|
133
|
+
public static void DisplayMovies(Movie Arr[]) {
|
|
134
|
+
System.out.printf("%-15s %-35s %-20s%n",
|
|
135
|
+
"MOVIE_ID", "TITLE", "VOTE_COUNT");
|
|
136
|
+
|
|
137
|
+
System.out.println("--------------------------------------------------------------------------");
|
|
138
|
+
|
|
139
|
+
int iLimit = Math.min(Arr.length, 10);
|
|
140
|
+
|
|
141
|
+
for (int iCnt = 0; iCnt < iLimit; iCnt++) {
|
|
142
|
+
System.out.printf("%-15s %-35s %-20s%n",
|
|
143
|
+
Arr[iCnt].sMovieID,
|
|
144
|
+
Arr[iCnt].sTitle,
|
|
145
|
+
Arr[iCnt].sSortKey);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -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 = "QS - Movie"
|
|
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
|
+
movie_id,movie_title,imdb_rating,vote_count
|
|
2
|
+
MOV-101,3 Idiots,8.4,41000
|
|
3
|
+
MOV-102,Dangal,8.3,38500
|
|
4
|
+
MOV-103,Taare Zameen Par,8.3,32000
|
|
5
|
+
MOV-104,Lagaan,8.1,27000
|
|
6
|
+
MOV-105,Swades,8.2,29500
|
|
7
|
+
MOV-106,Chak De India,8.1,24000
|
|
8
|
+
MOV-107,Gangs of Wasseypur,8.2,31000
|
|
9
|
+
MOV-108,Sholay,8.1,26000
|
|
10
|
+
MOV-109,Drishyam,8.2,30500
|
|
11
|
+
MOV-110,Andhadhun,8.2,33000
|
|
12
|
+
MOV-111,Tumbbad,8.2,28500
|
|
13
|
+
MOV-112,Barfi,8.1,25500
|
|
14
|
+
MOV-113,Queen,8.1,23000
|
|
15
|
+
MOV-114,Zindagi Na Milegi Dobara,8.2,31500
|
|
16
|
+
MOV-115,Dil Chahta Hai,8.1,26500
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
import java.io.*;
|
|
4
|
+
|
|
5
|
+
class Solution {
|
|
6
|
+
// 1. Main Function
|
|
7
|
+
// Entry point of the program.
|
|
8
|
+
|
|
9
|
+
public static void main(String A[]) {
|
|
10
|
+
int iSize = 0;
|
|
11
|
+
|
|
12
|
+
// 6. Main Logic
|
|
13
|
+
// Read job dataset, sort records and display results.
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// 6.1 Count Number of Jobs
|
|
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 Job Array
|
|
29
|
+
|
|
30
|
+
Job Arr[] = new Job[iSize];
|
|
31
|
+
|
|
32
|
+
// 6.3 Read Job 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 sRole = sData[1].trim().replace("\"", "");
|
|
44
|
+
String sSortKey = sData[3].trim().replace("\"", "");
|
|
45
|
+
|
|
46
|
+
Arr[iCnt] = new Job(sID, sRole, sSortKey);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bobj.close();
|
|
50
|
+
|
|
51
|
+
System.out.println("Loaded " + iSize + " job postings.");
|
|
52
|
+
|
|
53
|
+
// 6.4 Call Quick Sort
|
|
54
|
+
|
|
55
|
+
QuickSort(Arr, 0, iSize - 1);
|
|
56
|
+
|
|
57
|
+
// 6.5 Display Top 10 Jobs
|
|
58
|
+
|
|
59
|
+
System.out.println("\nTop 10 Job Listings:");
|
|
60
|
+
|
|
61
|
+
DisplayJobs(Arr);
|
|
62
|
+
} catch (Exception e) {
|
|
63
|
+
System.out.println("Error: " + e.getMessage());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 2. Job Entity
|
|
68
|
+
// Stores job ID, role and sorting parameter.
|
|
69
|
+
|
|
70
|
+
static class Job {
|
|
71
|
+
String sJobID;
|
|
72
|
+
String sRole;
|
|
73
|
+
String sSortKey;
|
|
74
|
+
|
|
75
|
+
Job(String sJobID, String sRole, String sSortKey) {
|
|
76
|
+
this.sJobID = sJobID;
|
|
77
|
+
this.sRole = sRole;
|
|
78
|
+
this.sSortKey = sSortKey;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 3. Swap Function
|
|
83
|
+
// Exchanges two job records in the array.
|
|
84
|
+
|
|
85
|
+
public static void Swap(Job Arr[], int iFirst, int iSecond) {
|
|
86
|
+
Job temp = Arr[iFirst];
|
|
87
|
+
|
|
88
|
+
Arr[iFirst] = Arr[iSecond];
|
|
89
|
+
|
|
90
|
+
Arr[iSecond] = temp;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 4. Partition Function
|
|
94
|
+
// Places the pivot element at its correct position.
|
|
95
|
+
|
|
96
|
+
public static int Partition(Job Arr[], int iLow, int iHigh) {
|
|
97
|
+
double dPivot = Double.parseDouble(Arr[iHigh].sSortKey);
|
|
98
|
+
|
|
99
|
+
int i = iLow - 1;
|
|
100
|
+
|
|
101
|
+
for (int j = iLow; j < iHigh; j++) {
|
|
102
|
+
double dValue = Double.parseDouble(Arr[j].sSortKey);
|
|
103
|
+
|
|
104
|
+
if (dValue >= dPivot) {
|
|
105
|
+
i++;
|
|
106
|
+
|
|
107
|
+
Swap(Arr, i, j);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
Swap(Arr, i + 1, iHigh);
|
|
112
|
+
|
|
113
|
+
return i + 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 5. Quick Sort Function
|
|
117
|
+
// Recursively sorts jobs around the pivot element.
|
|
118
|
+
|
|
119
|
+
public static void QuickSort(Job Arr[], int iLow, int iHigh) {
|
|
120
|
+
if (iLow < iHigh) {
|
|
121
|
+
int iPivot = Partition(Arr, iLow, iHigh);
|
|
122
|
+
|
|
123
|
+
QuickSort(Arr, iLow, iPivot - 1);
|
|
124
|
+
|
|
125
|
+
QuickSort(Arr, iPivot + 1, iHigh);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 7. Display Function
|
|
130
|
+
// Displays the first 10 jobs after sorting.
|
|
131
|
+
|
|
132
|
+
public static void DisplayJobs(Job Arr[]) {
|
|
133
|
+
System.out.printf("%-15s %-35s %-20s%n",
|
|
134
|
+
"JOB_ID", "JOB_ROLE", "SORT_VALUE");
|
|
135
|
+
|
|
136
|
+
System.out.println("--------------------------------------------------------------------------");
|
|
137
|
+
|
|
138
|
+
int iLimit = Math.min(Arr.length, 10);
|
|
139
|
+
|
|
140
|
+
for (int iCnt = 0; iCnt < iLimit; iCnt++) {
|
|
141
|
+
System.out.printf("%-15s %-35s %-20s%n",
|
|
142
|
+
Arr[iCnt].sJobID,
|
|
143
|
+
Arr[iCnt].sRole,
|
|
144
|
+
Arr[iCnt].sSortKey);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -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 = "QS - Online"
|
|
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
|
+
job_id,job_role,salary_lpa,applicants
|
|
2
|
+
JOB-701,Software Engineer (Backend),18,3450
|
|
3
|
+
JOB-702,Frontend Developer (React),14,4120
|
|
4
|
+
JOB-703,Full Stack Engineer,22,2890
|
|
5
|
+
JOB-704,Data Scientist (ML/AI),25,2340
|
|
6
|
+
JOB-705,DevOps Engineer (Cloud),20,1850
|
|
7
|
+
JOB-706,Mobile App Developer (Flutter),16,3100
|
|
8
|
+
JOB-707,UI/UX Product Designer,12,3900
|
|
9
|
+
JOB-708,Cyber Security Analyst,24,1420
|
|
10
|
+
JOB-709,Cloud Solutions Architect,32,980
|
|
11
|
+
JOB-710,QA Automation Engineer,11,4600
|
|
12
|
+
JOB-711,Database Administrator,15,1750
|
|
13
|
+
JOB-712,AI Research Scientist,35,820
|
|
14
|
+
JOB-713,Systems Network Engineer,13,2600
|
|
15
|
+
JOB-714,Product Manager,28,1250
|
|
16
|
+
JOB-715,Blockchain Developer,26,1100
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
==================================================
|
|
2
|
+
2. QUICK SORT (LAST ELEMENT AS PIVOT)
|
|
3
|
+
==================================================
|
|
4
|
+
|
|
5
|
+
ALGORITHM:
|
|
6
|
+
1. Select the last element A[high] as pivot.
|
|
7
|
+
2. Initialize i = low - 1.
|
|
8
|
+
3. Traverse the array using j = low to high - 1.
|
|
9
|
+
4. If A[j] <= pivot, increment i and swap A[i] with A[j].
|
|
10
|
+
5. Swap A[i+1] with the pivot.
|
|
11
|
+
6. Return the pivot index.
|
|
12
|
+
7. Recursively sort the left and right partitions.
|
|
13
|
+
|
|
14
|
+
RECURRENCE RELATION:
|
|
15
|
+
Best Case:
|
|
16
|
+
T(n) = 2T(n/2) + O(n)
|
|
17
|
+
|
|
18
|
+
Worst Case:
|
|
19
|
+
T(n) = T(n-1) + O(n)
|
|
20
|
+
|
|
21
|
+
RECURSIVE ANALYSIS:
|
|
22
|
+
Best Case:
|
|
23
|
+
T(n) = O(n log n)
|
|
24
|
+
|
|
25
|
+
Worst Case:
|
|
26
|
+
T(n) = n + (n-1) + (n-2) + ... + 1
|
|
27
|
+
T(n) = O(n^2)
|
|
28
|
+
|
|
29
|
+
TIME COMPLEXITY:
|
|
30
|
+
Best Case : O(n log n)
|
|
31
|
+
Average Case : O(n log n)
|
|
32
|
+
Worst Case : O(n^2)
|
|
33
|
+
Space : O(log n) average, O(n) worst
|