Anna CS 110 - Data Structures and Algorithms for Beginners
School name Anna University
Course Cs 110-
Pages 5

Unformatted text preview:

Data Structures and Algorithms for Beginners Programming with Mosh a In this we talk about the basics of data structures and algorithms We use the Big O notation to describe the performance of an algorithm This helps us determine if a given algorithm is scalable or not which basically means is this algorithm going to scale well as the input grows really large Just because your code executes quickly on your computer does n t mean it s gon na perform well when you give it a large data set Using the Big O notation to describe the performance of our algorithms we re going to look at code snippets and use it to describe performance of algorithms Over the next few videos we re going to talk about how scalable an algorithm is and nally knowing Big L will make you a better developer or software engineer The algorithm is the algorithm that we use for printing all combinations of items in an array here we re using a traditional for loop we could also use a for each loop for example for int number in numbers we could simply print the number we re still iterating over all the items in this array The run time complexity of this method is o of 1 plus n plus 1 which we can simplify to or of 2 plus n however when using the Big O notation we drop this constant because they do n t really matter An algorithm that runs in quadratic time is more e cient and more scalable than a linear algorithm As our input grows larger and larger algorithms that run in O of N squared get slower and slower Algorithms that run into a linear search are more e cient than those that run through linear time Algorithm that runs through an array of sorted numbers from 1 to 10 can be more e cient An algorithm with logarithmic time is more scalable than one with linear time An algorithm that runs in exponential time is not scalable at all it will become very slow very soon again I can not show you an example of this in code now because it s a bit too complex to show it in code The run time of this algorithm increases linearly and in direct proportion with the size of our array Marcia explains how we can use the Big O notation to describe the runtime complexity of our algorithms in an ideal world we want our algorithms to be super fast and scalable and take minimum amount of memory but unfortunately that hardly if ever happens it s like asking for a Ferrari for ten dollars it just does n t happen most of the time we have to do a trade o between saving time and saving space Marcia says this video is actually part of my ultimate data structures and algorithms course the complete course is 13 hours long I highly encourage you to take this course and learn all the essential data structures and algorithms from scratch divided it into three parts so you can take and complete each part easily The course is packed with almost 100 interview questions that get asked by companies like Google Microsoft and Amazon Ar arrays are static which means when we allocate them we should specify their size and this size can not change later on To add another item we ll have to resize the array which means we should allocate a larger array and then copy all the items in the old array into the new array this operation can be costly can you guess the runtime complexity of this operation IntelliJ imports an array of 3 items in Java dot util so we press ENTER and use the dot operator and call the two string method a password array This method will convert it to a string and then we ll print that string on the console no let s run the program one more time there you go much much better As we learn arrays in Java or static which means they have a xed size and this size can not be changed but now we re going to do something really cool I ve created this array class which is like a dynamic array as we add new items to it it will automatically grow and as we remove items it will shrink talk about them in the next section but before we get there I m gon na give you a fantastic exercise we ll look at that next This is the approach I want you to follow whenever you want to solve a complex problem do n t try to do too many things at once try to break down that problem into smaller easier to understand easier to solve problems In this video we just want to focus on creating this array class and printing its content on the console The rst step is to create a new array that is larger and then copy all the existing items into this new array The index of the last item or the place where we should insert the new item is index 0 next time we add a new item the index is gon na be 1 and then we increment count by 1 or we can simplify this code get rid of this line

View Full Document

Anna CS 110 - Data Structures and Algorithms for Beginners

Course: Cs 110-
Pages: 5
Download Data Structures and Algorithms for Beginners
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...

Join to view Data Structures and Algorithms for Beginners and access 3M+ class-specific study document.

We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Data Structures and Algorithms for Beginners 2 2 and access 3M+ class-specific study document.


By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?