Skip to content

Commit

Permalink
Merge pull request #66 from raj-rathod/rajesh
Browse files Browse the repository at this point in the history
feat:<Divide and conquer> content add and structure setup
  • Loading branch information
raj-rathod authored Aug 19, 2022
2 parents 4310416 + 3a9a736 commit cf2239c
Show file tree
Hide file tree
Showing 20 changed files with 240 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>closest-pair-of-points works!</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ClosestPairOfPointsComponent } from './closest-pair-of-points.component';

describe('ClosestPairOfPointsComponent', () => {
let component: ClosestPairOfPointsComponent;
let fixture: ComponentFixture<ClosestPairOfPointsComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ClosestPairOfPointsComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ClosestPairOfPointsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-closest-pair-of-points',
templateUrl: './closest-pair-of-points.component.html',
styleUrls: ['./closest-pair-of-points.component.css']
})
export class ClosestPairOfPointsComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
<p class="text-center mt-5">Coming soon</p>
<h1 class="text-center">Divide And Conquer algorithms</h1>
<div class="mt-md-4 mt-3" [innerHtml]="divideAndConquerMetaData.defination"></div>
<div class="mt-md-4 mt-3" [innerHtml]="divideAndConquerMetaData.terminologies"></div>
<div class="mt-md-4 mt-3" [innerHtml]="divideAndConquerMetaData.algorithms"></div>
<div class="mt-md-4 mt-3" [innerHtml]="divideAndConquerMetaData.timeComplexity"></div>
<div class="mt-md-4 mt-3" [innerHtml]="divideAndConquerMetaData.comparison"></div>
<div class="mt-md-4 mt-3" [innerHtml]="divideAndConquerMetaData.advantage"></div>
<div class="mt-md-4 mt-3" [innerHtml]="divideAndConquerMetaData.disadvantage"></div>
<div class="mt-md-4 mt-3 d-flex align-items-center horizontal-scroll">
<ng-container *ngFor="let data of divideAndConquerLinks; let i = index">
<div class="box p-lg-2 p-1 px-lg-3 px-2 tab me-lg-4 me-3" [routerLink]="data.route">
<p class="m-0">{{data.name}}</p>
</div>
</ng-container>
</div>
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Component, OnInit } from '@angular/core';
import { divideAndConquerMetaData } from 'src/app/core/algorithms/divide-and-conquer-meta-data';
import { divideAndConquerLinks } from 'src/app/core/meta-data/router-meta-data';

