so I wrote some Java code to list files in a directory and its sub-directories that were modified today. I need a little help understanding the time and space complexity.
The code:
public class FileInDir {
File[] files = null; Date d = new Date(); long mill; public void listTodayFiles(String path) { File dir = new File(path); files = dir.listFiles(); for(File file : files){ mill = file.lastModified(); Date f = new Date(mill); if(f.getDate() == d.getDate()){ if(file.isFile()) System.out.println("FILE: " + file.getName() + " WAS LAST MODIFIED ON: " + f); else if(file.isDirectory()) listTodayFiles(file.getAbsolutePath()); } } }
}
So from what I understand, storing all the files into the array takes O(n) time, the loop takes O(n) time. I'm unsure about the complexity for the recursive call. I'm also unsure if the if statement plays a role in time or space complexity. Also will the space complexity be O(n) because it needs to store each element (file).
Thanks :D