Posts

Showing posts from August 12, 2018

Java: Constructor- and Method-overloading exercise

Image
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 2 down vote favorite It's from a Java-course I'm enrolled into. The classes "Instructor" and "Book" are already provided. You got to write the different constructors of "Instructor" as well as the methods "getMostRecentBookTitle" and overloaded "updateBook". Here's are the final classes expanded with my additional code: // ------- Class Instructor ---------------------------------------- public class Instructor public long id; public String name; public String title; public String department; public Book books; public Instructor(long id, String name, String title, String department, Book books) this(id, name, title, department); this.books = books; public Instructor(long id, String name, String title, String department) this(id, name, title); this.department = department

Algorithmic complexity of this algorithm to find all ordered permutations of length X

Image
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 1 down vote favorite I have written a recursive function to generate the list of all ordered permutations of length X for a list of chars. For instance: ['a', 'b', 'c', 'd'] with X=2 will give [['a', 'a'], ['a', 'b'], ['a', 'c'], ['a', 'd'], ['b', 'a'], ['b', 'b'], ..., ['d', 'd']] I'm not sure about its algorithmic complexity though (at least I know it's pretty horrible). I would say it's something around: O(X * N^(L + X)) (where L is the number of different chars, 4 here because we have 'A', 'B', 'C', 'D', and X the length of the permutations we want to generate). Because I have 2 nested loops, which will be run X times (well, X-1 because of the special cas