Java Algorithms

Java AlgorithmsWelcome to my Java Algorithms tutorial. In this series I will cover everything there is to know about Java algorithms and data structures.

An algorithm is just the steps you take to manipulate data. A data structure is the way data is arranged in memory. There are 3 main data structure operations I will focus on first being inserting, deleting and searching for data.

Like all of my tutorials, everything is simple at first and then I cover more complex topics. The code below should help.

If you like videos like this, it helps to tell Google+ [googleplusone]

Code From the Video

ArrayStructures.java

Β The MVC Version of the Above Program

57 thoughts on “Java Algorithms”

  1. About 950 lines of high quality and free code, and this is just for one of your hundreds videos.
    You are the Man !

  2. hi derek, i just understood some 400 lines of code from this video which should take a college teacher a week to teach, u r so quick and this is the thing i like about u. be quick and fast and upload as many videos on java as u can.i am hoping that u will make videos on android development.thanks a lot man.

  3. derek the above MVC code is complicated, it took me half an hour to figure it out. i think AlgorithmsMVC should be declared as public class in his own source file because it is the class that contains main method

    1. Sorry about that. AlgorithmsMVC is actually protected here and all the other classes can access it because they are in the same package. It could have been public, but that isn’t needed. Does that make sense?

  4. hi derek, i wrote some two or three commnets but all of them are deleted i don’t know what is happening.plz explain.

  5. hi derek, i wanna say is that i posted two comments 2 days ago and both of them r deleted.did i do something wrong that i deleted them if u did not then plz look into the matter i am waiting for ur response.

  6. Derek, you are simply an amazing human being. You have made hundreds of videos, thousands of lines of code, and all for free, to teach us mere mortals. That’s beyond inspiring. You make me want to become a better human being!

  7. Awesome tutorials, love your tempo, straight to the point and knowledgeable. Personally find I don’t remember much when its s l o w and d u l l lecture type explanations. I will working through all your coding tutorials πŸ™‚ Have you been coding for a long time I wonder?

    1. I have been programming since I was about 10, so I have almost 30 years of experience. I’m glad you like the videos. I always wanted to make original videos, so I figured since everyone else was slow I’d make fast ones

  8. Hey derek, i almost gave up on java until i found your tutorials. i just want to thank you for boosting up my confidence. And its so pleasing to see people like you are helping us to get through this tough topics without any cost. you have no idea how you are changing our lives. and my best wishes for you to carry on
    πŸ™‚

    1. Thank you very much for taking the time to say I helped πŸ™‚ I have continued to make these tutorials because of all the kind people I have met from around the world.

      I originally planned to do my best to provide a free education to all, but I don’t think I would have stuck with it for over 5 years if I wouldn’t have met all the nice people that I have. I’m extremely grateful that I’m able to help.

      Thanks again
      Derek

      1. Yes! I was very tired and doing this on 3 am on BlueJ. I’m trying to learn about CS teoretical stuff since I have a degree in economics. I’ve been doing java for about 2 years. I’m actually embarassed by my question. LOL.

        Best core java tutorials on youtube!

  9. i started viewing ur series about arlgorithms,and i can understand whats going on but i have some troubles i would like u to clear for me, i will go one by and i would like u to explain to me like that, if its not a problem.

    1st: when u declared in the beggining theArray = new int[50], does that mean that the array contains 50 int elements, i mean because u puted arraySize to be equal to 10; does that mean even if u put that theArray = new int[10]; instead of 50 it would print the same like it printed with 50, i mean when u do the math.random() stuff

    2nd: about the Math.random()*10)+10 , it prints the random number from 10 through 19 thats because of the 0th index in the array right

    3rd: in the deleteIndex method in the for loop i < (arraySize – 1) i get that its because the arrays first index is 0 and arraySize is equal to 10 , but what i dont get u said in ur video it because arraySize is 10 and we have 9 fields, how come we have nine fields i mean we have from 0 to 9 thats the count 0, can u explain to me that please, and also u putted theArray[i] = theArray[i + 1]; in for loop if the same method, why did u put theArray[i +1]

    4th: in the insertValue method i dont understand why is it if(arraySize < 50) , i get in the other methods if(index < arraySize) etc i understand that, because arraySize is up to 10 and if u put index to be 11 then u will get nothing because u dont have that column, but here i dont get why is it < 50 and in ur video u putet value 55 and it was added, can u please explan to me that. and also in the same method : theArray[arraySize] = value; i dont understand this, if u can also explain to me this.

    thank u in advance for all ur hard work and great tutorials!

    im still trying to figure out whats going on in the linearSearch and im shure i have question about that one too but i want to get the main idea how it works and then i will ask u about it. πŸ™‚

    1. in the 3rd , where i explained about how i dont understand how we have 9 fields i forgot to write 10 where i said that we have from 0 to 9 and thats 10 ,countung the 0th index

      1. also i forgot in the insertValue method, why is it theArray[arraySize] = value; can u explain to me exactly what that means

        1. The current array size is being monitored by the class here

          private int arraySize = 10; // Elements in theArray – See more at: http://www.newthinktank.com/2013/02/java-algorithms/#sthash.u4D88pjR.dpuf

          Value was either increased or decreased by these methods

          public void deleteIndex(int index){
          086
          087 if(index < arraySize){ 088 089 // Overwrite the value for the supplied index 090 // and then keep overwriting every index that follows 091 // until you get to the last index in the array 092 093 for(int i = index; i < (arraySize - 1); i++){ 094 095 theArray[i] = theArray[i+1]; 096 097 } 098 099 arraySize--; 100 101 } 102 103 } 104 105 public void insertValue(int value){ 106 107 if(arraySize < 50){ 108 109 theArray[arraySize] = value; 110 111 arraySize++; 112 113 } 114 115 } - See more at: http://www.newthinktank.com/2013/02/java-algorithms/#sthash.u4D88pjR.dpuf

    2. also in the linear search method im confused at the end where it says if(!valueInArray) does this mean if valueInArray is not false because u puted it to be false in the begining and also if i was true in the begining than it would mean if valueInArray is not true , am i right, if not can u explan to me please thank you

    3. i think i figured it out about the if(!valueInArray), i think its not refereing to the valueInArray in the top its refering to the valueInArray in the if loop which is in the for loop, and it means if valueInArray is not true ,because in the if statement valueInArray is set to true, in that case indexsWithValue are none, because the valueInArray is not true and system prints none because there are no values in indexes, am i right this time πŸ˜€

      1. valueInArray is just a way for us to mark that the value is in the array or not. It is either set to true while checking in the following code or it remains false. Sorry about the confusion.

        for(int i = 0; i < arraySize; i++){ 128 129 if(theArray[i] == value) { 130 valueInArray = true; 131 132 System.out.print(i + " "); 133 134 indexsWithValue+= i + " "; 135 } 136 137 } - See more at: http://www.newthinktank.com/2013/02/java-algorithms/#sthash.u4D88pjR.dpuf

    4. int[50] means that that is the maximum number of items in the array since it is static. arraySize monitors how many items are currently in the array.

      Math.random()*10 : Generates numbers between 0 and 9

      I’m sorry, but I don’t understand the 3rd question.

      I’m checking to make sure I don’t try and add more values then the array allows with i < (arraySize – 1) I hope that helps πŸ™‚

  10. Hi Derek Banas;
    thank you for spending your time to help people. If you have time, I’d like you to teach me in Data Structure.
    again many thanks for your help.

      1. Thank you for your replay.
        The book is (Data Structures Abstraction and Design Using Java) and I also would like to discuss this via email if it’s possible.
        Many thanks for you

        1. Sorry, but I have not read that book. I plan on getting back into data structures and algorithms soon though. Feel free to leave any questions you have here. I get over 1000 emails a day.

  11. Hi Derek!
    Your tutorials are so awesome, I can’t thank you enough!!!
    Will you be covering iOS development anytime soon?
    Thank you so much for your wonderful work, it’s helped me so much.

  12. This is amazing. You donot teach just one piece of code like everyone else. But you are getting us into the real stuff. I can tell you are very passionate about your work. Do you tutor people personally.? It would be great if you could?

    1. Thank you for the compliment πŸ™‚ I used to spend a lot of time teaching junior programmers. I basically feel like this medium allows me to reach many more people which is great.

Leave a Reply

Your email address will not be published. Required fields are marked *