hello everybody and welcome to another youtube video so in today's video i'm going to be explaining greedy algorithms now this is really meant to just be an introduction to this topic so in this video i will explain to you what a greedy algorithm is how you can go about creating a greedy algorithm and then show you a few examples of it but with that said if you want to learn more and practice with greedy algorithms what you can do is check out the sponsor of this video before we get started i need to thank the sponsor of this video which is alcoexpert algo expert is the best platform to use from preparing for your software engineering coding interviews and has the highest quality coding interview practice questions with NUMBER_TOKEN practice questions detailed solutions in nine of the most popular programming languages a feature-packed browser-based coding environment extensive test suites and conceptual overviews and code walkthroughs for each and every problem algo expert is the best resource to use to ace your coding interviews algo expert also has a data structures crash course coding interview assessments and a mock interviews feature i can highly recommend algo expert as a former customer myself and now an official instructor on the platform get started using algo expert today by clicking the link in the description and using the code tech with tim for a discount on the platform so i'm here on my drawing tablet and i'm going to start explaining to you what greedy algorithms are now before i do that i will note that i do have very messy handwriting so please excuse me i'll try my best to make everything as neat as possible in this video with that said what is a greedy algorithm well a greedy algorithm is really an algorithm that makes a greedy choice you can think of this as kind of an optimal choice at every single step in the solution or in the problem now the greedy choice is defined by some rule that rule could be select the largest number select the smallest number select the element that has a certain property whatever you're making some definitive choice some greedy choice at every step in the algorithm now greedy algorithms can be very complicated they can also be quite simple to give you an explanation or kind of an example of a greedy algorithm let me kind of introduce a problem to you right here so let's say for this problem we're given some array and this array is filled with integers so i have NUMBER_TOKEN NUMBER_TOKEN negative NUMBER_TOKEN NUMBER_TOKEN negative NUMBER_TOKEN and NUMBER_TOKEN and then maybe we're given some integer n we can say here that n is equal to NUMBER_TOKEN. now what this problem is asking us to do is to find the n numbers in this array that equal the largest sum now if that's the case the greedy algorithm approach to solving this problem is to simply select the largest number at every single step until we've selected n numbers and this should hopefully solve the problem for us so if we apply the greedy algorithm approach we're selecting the largest number at every step until we've hit four numbers so what we do is we start by selecting four because this is the current largest number so we select four then we select NUMBER_TOKEN because NUMBER_TOKEN was already selected so now we have NUMBER_TOKEN and NUMBER_TOKEN. then we select NUMBER_TOKEN and then finally we select NUMBER_TOKEN and what we get is NUMBER_TOKEN NUMBER_TOKEN NUMBER_TOKEN and NUMBER_TOKEN which means that we have an answer of NUMBER_TOKEN. so that's the largest sum that we can create by selecting four numbers and this would actually be our answer here we would return NUMBER_TOKEN NUMBER_TOKEN NUMBER_TOKEN and NUMBER_TOKEN.
START_SPONSOR_TOKEN of this video before we get started i need to thank the sponsor of this video which is alcoexpert algo expert is the best platform to use from preparing for your software engineering coding interviews and has the highest quality coding interview practice questions with NUMBER_TOKEN practice questions detailed solutions in nine of the most popular programming languages a feature-packed browser-based coding environment extensive test suites and conceptual overviews and code walkthroughs for each and every problem algo expert is the best resource to use to ace your coding interviews algo expert also has a data structures crash course coding interview assessments and a mock interviews feature i can highly recommend algo expert as a former customer myself and now an official instructor on the platform get started using algo expert today by clicking the link in the description and using the code tech with tim for a discount on the platform END_SPONSOR_TOKEN