DENVER  Senators John McCain and Barack Obama have begun recalibrating their strategies for the presidential campaign  and reconsidering some of their basic assumptions about which states and voters are in play  in a contest recast by Mr. McCain’s unexpected selection of Gov. Sarah Palin of Alaska as his running mate.

A day after Mr. McCain announced his decision, catching almost everyone but his inner circle by surprise, both sides were trying to gauge the risks and opportunities of having a young, relatively inexperienced, socially conservative woman on the Republican ticket.

The Obama campaign and the Democratic Party had prepared advertisements and lines of attack directed at the two men who had been most prominently mentioned as vice-presidential possibilities for Mr. McCain  former Gov. Mitt Romney of Massachusetts and Gov. Tim Pawlenty of Minnesota  but had not considered Ms. Palin a likely enough choice to do the same for her. A new advertisement linking President Bush to Mr. McCain was quickly put together, but it contained only a fleeting mention of Ms. Palin.

That tentativeness reflected what Mr. Obama’s advisers said was their struggle to figure out how to challenge the credentials and the ideology of a woman whose candidacy could be embraced by many women as a historic milestone. Once formally nominated at the Republican convention in Minneapolis-St. Paul this week, Ms. Palin, who was elected governor two years ago, will be the second woman chosen by a major party as a vice-presidential candidate.