SlideShare a Scribd company logo
// finds a single missing integer in an array
unsigned Arrays::MissingInt(unsigned* _arr, unsigned _arrSize)
{
// equation for summing all numbers in a range ('- 1' since _arr starts at 1)
unsigned grandTotal = ((_arrSize * (_arrSize + 1)) / 2) - 1;
// summing of numbers in the array
// since array is short by 1, must reduce by 2 to get actual back index value
unsigned front = 0, back = _arrSize - 2, arrTotal = 0;
// two at a time. ie front and back of array (faster)
// do while instead of for loop because i think it looks better (cleaner)
do{
arrTotal += (_arr[front++] + _arr[back--]);
} while (front < back);
// if odd numbered array, front and back will eventually be the same
// need to add ONE of them to arrTotal (not both)
// did this here to avoid running the check every loop
if (front == back) arrTotal += _arr[front];
// subtracting current total from grand total will return the missing number
return grandTotal - arrTotal;
}
// compares values in array to find a single duplicate (multiple versions)
unsigned Arrays::DuplicatedInt(unsigned* _arr, unsigned _arrSize)
{
#if 1
// fast O(count), but extra memory (hash_map)
hash_map<unsigned, unsigned> dupCheck;
for (unsigned count = 0; count < _arrSize; count++)
{
if (!dupCheck.emplace(_arr[count], _arr[count]).second)
return _arr[count];
}
#endif
#if 0
// double for loop = slow O(n^2), but breaks as soon as it finds a duplicate so O(n * count)
// also no extra variable(s)
for (unsigned countA = 0; countA < _arrSize; countA++)
{
for (unsigned countB = countA + 1; countB < _arrSize; countB++)
{
if (_arr[countA] == _arr[countB])
return _arr[countA];
}
}
#endif
#if 0
// takes time to sort (esp w/ 1,000,000 entries), but less memory (no extra variable(s))
O(nlog(n) + count)?
std::sort(_arr, _arr + _arrSize);
for (unsigned count = 0; count < _arrSize; count++)
{
if (_arr[count] == _arr[count + 1])
return _arr[count];
}
#endif
return -1;
}

More Related Content

What's hot

The hidden and new parts of JS
The hidden and new parts of JSThe hidden and new parts of JS
The hidden and new parts of JS
Ritesh Kumar
 
Rcpp11 genentech
Rcpp11 genentechRcpp11 genentech
Rcpp11 genentech
Romain Francois
 
R/C++ talk at earl 2014
R/C++ talk at earl 2014R/C++ talk at earl 2014
R/C++ talk at earl 2014
Romain Francois
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6ecomputernotes
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
Trupti Agrawal
 
Memory management in cocos2d x - Le Duy Vu
Memory management in cocos2d x - Le Duy VuMemory management in cocos2d x - Le Duy Vu
Memory management in cocos2d x - Le Duy VuFramgia Vietnam
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
Joachim Bengtsson
 
Stack
StackStack
Computer notes data structures - 9
Computer notes   data structures - 9Computer notes   data structures - 9
Computer notes data structures - 9ecomputernotes
 
Lisp tutorial
Lisp tutorialLisp tutorial
Lisp tutorial
Nilt1234
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
Samsil Arefin
 

What's hot (13)

The hidden and new parts of JS
The hidden and new parts of JSThe hidden and new parts of JS
The hidden and new parts of JS
 
Rcpp11 genentech
Rcpp11 genentechRcpp11 genentech
Rcpp11 genentech
 
R/C++ talk at earl 2014
R/C++ talk at earl 2014R/C++ talk at earl 2014
R/C++ talk at earl 2014
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Tugas1
Tugas1Tugas1
Tugas1
 
Memory management in cocos2d x - Le Duy Vu
Memory management in cocos2d x - Le Duy VuMemory management in cocos2d x - Le Duy Vu
Memory management in cocos2d x - Le Duy Vu
 
Circuloapp
CirculoappCirculoapp
Circuloapp
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
 
Stack
StackStack
Stack
 
