SlideShare a Scribd company logo
1 of 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;
}

More Related Content

What's hot

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údeDaniel Mota
 
The DI - Chitimacha Expansion
The DI - Chitimacha ExpansionThe DI - Chitimacha Expansion
The DI - Chitimacha ExpansionBarbara L. Nelson
 
Product key
Product keyProduct key
Product keysajeepan
 
Peticion de visitas ficha 581708 - sena
Peticion de visitas   ficha 581708 - senaPeticion de visitas   ficha 581708 - sena
Peticion de visitas ficha 581708 - senaMisa 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.pdfANJALIENTERPRISES1
 
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.pdffeelinggift
 
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 .pdfarrowit1
 
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.pdfmdameer02
 
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.pdfmohammadirfan136964
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetJose 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 .pdfarorasales234
 
Object oriented programming; operator overloading array
Object oriented programming; operator overloading arrayObject oriented programming; operator overloading array
Object oriented programming; operator overloading arraySyed 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.pdfangelfragranc
 
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.pdfamitbagga0808
 
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.pdfshreeaadithyaacellso
 
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.pdfnageswara1958
 
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.pdfdhavalbl38
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaDaniel 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.docxajoy21
 
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.pdfarri2009av
 

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

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

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Recently uploaded (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

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; }