Android project for rent of sooters
Android on eclipse
USANDO LA API DE GOOGLE CON EL SPREADSHEET
/**
* @OnlyCurrentDoc Limits the script to only accessing the current sheet.
*/
/**
* A special function that runs when the spreadsheet is open, used to add a
* custom menu to the spreadsheet.
*/
function onOpen() {
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Prepare sheet...', functionName: 'prepareSheet_'},
{name: 'Generate step-by-step...', functionName: 'generateStepByStep_'}
];
spreadsheet.addMenu('Directions', menuItems);
}
/**
* A custom function that converts meters to miles.
*
* @param {Number} meters The distance in meters.
* @return {Number} The distance in miles.
*/
function metersToMiles(meters) {
if (typeof meters != 'number') {
return null;
}
return meters / 1000 * 0.621371;
}
/**
* A custom function that gets the driving distance between two addresses.
*
* @param {String} origin The starting address.
* @param {String} destination The ending address.
* @return {Number} The distance in meters.
*/
function drivingDistance(origin, destination) {
var directions = getDirections_(origin, destination);
return directions.routes[0].legs[0].distance.value;
}
/**
* A function that adds headers and some initial data to the spreadsheet.
*/
function prepareSheet_() {
var sheet = SpreadsheetApp.getActiveSheet().setName('Settings');
var headers = [
'Start Address',
'End Address',
'Driving Distance (meters)',
'Driving Distance (miles)'];
var initialData = [
'350 5th Ave, New York, NY 10118',
'405 Lexington Ave, New York, NY 10174'];
sheet.getRange('A1:D1').setValues([headers]).setFontWeight('bold');
sheet.getRange('A2:B2').setValues([initialData]);
sheet.setFrozenRows(1);
sheet.autoResizeColumns(1, 4);
}
/**
* Creates a new sheet containing step-by-step directions between the two
* addresses on the "Settings" sheet that the user selected.
*/
function generateStepByStep_() {
var spreadsheet = SpreadsheetApp.getActive();
var settingsSheet = spreadsheet.getSheetByName('Settings');
settingsSheet.activate();
// Prompt the user for a row number.
var selectedRow = Browser.inputBox('Generate step-by-step',
'Please enter the row number of the addresses to use' +
' (for example, "2"):',
Browser.Buttons.OK_CANCEL);
if (selectedRow == 'cancel') {
return;
}
var rowNumber = Number(selectedRow);
if (isNaN(rowNumber) || rowNumber < 2 ||
rowNumber > settingsSheet.getLastRow()) {
Browser.msgBox('Error',
Utilities.formatString('Row "%s" is not valid.', selectedRow),
Browser.Buttons.OK);
return;
}
// Retrieve the addresses in that row.
var row = settingsSheet.getRange(rowNumber, 1, 1, 2);
var rowValues = row.getValues();
var origin = rowValues[0][0];
var destination = rowValues[0][1];
if (!origin || !destination) {
Browser.msgBox('Error', 'Row does not contain two addresses.',
Browser.Buttons.OK);
return;
}
// Get the raw directions information.
var directions = getDirections_(origin, destination);
// Create a new sheet and append the steps in the directions.
var sheetName = 'Driving Directions for Row ' + rowNumber;
var directionsSheet = spreadsheet.getSheetByName(sheetName);
if (directionsSheet) {
directionsSheet.clear();
directionsSheet.activate();
} else {
directionsSheet =
spreadsheet.insertSheet(sheetName, spreadsheet.getNumSheets());
}
var sheetTitle = Utilities.formatString('Driving Directions from %s to %s',
origin, destination);
var headers = [
[sheetTitle, '', ''],
['Step', 'Distance (Meters)', 'Distance (Miles)']
];
var newRows = [];
for (var i = 0; i < directions.routes[0].legs[0].steps.length; i++) {
var step = directions.routes[0].legs[0].steps[i];
// Remove HTML tags from the instructions.
var instructions = step.html_instructions.replace(/<br>|<div.*?>/g, '\n')
.replace(/<.*?>/g, '');
newRows.push([
instructions,
step.distance.value
]);
}
directionsSheet.getRange(1, 1, headers.length, 3).setValues(headers);
directionsSheet.getRange(headers.length + 1, 1, newRows.length, 2)
.setValues(newRows);
directionsSheet.getRange(headers.length + 1, 3, newRows.length, 1)
.setFormulaR1C1('=METERSTOMILES(R[0]C[-1])');
// Format the new sheet.
directionsSheet.getRange('A1:C1').merge().setBackground('#ddddee');
directionsSheet.getRange('A1:2').setFontWeight('bold');
directionsSheet.setColumnWidth(1, 500);
directionsSheet.getRange('B2:C').setVerticalAlignment('top');
directionsSheet.getRange('C2:C').setNumberFormat('0.00');
var stepsRange = directionsSheet.getDataRange()
.offset(2, 0, directionsSheet.getLastRow() - 2);
setAlternatingRowBackgroundColors_(stepsRange, '#ffffff', '#eeeeee');
directionsSheet.setFrozenRows(2);
SpreadsheetApp.flush();
}
/**
* Sets the background colors for alternating rows within the range.
* @param {Range} range The range to change the background colors of.
* @param {string} oddColor The color to apply to odd rows (relative to the
* start of the range).
* @param {string} evenColor The color to apply to even rows (relative to the
* start of the range).
*/
function setAlternatingRowBackgroundColors_(range, oddColor, evenColor) {
var backgrounds = [];
for (var row = 1; row <= range.getNumRows(); row++) {
var rowBackgrounds = [];
for (var column = 1; column <= range.getNumColumns(); column++) {
if (row % 2 == 0) {
rowBackgrounds.push(evenColor);
} else {
rowBackgrounds.push(oddColor);
}
}
backgrounds.push(rowBackgrounds);
}
range.setBackgrounds(backgrounds);
}
/**
* A shared helper function used to obtain the full set of directions
* information between two addresses. Uses the Apps Script Maps Service.
*
* @param {String} origin The starting address.
* @param {String} destination The ending address.
* @return {Object} The directions response object.
*/
function getDirections_(origin, destination) {
var directionFinder = Maps.newDirectionFinder();
directionFinder.setOrigin(origin);
directionFinder.setDestination(destination);
var directions = directionFinder.getDirections();
if (directions.status !== 'OK') {
throw directions.error_message;
}
return directions;
}
Compile code C in Microsoft visual studio can be a very shity thing, first you need t specify the compiler for C and no C++
Then you compile it and create an exe file on the Debug folder, and then you need t open console in order to execute the code, This is very nasty! very Microsoft
MOCOSOFT
Microsoft Windows [Versión 10.0.17134.885]
(c) 2018 Microsoft Corporation. Todos los derechos reservados.
C:\Users\admin>gcc
"gcc" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
C:\Users\admin>g++
"g++" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
C:\Users\admin>cd C:\Users\admin\Documents\Visual Studio 2015\Projects
C:\Users\admin\Documents\Visual Studio 2015\Projects>ls
"ls" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
C:\Users\admin\Documents\Visual Studio 2015\Projects>dir
El volumen de la unidad C es Windows
El número de serie del volumen es: CA17-A5F2
Directorio de C:\Users\admin\Documents\Visual Studio 2015\Projects
06/14/2018 12:04 AM <DIR> .
06/14/2018 12:04 AM <DIR> ..
06/30/2018 11:34 PM <DIR> ConsoleApplication1
06/30/2018 11:34 PM <DIR> ConsoleApplication2
08/13/2019 12:00 AM <DIR> ConsoleApplication3
06/30/2018 11:34 PM <DIR> ConsoleApplication4
0 archivos 0 bytes
6 dirs 28,501,790,720 bytes libres
C:\Users\admin\Documents\Visual Studio 2015\Projects>cd ConsoleApplication3
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3>dir
El volumen de la unidad C es Windows
El número de serie del volumen es: CA17-A5F2
Directorio de C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3
08/13/2019 12:00 AM <DIR> .
08/13/2019 12:00 AM <DIR> ..
08/13/2019 12:05 AM <DIR> ConsoleApplication3
06/13/2018 06:51 PM 1,339 ConsoleApplication3.sln
06/30/2018 11:36 PM 2,367,488 ConsoleApplication3.VC.db
06/30/2018 11:32 PM <DIR> Debug
2 archivos 2,368,827 bytes
4 dirs 28,504,006,656 bytes libres
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3>cd ConsoleApplication3
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3>dir
El volumen de la unidad C es Windows
El número de serie del volumen es: CA17-A5F2
Directorio de C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3
08/13/2019 12:05 AM <DIR> .
08/13/2019 12:05 AM <DIR> ..
08/13/2019 12:05 AM 117 ConsoleApplication3.cpp
06/13/2018 06:55 PM 7,661 ConsoleApplication3.vcxproj
06/13/2018 06:51 PM 1,346 ConsoleApplication3.vcxproj.filters
06/30/2018 11:32 PM 300 ConsoleApplication3.vcxproj.user
06/30/2018 11:32 PM <DIR> Debug
06/13/2018 06:51 PM 1,799 ReadMe.txt
06/13/2018 06:51 PM 306 stdafx.cpp
06/13/2018 06:51 PM 320 stdafx.h
06/13/2018 06:51 PM 314 targetver.h
8 archivos 12,163 bytes
3 dirs 28,504,002,560 bytes libres
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3>cd D
El sistema no puede encontrar la ruta especificada.
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3>cd Debug
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Debug>dir
El volumen de la unidad C es Windows
El número de serie del volumen es: CA17-A5F2
Directorio de C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Debug
08/13/2019 12:09 AM <DIR> .
08/13/2019 12:09 AM <DIR> ..
08/13/2019 12:09 AM <DIR> ConsoleA.8EC92C8E.tlog
08/13/2019 12:09 AM 1,609 ConsoleApplication3.Build.CppClean.log
08/13/2019 12:09 AM 389 ConsoleApplication3.log
08/13/2019 12:09 AM 59 consoleapplication3.nativecodeanalysis.xml
08/13/2019 12:09 AM 6,185 ConsoleApplication3.obj
08/13/2019 12:09 AM 128 NativeCodeAnalysis.read.1.tlog
08/13/2019 12:09 AM 59 stdafx.nativecodeanalysis.xml
08/13/2019 12:09 AM 3,387 stdafx.obj
08/13/2019 12:09 AM 52 vc.nativecodeanalysis.all.xml
08/13/2019 12:09 AM 68,608 vc140.idb
08/13/2019 12:09 AM 77,824 vc140.pdb
10 archivos 158,300 bytes
3 dirs 28,503,171,072 bytes libres
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Debug>dir
El volumen de la unidad C es Windows
El número de serie del volumen es: CA17-A5F2
Directorio de C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Debug
08/13/2019 12:09 AM <DIR> .
08/13/2019 12:09 AM <DIR> ..
08/13/2019 12:09 AM <DIR> ConsoleA.8EC92C8E.tlog
08/13/2019 12:09 AM 1,609 ConsoleApplication3.Build.CppClean.log
08/13/2019 12:09 AM 389 ConsoleApplication3.log
08/13/2019 12:09 AM 59 consoleapplication3.nativecodeanalysis.xml
08/13/2019 12:09 AM 6,185 ConsoleApplication3.obj
08/13/2019 12:09 AM 128 NativeCodeAnalysis.read.1.tlog
08/13/2019 12:09 AM 59 stdafx.nativecodeanalysis.xml
08/13/2019 12:09 AM 3,387 stdafx.obj
08/13/2019 12:09 AM 52 vc.nativecodeanalysis.all.xml
08/13/2019 12:09 AM 68,608 vc140.idb
08/13/2019 12:09 AM 77,824 vc140.pdb
10 archivos 158,300 bytes
3 dirs 28,503,171,072 bytes libres
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Debug>ConsoleApplication3.exe
"ConsoleApplication3.exe" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Debug>cd C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\Debug\
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\Debug>dir
El volumen de la unidad C es Windows
El número de serie del volumen es: CA17-A5F2
Directorio de C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\Debug
08/13/2019 12:09 AM <DIR> .
08/13/2019 12:09 AM <DIR> ..
08/13/2019 12:09 AM 37,376 ConsoleApplication3.exe
08/13/2019 12:09 AM 0 ConsoleApplication3.exe.lastcodeanalysissucceeded
08/13/2019 12:09 AM 287,584 ConsoleApplication3.ilk
08/13/2019 12:09 AM 552,960 ConsoleApplication3.pdb
4 archivos 877,920 bytes
2 dirs 28,502,843,392 bytes libres
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\Debug>ConsoleApplication3.exe
Hello, World!
C:\Users\admin\Documents\Visual Studio 2015\Projects\ConsoleApplication3\Debug>
2019-08-12 18:12:21 - Workbench will use cmd shell commands to start/stop this instance
2019-08-12 18:12:21 - Checking server status...
2019-08-12 18:12:21 - MySQL server is currently running
2019-08-12 18:12:21 - Checking server status...
2019-08-12 18:12:21 - MySQL server is currently running
2019-08-12 18:12:30 - Server stop done.
FROM DESKTOP-DLK8P3R.err:
2019-08-12T23:12:27 0 Note C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: Normal shutdown
2019-08-12T23:12:27 0 Note Giving 4 client threads a chance to die gracefully
2019-08-12T23:12:27 0 Note Shutting down slave threads
2019-08-12T23:12:29 0 Note Forcefully disconnecting 3 remaining clients
2019-08-12T23:12:29 0 Warning C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: Forcing close of thread 10 user: 'root'
2019-08-12T23:12:29 0 Warning C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: Forcing close of thread 11 user: 'root'
2019-08-12T23:12:29 0 Warning C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: Forcing close of thread 13 user: 'root'
2019-08-12T23:12:29 0 Note Event Scheduler: Purging the queue. 0 events
2019-08-12T23:12:29 0 Note Binlog end
2019-08-12T23:12:29 0 Note Shutting down plugin 'ngram'
2019-08-12T23:12:29 0 Note Shutting down plugin 'partition'
2019-08-12T23:12:29 0 Note Shutting down plugin 'BLACKHOLE'
2019-08-12T23:12:29 0 Note Shutting down plugin 'ARCHIVE'
2019-08-12T23:12:29 0 Note Shutting down plugin 'PERFORMANCE_SCHEMA'
2019-08-12T23:12:29 0 Note Shutting down plugin 'MRG_MYISAM'
2019-08-12T23:12:29 0 Note Shutting down plugin 'MyISAM'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_VIRTUAL'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_DATAFILES'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_TABLESPACES'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_FOREIGN'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_FIELDS'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_COLUMNS'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_INDEXES'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_TABLESTATS'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_SYS_TABLES'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_FT_CONFIG'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_FT_BEING_DELETED'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_FT_DELETED'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_METRICS'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_BUFFER_PAGE'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_CMP_PER_INDEX'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_CMPMEM_RESET'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_CMPMEM'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_CMP_RESET'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_CMP'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_LOCK_WAITS'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_LOCKS'
2019-08-12T23:12:29 0 Note Shutting down plugin 'INNODB_TRX'
2019-08-12T23:12:29 0 Note Shutting down plugin 'InnoDB'
2019-08-12T23:12:29 0 Note InnoDB: FTS optimize thread exiting.
2019-08-12T23:12:29 0 Note InnoDB: Starting shutdown...
2019-08-12T23:12:29 0 Note InnoDB: Dumping buffer pool(s) to C:\ProgramData\MySQL\MySQL Server 5.7\Data\ib_buffer_pool
2019-08-12T23:12:29 0 Note InnoDB: Buffer pool(s) dump completed at 190812 18:12:29
2019-08-12T23:12:30 0 Note InnoDB: Shutdown completed; log sequence number 10732318
2019-08-12T23:12:30 0 Note InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-08-12T23:12:30 0 Note Shutting down plugin 'MEMORY'
2019-08-12T23:12:30 0 Note Shutting down plugin 'CSV'
2019-08-12T23:12:30 0 Note Shutting down plugin 'sha256_password'
2019-08-12T23:12:30 0 Note Shutting down plugin 'mysql_native_password'
2019-08-12T23:12:30 0 Note Shutting down plugin 'binlog'
2019-08-12T23:12:30 0 Note C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: Shutdown complete
2019-08-12 18:12:31 - Checking server status...
2019-08-12 18:12:31 - MySQL server is currently running
2019-08-12 18:12:31 - Checking server status...
2019-08-12 18:12:31 - Trying to connect to MySQL...
2019-08-12 18:12:31 - Can't connect to MySQL server on '127.0.0.1' (10061) (2003)
2019-08-12 18:12:31 - Assuming server is not running
2019-08-13 00:20:22 - Starting server...
FROM DESKTOP-DLK8P3R.err:
2019-08-13T05:20:25 0 Warning TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-13T05:20:25 0 Warning 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2019-08-13T05:20:25 0 Note C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe (mysqld 5.7.16-log) starting as process 16956 ...
2019-08-13T05:20:25 0 Note InnoDB: Mutexes and rw_locks use Windows interlocked functions
2019-08-13T05:20:25 0 Note InnoDB: Uses event mutexes
2019-08-13T05:20:25 0 Note InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier
2019-08-13T05:20:25 0 Note InnoDB: Compressed tables use zlib 1.2.3
2019-08-13T05:20:25 0 Note InnoDB: Adjusting innodb_buffer_pool_instances from 8 to 1 since innodb_buffer_pool_size is less than 1024 MiB
2019-08-13T05:20:25 0 Note InnoDB: Number of pools: 1
2019-08-13T05:20:25 0 Note InnoDB: Not using CPU crc32 instructions
2019-08-13T05:20:25 0 Note InnoDB: Initializing buffer pool, total size = 8M, instances = 1, chunk size = 8M
2019-08-13T05:20:25 0 Note InnoDB: Completed initialization of buffer pool
2019-08-13T05:20:25 0 Note InnoDB: Highest supported file format is Barracuda.
2019-08-13T05:20:27 0 Note InnoDB: Creating shared tablespace for temporary tables
2019-08-13T05:20:27 0 Note InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-08-13T05:20:27 0 Note InnoDB: File '.\ibtmp1' size is now 12 MB.
2019-08-13T05:20:27 0 Note InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-08-13T05:20:27 0 Note InnoDB: 32 non-redo rollback segment(s) are active.
2019-08-13T05:20:27 0 Note InnoDB: Waiting for purge to start
2019-08-13T05:20:27 0 Note InnoDB: 5.7.16 started; log sequence number 10732318
2019-08-13T05:20:27 0 Note InnoDB: Loading buffer pool(s) from C:\ProgramData\MySQL\MySQL Server 5.7\Data\ib_buffer_pool
2019-08-13T05:20:27 0 Note Plugin 'FEDERATED' is disabled.
2019-08-13T05:20:27 0 Warning Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2019-08-13T05:20:27 0 Note Server hostname (bind-address): '*'; port: 3306
2019-08-13T05:20:27 0 Note IPv6 is available.
2019-08-13T05:20:27 0 Note - '::' resolves to '::';
2019-08-13T05:20:27 0 Note Server socket created on IP: '::'.
2019-08-13T05:20:27 0 Note InnoDB: Buffer pool(s) load completed at 190813 0:20:27
2019-08-13T05:20:28 0 Note Event Scheduler: Loaded 0 events
2019-08-13T05:20:28 0 Note C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: ready for connections.
Version: '5.7.16-log' socket: '' port: 3306 MySQL Community Server (GPL)
2019-08-13T05:20:28 2 Note Access denied for user 'root'@'localhost' (using password: NO)
2019-08-13 00:20:49 - Server start done.
2019-08-13 00:20:49 - Checking server status...
2019-08-13 00:20:49 - Trying to connect to MySQL...
2019-08-13 00:20:49 - Connection succeeded
2019-08-13 00:20:49 - Assuming server is running
2019-08-13 00:20:49 - Checking server status...
2019-08-13 00:20:49 - Trying to connect to MySQL...
2019-08-13 00:20:49 - Connection succeeded
2019-08-13 00:20:49 - Assuming server is running
7 algorithms and data structures every programmer must know
In programmers life algorithms and data structures is most important subject if they want to go out in the programming world and make some bucks. Today, We will see what they do and where they are used with simplest examples. This list is prepared keeping in mind their use in competitive programming and current development practices.
1. Sort Algorithms
Sorting is the most heavily studied concept in Computer Science. Idea is to arrange the items of a list in a specific order. Though every major programming language has built-in sorting libraries, it comes in handy if you know how they work. Depending upon requirement you may want to use any of these.
- Merge Sort
- Quick Sort
- Bucket Sort
- Heap Sort
- Counting Sort
More importantly one should know
when and where to use them. Some examples where you can find direct application of sorting techniques include:
- Sorting by price, popularity etc in e-commerce websites
2. Search Algorithms
Binary Search (in linear data structures)
Binary search is used to perform a very efficient search on sorted dataset. The time complexity is O(log2N). Idea is to repeatedly divide in half the portion of the list that could contain the item, until we narrow it down to one possible item. Some applications are:
- When you search for a name of song in a sorted list of songs, it performs binary search and string-matching to quickly return the results.
- Used to debug in git through git bisect
Depth/Breadth First Search (in Graph data structures)
DFS and BFS are tree/graph traversing and searching data structures. We wouldn’t go deep into
how DFS/BFS work but will see how they are different through following animation.
Applications:
- Used by search engines for web-crawling
- Used in artificial intelligence to build bots, for instance a chess bot
- Finding shortest path between two cities in a map and many other such applications
3. Hashing
Hash lookup is currently the most widely used technique to find appropriate data by key or ID. We access data by its index. Previously we relied on Sorting+Binary Search to look for index whereas now we use hashing.
The data structure is referred as Hash-Map or Hash-Table or Dictionary that maps keys to values, efficiently. We can perform value lookups using keys. Idea is to use an appropriate hash function which does the key -> value mapping. Choosing a good hash function depends upon the scenario.
Applications:
- In routers, to store IP address -> Path pair for routing mechanisms
- To perform the check if a value already exists in a list. Linear search would be expensive. We can also use Set data structure for this operation.
4. Dynamic Programming
Dynamic programming (DP) is a method for solving a complex problem by breaking it down into simpler subproblems. We solve the subproblems, remember their results and using them we make our way to solve the complex problem, quickly.
*writes down “1+1+1+1+1+1+1+1 =” on a sheet of paper* What’s that equal to?
*counting* Eight!
*writes down another “1+” on the left* What about that?
*quickly* Nine!
How’d you know it was nine so fast?
You just added one more
So you didn’t need to recount because you remembered there were eight! Dynamic Programming is just a fancy way to say ‘remembering stuff to save time later’
Applications:
- There are many DP algorithms and applications but I’d name one and blow you away, Duckworth-Lewis method in cricket.
5. Exponentiation by squaring
Say you want to calculate 232. Normally we’d iterate 32 times and find the result. What if I told you it can be done in 5 iterations?
Exponentiation by squaring or
Binary exponentiation is a general method for fast computation of large positive integer powers of a number in O(log
2N). Not only this, the method is also used for computation of powers of polynomials and square matrices.
Application:
- Calculation of large powers of a number is mostly required in RSA encryption. RSA also uses modular arithmetic along with binary exponentiation.
6. String Matching and Parsing
Pattern matching/searching is one of the most important problem in Computer Science. There have been a lot of research on the topic but we’ll enlist only two basic necessities for any programmer.
KMP Algorithm (String Matching)
Knuth-Morris-Pratt algorithm is used in cases where we have to match a short pattern in a long string. For instance, when we Ctrl+F a keyword in a document, we perform pattern matching in the whole document.
Regular Expression (String Parsing)
Many a times we have to validate a string by parsing over a predefined restriction. It is heavily used in web development for URL parsing and matching.
7. Primality Testing Algorithms
There are deterministic and probabilistic ways of determining whether a given number is prime or not. We’ll see both deterministic and probabilistic (nondeterministic) ways.
Sieve of Eratosthenes (deterministic)
If we have certain limit on the range of numbers, say determine all primes within range 100 to 1000 then Sieve is a way to go. The length of range is a crucial factor, because we have to allocate certain amount of memory according to range.
For any number n, incrementally testing upto sqrt(n) (deterministic)
In case you want to check for few numbers which are sparsely spread over a long range (say 1 to 1012), Sieve won’t be able to allocate enough memory. You can check for each number n by traversing only upto sqrt(n) and perform a divisibility check on n.
Fermat primality test and Miller–Rabin primality test (both are nondeterministic)
Both of these are compositeness tests. If a number is proved to be composite, then it sure isn’t a prime number. Miller-Rabin is a more sophisticated one than Fermat’s. Infact, Miller-Rabin also has a deterministic variant, but then its a game of trade between time complexity and accuracy of the algorithm.
Application:
- The single most important use of prime numbers is in Cryptography. More precisely, they are used in encryption and decryption in RSA algorithm which was the very first implementation of Public Key Cryptosystems
- Another use is in Hash functions used in Hash Tables
We’ll discuss some advanced algorithms every competitive programmer should know in the next post. Meanwhile master the above algorithms or share in the comments about what you think every beginner-intermediate programmer should know.