@Component({
selector: 'app-divide-and-conquer-algorithm',
templateUrl: './divide-and-conquer-algorithm.component.html',
styleUrls: ['./divide-and-conquer-algorithm.component.css']
})
export class DivideAndConquerAlgorithmComponent implements OnInit {

divideAndConquerMetaData = divideAndConquerMetaData;
divideAndConquerLinks = divideAndConquerLinks
constructor() { }

ngOnInit(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ClosestPairOfPointsComponent } from './closest-pair-of-points/closest-pair-of-points.component';
import { DivideAndConquerAlgorithmComponent } from './divide-and-conquer-algorithm/divide-and-conquer-algorithm.component';
import { KaratsubaComponent } from './karatsuba/karatsuba.component';
import { StrassenComponent } from './strassen/strassen.component';

const routes: Routes = [
{
path: '', component: DivideAndConquerAlgorithmComponent
},
{
path: 'closet-pair-of-points', component: ClosestPairOfPointsComponent,

},
{
path: 'strassen', component: StrassenComponent
},
{
path: 'karatsuba', component: KaratsubaComponent
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DivideAndConqureRoutingModule } from './divide-and-conquer-routing.module';
import { DivideAndConquerAlgorithmComponent } from './divide-and-conquer-algorithm/divide-and-conquer-algorithm.component';
import { ClosestPairOfPointsComponent } from './closest-pair-of-points/closest-pair-of-points.component';
import { StrassenComponent } from './strassen/strassen.component';
import { KaratsubaComponent } from './karatsuba/karatsuba.component';


@NgModule({
declarations: [

DivideAndConquerAlgorithmComponent
DivideAndConquerAlgorithmComponent,
ClosestPairOfPointsComponent,
StrassenComponent,
KaratsubaComponent
],
imports: [CommonModule, DivideAndConqureRoutingModule]
})
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>karatsuba works!</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { KaratsubaComponent } from './karatsuba.component';

describe('KaratsubaComponent', () => {
let component: KaratsubaComponent;
let fixture: ComponentFixture<KaratsubaComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ KaratsubaComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(KaratsubaComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-karatsuba',
templateUrl: './karatsuba.component.html',
styleUrls: ['./karatsuba.component.css']
})
export class KaratsubaComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>strassen works!</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { StrassenComponent } from './strassen.component';

describe('StrassenComponent', () => {
let component: StrassenComponent;
let fixture: ComponentFixture<StrassenComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ StrassenComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(StrassenComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-strassen',
templateUrl: './strassen.component.html',
styleUrls: ['./strassen.component.css']
})
export class StrassenComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h1 class="text-center">Searching Algorithms</h1>
<div class="mt-md-4 mt-3" [innerHtml]="searchingMetaData.terminologies"></div>
<div class="mt-md-4 mt-3 d-flex align-items-center horizontal-scroll">
<ng-container *ngFor="let data of searchingLinks; let i = index">
<div *ngIf="i !=0" class="box p-lg-2 p-1 px-lg-3 px-2 tab me-lg-4 me-3" [routerLink]="data.route">
<div class="box p-lg-2 p-1 px-lg-3 px-2 tab me-lg-4 me-3" [routerLink]="data.route">
<p class="m-0">{{data.name}}</p>
</div>
</ng-container>
Expand Down
41 changes: 41 additions & 0 deletions src/app/core/algorithms/divide-and-conquer-meta-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Helper } from "src/app/helper/helper"

const divideAndConquerData = {
defination: "A divide and conquer algorithm is a strategy of solving a large problem by breaking the problem into smaller sub-problems, solving the sub-problems, and combining them to get the desired output.",
terminologies:[
"<b>Divide</b>: This involves dividing the problem into smaller sub-problems",
"<b>Conquer</b>: Solve sub-problems by calling recursively until solved",
"<b>Combine</b>: Combine the sub-problems to get the final solution of the whole problem",
],
algorithms: [
"<b>Quicksort</b>: is a sorting algorithm. The algorithm picks a pivot element and rearranges the array elements so that all elements smaller than the picked pivot element move to the left side of the pivot, and all greater elements move to the right side. Finally, the algorithm recursively sorts the subarrays on the left and right of the pivot element",
"<b>Merge Sort</b>: is also a sorting algorithm. The algorithm divides the array into two halves, recursively sorts them, and finally merges the two sorted halves",
"<b>Closest Pair of Points</b>: The problem is to find the closest pair of points in a set of points in the x-y plane. The problem can be solved in O(n^2) time by calculating the distances of every pair of points and comparing the distances to find the minimum. The Divide and Conquer algorithm solves the problem in O(N log N) time",
"<b>Strassen’s Algorithm</b>: is an efficient algorithm to multiply two matrices. A simple method to multiply two matrices needs 3 nested loops and is O(n^3). Strassen’s algorithm multiplies two matrices in O(n^2.8974) time",
"<b>Karatsuba algorithm</b>: is a fast multiplication algorithm that uses a divide and conquer approach to multiply two numbers",
],
comparison:"Both paradigms (D & C and DP) divide the given problem into subproblems and solve subproblems. How do choose one of them for a given problem? Divide and Conquer should be used when the same subproblems are not evaluated many times. Otherwise Dynamic Programming or Memoization should be used. For example, Quicksort is a Divide and Conquer algorithm, we never evaluate the same subproblems again. On the other hand, for calculating the nth Fibonacci number, Dynamic Programming should be preferred",
timeComplexity:"T(n) = aT(n/b) + f(n),<br><br> where, <br> &nbsp &nbsp n = size of input<br>&nbsp &nbsp a = number of subproblems in the recursion<br>&nbsp &nbspn/b = size of each subproblem. All subproblems are assumed to have the same size.<br>&nbsp &nbspf(n) = cost of the work done outside the recursive call, which includes the cost of dividing the problem and cost of merging the solutions<br>",
advantage:[
"The difficult problem can be solved easily",
"It divides the entire problem into subproblems thus it can be solved parallelly ensuring multiprocessing",
"Efficiently uses cache memory without occupying much space",
"Reduces time complexity of the problem"
],
disadvantage:[
"It involves recursion which is sometimes slow",
"Efficiency depends on the implementation of logic",
"It may crash the system if the recursion is performed rigorously"
]
}

export const divideAndConquerMetaData = {
defination: Helper.setHeader(divideAndConquerData.defination),
terminologies: Helper.setListwithTitleHtml("Terminologies", divideAndConquerData.terminologies),
algorithms: Helper.setListwithTitleHtml("Some Standard Algorithms", divideAndConquerData.algorithms),
timeComplexity: Helper.setTitleDescription("Time Complexity of Divide and Conquer Algorithm", divideAndConquerData.timeComplexity),
comparison: Helper.setTitleDescription("Divide and Conquer (D & C) vs Dynamic Programming (DP)", divideAndConquerData.comparison),
advantage: Helper.setListwithTitleHtml("Advantages", divideAndConquerData.advantage),
disadvantage: Helper.setListwithTitleHtml("Disadvantages", divideAndConquerData.disadvantage)

}
35 changes: 31 additions & 4 deletions src/app/core/meta-data/router-meta-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,24 @@ export const sorting: RouterLinkData[] = [
{
name: "Merge Sort",
route: "/algorithm/sorting/merge-sort"
}, {
},
{
name: "Quick Sort",
route: "/algorithm/sorting/quick-sort"
}, {
},
{
name: "Counting Sort",
route: "/algorithm/sorting/counting-sort"
}, {
},
{
name: "Radix Sort",
route: "/algorithm/sorting/radix-sort"
},
{
name: "Bucket Sort",
route: "/algorithm/sorting/bucket-sort"
}, {
},
{
name: "Heap Sort",
route: "/non-primitive/non-linear/heap-tree"
},
Expand Down Expand Up @@ -152,3 +156,26 @@ export const searchingLinks: RouterLinkData[] = [
route: "/algorithm/searching/fibonacci-search"
},
];

export const divideAndConquerLinks: RouterLinkData[] = [
{
name: "Merge Sort",
route: "/algorithm/sorting/merge-sort"
},
{
name: "Quick Sort",
route: "/algorithm/sorting/quick-sort"
},
{
name: "Strassen's Algorithm",
route: "/algorithm/divide-and-conquer/strassen"
},
{
name: "Closest Pair of Points",
route: "/algorithm/divide-and-conquer/closest-pair-of-points"
},
{
name: "Karatsuba Algorithm",
route: "/algorithm/divide-and-conquer/karatsuba"
}
];
8 changes: 5 additions & 3 deletions src/app/layout/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, ElementRef, OnInit } from '@angular/core';
import { algorithms, dataStructure, searchingLinks, sorting } from 'src/app/core/meta-data/router-meta-data';
import { algorithms, dataStructure, divideAndConquerLinks, searchingLinks, sorting } from 'src/app/core/meta-data/router-meta-data';

@Component({
selector: 'app-navbar',
Expand All @@ -9,11 +9,13 @@ import { algorithms, dataStructure, searchingLinks, sorting } from 'src/app/core
export class NavbarComponent implements OnInit {
dataStructure = dataStructure;
algorithms = algorithms
searchData = dataStructure.concat(algorithms, sorting, searchingLinks);
searchData = dataStructure.concat(algorithms, sorting, searchingLinks, divideAndConquerLinks);
searchKey = '';
constructor(
private elRef: ElementRef
) { }
) {
this.searchData = [...new Set(this.searchData.map(s => JSON.stringify(s)))].map(s => JSON.parse(s));
}

ngOnInit(): void {
}
Expand Down

0 comments on commit cf2239c

Please sign in to comment.