Neha
Neha

Reputation: 255

data structure applications example code (preferably in Java)

I'm learning data structures since last 2 months.
Have got good at basics of each but still find myself unable to apply it to any real world problem.

Whenever I come across any problem, my mind still goes in old mode of creating array or list of objects and then coding solution. (like older days when I was switching to OOP from procedure programming. But now I can see everything as object :))

I tried to search on net and went through few books also. But each book is filed with basic algorithms. (ex. creating/inserting/deleting/finding element in stack, queue, tree etc... and their Big O evaluations)

I'm looking for actual code implementations of some real problems.

Upvotes: 0

Views: 1509

Answers (1)

AardvarkSoup
AardvarkSoup

Reputation: 1081

Here are some random examples of applications of a few data structures (not all of them extremely realistic and/or practical, I must admit), there are of course many more but this should give some indications:

  • Hash table: you have a large dictionary of words and definitions. A user is able to input a word and directly see its definition. It should also be possible to extend the dictionary with new words.
  • Balanced binary search tree (e.g. Red-black): same dictionary; except this time, when a user inputs a word, you also want to display the 10 words that alphabetically come before and after it.
  • Linked List: you're an evil hacker programming a key logger that listens to someone inputting a password in a password field. Unfortunately that person tends to make a lot of typos and constantly corrects themself by using the arrow keys, delete and backspace. The list in question contains the characters typed. You also have an iterator positioned at the same place as the cursor, and used it accordingly.
  • Queue: you are handling sequential requests to a web server, one at a time. Whenever a new request comes in while you're still busy with another one you put it in the queue.
  • Priority queue: you're implementing a process scheduler. When the time of a process is over you put it in the queue and depend its key on the process priority and the point of time at which is stopped.

Upvotes: 1

Related Questions