Welcome 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
You are too fast :/ please teach slowly π
Sorry about that. It may help to print the code and take notes. I tend to be quicker then everyone else
About 950 lines of high quality and free code, and this is just for one of your hundreds videos.
You are the Man !
Thank you very much π Everything I ever do will be free. Always feel free to do anything you’d like with the code
Hey Buddy,
Have you ever thought of making teams for such a great free work you do?
Hey, I’m not sure what you mean by teams? Thank you π I’m glad you enjoy the videos.
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.
Thank you very much π I do my best. Sorry it took so long to answer you. My real life world has been a little out of control lately
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
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?
hi derek, i wrote some two or three commnets but all of them are deleted i don’t know what is happening.plz explain.
Sorry about that. I got backed up because my real world life has been crazy
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.
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!
Thank you π I just enjoy helping people. It is very gratifying to be able to help. Thank you for the very kind words!
great job!!
Thank you π
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?
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
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
π
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
Just one question. How did you call non-static functions from a static context. How did you call them in void main?
I created an object of type newArray. Does that answer your question?
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!
Always feel free to ask questions and thank you for the nice compliment π
Excellent tutorial!! Thanks and keep up the good work.
Thank you very much π Many more videos are coming.
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. π
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
also i forgot in the insertValue method, why is it theArray[arraySize] = value; can u explain to me exactly what that means
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
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
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 π
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
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 π
Perfect! Finally tutorials that are comprehensive and intelligently presented. Thanks a million for these!
Thank you π and you’re very welcome
Thank you sir!
You’re very welcome π
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.
Hi, You are very welcome. What data structure do you want me to cover?
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
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.
Hi Derek, Can you post a video, detailing the Dijkstra’s algorithm.
Thanks
Abhishek
I’ll see if I can fit it in.
Your tutorials are very helpful. Thanks a lot!
Thank you π
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.
Thank you π I have been thinking about iOS. I may cover it after I finish up Android
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?
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.
Derek, excellent tutorials. Any chance we can get a link to slideshare for the slides you are using in the videos?
Thank you π Sorry, but I deleted the slides. Sorry about that.
Great tutorials. Keep unlocking knowledge. Thank You!
Thank you π You’re very welcome
Hi Derek this is amazing tutorial for my data structure class.you made my life easy. You are the man.
Thank you π I’m happy that I could help.