Yeah you can prevent it, I did with a previous character, smacked the guy who was going to backstab her as soon as i entered the city. The quest still starts tho. I hate Markarth too but mostly due to how difficult it is to find your way around the city. It is a mess.
So many creepy, unpleasant and apparently unavoidable things happened to me the first couple times I ever went to Markarth... even though I got to like it a little better later on because of some of the nicer NPCs I met, it's just never lost that creepy cringe-inducing vibe for me.
I've never been able to prevent the killing, I think the one time I tried it happened anyway and I was right there in the middle of it and got waylaid into the convo that starts the quests. The last time I ended up with the note in my inventory and ignored it for a long time before I finally gave in.
I'm not sure but I think I may have avoided it this time so far... I saw the murder when I entered the city but I was working undercover for the Stormcloaks so I was able to RP myself a reason for completely avoiding the scene. I'd have to check my inventory to see if the damn note is there but IIRC I was able to walk around a different way and never got close enough to the scene to be pulled into the action. I think now it may just be a matter of not talking to any NPCs about the killing.
Of course I might go back there several weeks later to find the body and other witnesses still standing there, just waiting for me to come along. "Hey would you please come over here and get this quest going, this corpse is starting to stink up the marketplace and we can't move it until you ask us about it."
