Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6860473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:24:47+00:00 2026-05-27T02:24:47+00:00

i have a question on a problem i am working on. I have to

  • 0

i have a question on a problem i am working on. I have to play Videos randomly in order without repeating a video. Each video is only allowed to be played once per playlist. Each video has an unique id from 0 up to max_video_count which is determined on runtime (depending on the server).

What i do now is, i created a linked list which adds the unique id of each video played. Than i create randomly a random number between 0 and max_video_count , do linear search if the number is already in the linked list and if yes i calculate a new number.. and again linear search .. and so on!!

obvisiouly this isn’t very practical and sometimes it takes way to long to find an element. especially when a lot of videos were played already.

So i thought, i implement binear search instead of linear search but that brings me to the problem that i have to sort the list first. So, my next step was to think, that i sort the list while inserting the new unique_id and than do binary search.

I know that binary search is O(log n) compared to O(n) linear search which is a great advancement. But sorting the list is also O(n) because to find the right spot i would have to do linear search again….. So i come to the solution than that binary search would be O(log N * n) compared to O(n) linear search -> linear search fast. Is that right? Maybe my whole approach is wrong.. but i couldn’t come up with something better yet…

I am quite new to algorithms so it would be nice if someone could enlighten me here 🙂

Greetings
Markus

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:24:47+00:00Added an answer on May 27, 2026 at 2:24 am

    You are essentially just looking at a random permutation. Arrange your videos in one fixed list, and then, to create the playlist, produce a random permutation of that list and play the permuted list.

    A typical and efficient (O(n)) way to achieve such a permutation is via a Knuth Shuffle.

    (Practically, you can of course just create a random permutation of an index set and play the items in order of the permuted indices.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem solved, see below Question I'm working in Flex Builder 3 and I have
I am working a problem from the Stanford DB class and have a question.
I have the same question problem as described here How to purge a cached
I have a question regarding a problem with L2S, Autogenerated DataContext and the use
I have a question about a problem I'm struggling with. Hope you can bear
The responses I've got to this question have solved the problem I had in
Okay, so I have another question on a prolog homework problem I am struggling
I have asked this question before and the problem was half solved in the
I have a ridiculous question due to a ridiculous problem. Normally if I want
(I have a problem that I illustrated in this question but had no correct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.