Computer notes data structures - 9
Computer notes   data structures - 9Computer notes   data structures - 9
Computer notes data structures - 9
 
Lisp tutorial
Lisp tutorialLisp tutorial
Lisp tutorial
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
 

Viewers also liked

Fluxo de atendimento aos pacientes de malária na unidade de saúde
Fluxo de atendimento aos pacientes de malária na unidade de saúdeFluxo de atendimento aos pacientes de malária na unidade de saúde
Fluxo de atendimento aos pacientes de malária na unidade de saúde
Daniel Mota
 
07 mar-2013
07 mar-201307 mar-2013
07 mar-2013
civil1980
 
The DI - Chitimacha Expansion
The DI - Chitimacha ExpansionThe DI - Chitimacha Expansion
The DI - Chitimacha ExpansionBarbara L. Nelson
 
21 jun-2012
21 jun-201221 jun-2012
21 jun-2012
civil1980
 
Product key
Product keyProduct key
Product keysajeepan
 
How to Generate Website Visits and Convert More Sales Leads
How to Generate Website Visits and Convert More Sales LeadsHow to Generate Website Visits and Convert More Sales Leads
How to Generate Website Visits and Convert More Sales Leads
StoryTeller Media + Communications
 
Peticion de visitas ficha 581708 - sena
Peticion de visitas   ficha 581708 - senaPeticion de visitas   ficha 581708 - sena
Peticion de visitas ficha 581708 - sena
Misa Amane
 

Viewers also liked (9)

Fluxo de atendimento aos pacientes de malária na unidade de saúde
Fluxo de atendimento aos pacientes de malária na unidade de saúdeFluxo de atendimento aos pacientes de malária na unidade de saúde
Fluxo de atendimento aos pacientes de malária na unidade de saúde
 
interview
interviewinterview
interview
 
07 mar-2013
07 mar-201307 mar-2013
07 mar-2013
 
The DI - Chitimacha Expansion
The DI - Chitimacha ExpansionThe DI - Chitimacha Expansion
The DI - Chitimacha Expansion
 
21 jun-2012
21 jun-201221 jun-2012
21 jun-2012
 
Product key
Product keyProduct key
Product key
 
How to Generate Website Visits and Convert More Sales Leads
How to Generate Website Visits and Convert More Sales LeadsHow to Generate Website Visits and Convert More Sales Leads
How to Generate Website Visits and Convert More Sales Leads
 
Peticion de visitas ficha 581708 - sena
Peticion de visitas   ficha 581708 - senaPeticion de visitas   ficha 581708 - sena
Peticion de visitas ficha 581708 - sena
 
IMS Observer Brochure
IMS Observer BrochureIMS Observer Brochure
IMS Observer Brochure
 

Similar to Arrays

i am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdfi am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdf
ANJALIENTERPRISES1
 
DAA Lab Work.docx
DAA Lab Work.docxDAA Lab Work.docx
DAA Lab Work.docx
Deepusri2000Srivasta
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
Maxima Finding problem In the 2-dimension space, we shall say that .pdf
Maxima Finding problem In the 2-dimension space, we shall say that .pdfMaxima Finding problem In the 2-dimension space, we shall say that .pdf
Maxima Finding problem In the 2-dimension space, we shall say that .pdf
arrowit1
 
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
mdameer02
 
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdfPart 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
mohammadirfan136964
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
arorasales234
 
Object oriented programming; operator overloading array
Object oriented programming; operator overloading arrayObject oriented programming; operator overloading array
Object oriented programming; operator overloading array
Syed Zaid Irshad
 
check the modifed code now you will get all operations done.termin.pdf
check the modifed code now you will get all operations done.termin.pdfcheck the modifed code now you will get all operations done.termin.pdf
check the modifed code now you will get all operations done.termin.pdf
angelfragranc
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
amitbagga0808
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
Bhuvana Gowtham
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
a) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfa) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdf
nageswara1958
 
8558537werr.pptx
8558537werr.pptx8558537werr.pptx
8558537werr.pptx
ssuser8a9aac
 
c++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdfc++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdf
dhavalbl38
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
Daniel Cukier
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx
ajoy21
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
arri2009av
 

