Hack Forums
[Java] Simple program that involves certain algorithms - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Simple program that involves certain algorithms (/showthread.php?tid=6039764)



Simple program that involves certain algorithms - allesbaba - Jan 10, 2020

Hey all,

So our algorthims teacher asked us to make a simple project (program) in java that would involve one of the topics that we learnt during the semester but I have no idea what to do. So we learnt about some string search/sorting algorithms like LSD, MSD, Bruteforce, Knuth-Morris-Pratt (DFA), boyer-moore alg and rabin karp. So what I'm asking is if you have any idea what could I do or if you have any source to get some ideas. It doesn't necessarily have to be complicated (it can be as easy as selecting a file and sorting it using DFS or something).

I'd really appreciate your help, have a nice day all. 🤝


RE: Simple program that involves certain algorithms - JordanClutch - Jan 10, 2020

A simple program would be sorting a text file where each line contains a string, you could use any sorting algorithm for this such as merge sort.

Something more advanced would be using BFS or DFS to solve a maze, but you would need to generate your own maze or find an existing maze for this.


RE: Simple program that involves certain algorithms - MavenGradle - Jan 10, 2020

Here are some ideas that might help to get you started.

Depth first search / Breadth first search:

I'm a traveller, looking for flights to catch until I reach my destination. The question that I'm faced with, is what the route is that I can take that takes the least amount of time in order to get to my destination. I don't care how many times I have to switch flights.
Each node (as seen on the graph below) can be seen as a change of flights. Each node holds a specific score, this represents the amount of time it takes to get to that point. The end node of every branch can be seen as the destination, but holds a different score depending on the previous node (Obviously, because travelling from Paris to Amsterdam takes less time than travelling from New York to Amsterdam).

An example of flight paths:
[Image: Screen%2BShot%2B2015-12-27%2Bat%2B11.19.48%2Bpm.png]

If you can, please create a version of this which utilizes an A* algorithm to perform the search.
Also, if possible, please explain to me why both methods (DFS/BFS) are imperfect/incorrect for this particular use case.

Helping materials:
https://stackabuse.com/graphs-in-java-depth-first-search-dfs/
https://stackabuse.com/graphs-in-java-breadth-first-search-bfs/

Bruteforce:
Consider the following example character set:
Code
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

I'd like to see a list of unique strings that you can generate that are formatted in the following fashion:
Code
[A-Z][A-Z][A-Z]-[0-9][0-9][0-9]-[A-Z][A-Z][A-Z]

Example output:
Code
AAA-000-AAAA
AAA-000-AAAB

Hint (C#):
https://hackforums.net/showthread.php?tid=6019165&pid=59087444#pid59087444