Similar to Arrays (20)

i am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdfi am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdf
 
DAA Lab Work.docx
DAA Lab Work.docxDAA Lab Work.docx
DAA Lab Work.docx
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
Maxima Finding problem In the 2-dimension space, we shall say that .pdf
Maxima Finding problem In the 2-dimension space, we shall say that .pdfMaxima Finding problem In the 2-dimension space, we shall say that .pdf
Maxima Finding problem In the 2-dimension space, we shall say that .pdf
 
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
 
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdfPart 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
 
Object oriented programming; operator overloading array
Object oriented programming; operator overloading arrayObject oriented programming; operator overloading array
Object oriented programming; operator overloading array
 
check the modifed code now you will get all operations done.termin.pdf
check the modifed code now you will get all operations done.termin.pdfcheck the modifed code now you will get all operations done.termin.pdf
check the modifed code now you will get all operations done.termin.pdf
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
a) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfa) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdf
 
8558537werr.pptx
8558537werr.pptx8558537werr.pptx
8558537werr.pptx
 
c++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdfc++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdf
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 

More from George Scott IV

Square selection function
Square selection functionSquare selection function
Square selection function
George Scott IV
 
Save game function
Save game functionSave game function
Save game function
George Scott IV
 
Delete save from folder function
Delete save from folder functionDelete save from folder function
Delete save from folder function
George Scott IV
 
Trees
TreesTrees
Strings
StringsStrings
Linked lists
Linked listsLinked lists
Linked lists
George Scott IV
 
Misc
MiscMisc

More from George Scott IV (7)

Square selection function
Square selection functionSquare selection function
Square selection function
 
Save game function
Save game functionSave game function
Save game function
 
Delete save from folder function
Delete save from folder functionDelete save from folder function
Delete save from folder function
 
Trees
TreesTrees
Trees
 
Strings
StringsStrings
Strings
 
Linked lists
Linked listsLinked lists
Linked lists
 
Misc
MiscMisc
Misc
 

Recently uploaded

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 

Recently uploaded (20)

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 

Arrays

  • 1. // finds a single missing integer in an array unsigned Arrays::MissingInt(unsigned* _arr, unsigned _arrSize) { // equation for summing all numbers in a range ('- 1' since _arr starts at 1) unsigned grandTotal = ((_arrSize * (_arrSize + 1)) / 2) - 1; // summing of numbers in the array // since array is short by 1, must reduce by 2 to get actual back index value unsigned front = 0, back = _arrSize - 2, arrTotal = 0; // two at a time. ie front and back of array (faster) // do while instead of for loop because i think it looks better (cleaner) do{ arrTotal += (_arr[front++] + _arr[back--]); } while (front < back); // if odd numbered array, front and back will eventually be the same // need to add ONE of them to arrTotal (not both) // did this here to avoid running the check every loop if (front == back) arrTotal += _arr[front]; // subtracting current total from grand total will return the missing number return grandTotal - arrTotal; } // compares values in array to find a single duplicate (multiple versions) unsigned Arrays::DuplicatedInt(unsigned* _arr, unsigned _arrSize) { #if 1 // fast O(count), but extra memory (hash_map) hash_map<unsigned, unsigned> dupCheck; for (unsigned count = 0; count < _arrSize; count++) { if (!dupCheck.emplace(_arr[count], _arr[count]).second) return _arr[count]; } #endif #if 0 // double for loop = slow O(n^2), but breaks as soon as it finds a duplicate so O(n * count) // also no extra variable(s) for (unsigned countA = 0; countA < _arrSize; countA++) { for (unsigned countB = countA + 1; countB < _arrSize; countB++) { if (_arr[countA] == _arr[countB]) return _arr[countA]; } } #endif #if 0 // takes time to sort (esp w/ 1,000,000 entries), but less memory (no extra variable(s)) O(nlog(n) + count)? std::sort(_arr, _arr + _arrSize); for (unsigned count = 0; count < _arrSize; count++) { if (_arr[count] == _arr[count + 1]) return _arr[count]; } #endif return -1; }