×
Log in to StudySoup
Get Full Access to Introduction To Algorithms - 3 Edition - Chapter 8 - Problem 8-7
Join StudySoup for FREE
Get Full Access to Introduction To Algorithms - 3 Edition - Chapter 8 - Problem 8-7

Already have an account? Login here
×
Reset your password

The 0-1 sorting lemma and columnsort A compare-exchange

Introduction to Algorithms | 3rd Edition | ISBN: 9780262033848 | Authors: Thomas H. Cormen ISBN: 9780262033848 130

Solution for problem 8-7 Chapter 8

Introduction to Algorithms | 3rd Edition

  • Textbook Solutions
  • 2901 Step-by-step solutions solved by professors and subject experts
  • Get 24/7 help from StudySoup virtual teaching assistants
Introduction to Algorithms | 3rd Edition | ISBN: 9780262033848 | Authors: Thomas H. Cormen

Introduction to Algorithms | 3rd Edition

4 5 1 377 Reviews
27
4
Problem 8-7

The 0-1 sorting lemma and columnsort A compare-exchange operation on two array elements Ai and Aj , where i Aj 2 exchange Ai with Aj After the compare-exchange operation, we know that Ai Aj . An oblivious compare-exchange algorithm operates solely by a sequence of prespecified compare-exchange operations. The indices of the positions compared in the sequence must be determined in advance, and although they can depend on the number of elements being sorted, they cannot depend on the values being sorted, nor can they depend on the result of any prior compare-exchange operation. For example, here is insertion sort expressed as an oblivious compare-exchange algorithm: INSERTION-SORT.A/ 1 for j D 2 to A:length 2 for i D j 1 downto 1 3 COMPARE-EXCHANGE.A; i; i C 1/ for Chapter 8 209 The 0-1 sorting lemma provides a powerful way to prove that an oblivious compare-exchange algorithm produces a sorted result. It states that if an oblivious compare-exchange algorithm correctly sorts all input sequences consisting of only 0s and 1s, then it correctly sorts all inputs containing arbitrary values. You will prove the 0-1 sorting lemma by proving its contrapositive: if an oblivious compare-exchange algorithm fails to sort an input containing arbitrary values, then it fails to sort some 0-1 input. Assume that an oblivious compare-exchange algorithm X fails to correctly sort the array A1 : : n. Let Ap be the smallest value in A that algorithm X puts into the wrong location, and let Aq be the value that algorithm X moves to the location into which Ap should have gone. Define an array B1 : : n of 0s and 1s as follows: Bi D ( 0 if Ai Ap ; 1 if Ai > Ap : a. Argue that Aq > Ap, so that Bp D 0 and Bq D 1. b. To complete the proof of the 0-1 sorting lemma, prove that algorithm X fails to sort array B correctly. Now you will use the 0-1 sorting lemma to prove that a particular sorting algorithm works correctly. The algorithm, columnsort, works on a rectangular array of n elements. The array has r rows and s columns (so that n D rs), subject to three restrictions: r must be even, s must be a divisor of r, and r 2s2. When columnsort completes, the array is sorted in column-major order: reading down the columns, from left to right, the elements monotonically increase. Columnsort operates in eight steps, regardless of the value of n. The odd steps are all the same: sort each column individually. Each even step is a fixed permutation. Here are the steps: 1. Sort each column. 2. Transpose the array, but reshape it back to r rows and s columns. In other words, turn the leftmost column into the top r=s rows, in order; turn the next column into the next r=s rows, in order; and so on. 3. Sort each column. 4. Perform the inverse of the permutation performed in step 2. 210 Chapter 8 Sorting in Linear Time 10 14 5 8 7 17 12 1 6 16 9 11 4 15 2 18 3 13 (a) 412 835 10 7 6 12 9 11 16 14 13 18 15 17 (b) 4 8 10 12 16 18 137 9 14 15 256 11 13 17 (c) 136 257 4 8 10 9 13 15 11 14 17 12 16 18 (d) 1 4 11 3 8 14 6 10 17 2 9 12 5 13 16 7 15 18 (e) 1 4 11 2 8 12 3 9 14 5 10 16 6 13 17 7 15 18 (f) 5 10 16 6 13 17 7 15 18 1 4 11 2 8 12 3 9 14 (g) 4 10 16 5 11 17 6 12 18 1 7 13 2 8 14 3 9 15 (h) 1 7 13 2 8 14 3 9 15 4 10 16 5 11 17 6 12 18 (i) Figure 8.5 The steps of columnsort. (a) The input array with 6 rows and 3 columns. (b) After sorting each column in step 1. (c) After transposing and reshaping in step 2. (d) After sorting each column in step 3. (e) After performing step 4, which inverts the permutation from step 2. (f) After sorting each column in step 5. (g) After shifting by half a column in step 6. (h) After sorting each column in step 7. (i) After performing step 8, which inverts the permutation from step 6. The array is now sorted in column-major order. 5. Sort each column. 6. Shift the top half of each column into the bottom half of the same column, and shift the bottom half of each column into the top half of the next column to the right. Leave the top half of the leftmost column empty. Shift the bottom half of the last column into the top half of a new rightmost column, and leave the bottom half of this new column empty. 7. Sort each column. 8. Perform the inverse of the permutation performed in step 6. Figure 8.5 shows an example of the steps of columnsort with r D 6 and s D 3. (Even though this example violates the requirement that r 2s2, it happens to work.) c. Argue that we can treat columnsort as an oblivious compare-exchange algorithm, even if we do not know what sorting method the odd steps use. Although it might seem hard to believe that columnsort actually sorts, you will use the 0-1 sorting lemma to prove that it does. The 0-1 sorting lemma applies because we can treat columnsort as an oblivious compare-exchange algorithm. A Notes for Chapter 8 211 couple of definitions will help you apply the 0-1 sorting lemma. We say that an area of an array is clean if we know that it contains either all 0s or all 1s. Otherwise, the area might contain mixed 0s and 1s, and it is dirty. From here on, assume that the input array contains only 0s and 1s, and that we can treat it as an array with r rows and s columns. d. Prove that after steps 13, the array consists of some clean rows of 0s at the top, some clean rows of 1s at the bottom, and at most s dirty rows between them. e. Prove that after step 4, the array, read in column-major order, starts with a clean area of 0s, ends with a clean area of 1s, and has a dirty area of at most s2 elements in the middle. f. Prove that steps 58 produce a fully sorted 0-1 output. Conclude that columnsort correctly sorts all inputs containing arbitrary values. g. Now suppose that s does not divide r. Prove that after steps 13, the array consists of some clean rows of 0s at the top, some clean rows of 1s at the bottom, and at most 2s 1 dirty rows between them. How large must r be, compared with s, for columnsort to correctly sort when s does not divide r? h. Suggest a simple change to step 1 that allows us to maintain the requirement that r 2s2 even when s does not divide r, and prove that with your change, columnsort correctly sorts.

Step-by-Step Solution:
Step 1 of 3

4/4/16 Lecture 4 Social Psychology • scientific study of thoughts, feelings, and behaviors • Affect, Behavior, Cognition Social Influence • Group Conformity: adjusting beliefs, feelings, and behaviors to align with others in the group • Information social influence • influence from reliable information • private conformity—internal, personal beliefs changed • ex: interrogator asks a witness questions that are so convincing that the suspect becomes convinced that he actually did do it normative social influence • • influence based on social pressure • public conformity—external, change just to go with the group • ex: interrogator asks a witness questions for a long time and the suspect just admits that they did it after a while so that they can leave • Factors that influence conformity • number of people in a group • one person giving the correct response • one person giving the incorrect response • Obedience: engaging in a behavior that is commanded by an authority figure • can either be good (ex: obeying firefighter instructions) or bad (ex: becoming a Nazi) based on the outcome • Factors that decrease obedience • physical and psychological proximity to the learner • closer proximity increases personal responsibility • undermining authority • Bystander effect: presence of other people reduces the chance that any one person will help • Pluralistic ignorance • false belief that everyone else perceives a situation differently than you do but everyone feels the same way • ex: everyone in the group hates to drink and party but they all think that the rest of them do so they all go drink and party together • Kitty Genovese case: (she was stabbed to death) false belief: the situation wasn't an emergency (since nobody else was concerned) reality: it is an emergency influence on behavior: nobody helped • Diffusion of responsibility • the more people present in an emergency, the less each person feels responsible for helping • reducing the bystander effect: • point and direct “you call 911” “you get the life guard” • knowledge of the bystander effect Situational influences on helping • noticing the need to help • being in a happy mood • victim’s deservingness—people are more likely to help someone with a cane than a drunk person • time—more available time, the more likely they are to help 4/5/16 Lecture 5 • Deindividuation: tendency for people to engage in deviant behaviors when stripped of their typical identity • Is more likely to occur when: • you feel anonymous (ex: in costumes on Halloween, TPing houses) • you are adopting social roles (ex: in a group—mob riots) • you have low self-awareness (ex: headphones on and start singing out loud and not notice until you realize everyone is staring at you) demand characteristics: participants may act how they think the experimenters want them to act Social Perception • Social schema: mental structures that people use to organize their knowledge about the world • useful because they allow us to not become overwhelmed by all pieces of info • influence the info that we notice • influence the associations • Self-concept: knowledge about who we are and what we are like • comprised of multiple self-schemas • self-reference effect: perceiving that our own beliefs and viewpoints are the norm; overestimating the degree to which others share our beliefs • ex: talking about a favorite show with a friend that doesn't know about it and saying “What How do you not know about this show, it’s so great” • Social Comparison Theory: evaluating our abilities and comparing ourselves to other people • upward: comparing us to people who are better than us on a trait or ability • can be motivating, but might make us feel worse about ourselves • downward: comparing us to people who are worse than us on a trait or ability • not motivating, makes us feel better about ourselves • Perceiving others—the halo effect: the tendency for one positive characteristic of a person to transfer to judgements of other positive characteristics • common occurrence is for people that are attractive (good people in movies are generally attractive while the bad people are generally unattractive) • Trait Impressions: some traits are weighted more heavily than others • central traits: have large influence on impressions of other people • peripheral: have small influence on impressions of other people • Inferring traits from facial features • we judge “baby-faced” adults differently then “mature-faced” adults 4/6/16 Lecture 6 Attributions: inferences we make about the causes of other people’s behaviors • dispositional—attribution made to an internal cause of behavior • more likely to make these for other people’s behavior • situational—attribution made to external cause of behavior • more likely to make these for our own behaviors Intergroup Bias • Social Categorization: classification of people into groups based on common attributes • benefits: function as schemas, aids impression formation, saves time and energy • costs: overestimate between-group differences, underestimate within-group differences, basis for stereotyping and prejudice • Affect • prejudice: negative feelings or attitudes toward people based on their group membership • has become socially unacceptable: used to be overt, blatant; now is subtle, covert • Behavior • discrimination: negative behavior directed against people because of their group membership • can be negative behavior directed against a certain group or preferential treatment for one group over another • blatant ex: writing hateful things toward a group on buildings • subtle ex: music auditions by gender • Cognition • stereotypes: cognitive beliefs that associate people with certain traits based on their group membership • culturally pervasive • observations from environment • expected social roles • subtyping • exceptions to stereotype (ex: working women (vs stay at home women)) • Positive stereotype (ex: women are kind and nurturing) consequences positive: conform to expectations • • negative: inaccurate impressions, can justify pre-existing social hierarchies • prejudice, discrimination, and stereotypes are independent, consequential, and bi-directional (one can lead to the other and visa versa) • In-groups and out-groups • out-group homogeneity: tendency to view outgrip members as highly similar and to view the members of our own in-group as more diverse • in-group bias: preference for in-group over out-group • reducing intergroup bias • motivation • contact hypothesis • Robbert’s Cave Study • tested how to reduce intergroup conflict between 5th grade boys • Stereotype Threat: apprehension that one’s behavior might confirm a stereotype while in a stereotype relevant situation • impairs performance in the stereotyped domain • ex: Steele andAronson, 1995 4/7/16 Lecture 7 Personality Psychology • personality: the unique and relatively enduring set of thoughts, feelings, behaviors, and motives that characterize an individual Major theoretical approaches • PsychoanalyticApproach • unconscious forces drive personality and behavior and they can express themselves in distorted forms • Frued’s (1856-1939) model of the mind • Id—seeks pleasure, impulsive • Ego—makes realistic attempt to satisfy id’s desires • Superego—sense of conscience and morality • unconscious defense mechanisms: used to protect against anxiety-provoking thoughts and feelings and against threats from the outside world • repression, reaction formation, projection, sublimation, etc. • Neo-Freudians similarities: unconscious processes, importance of early childhood experiences • • differences (from Freud): less emphasis on sexuality and more on social drives, more optimistic about personality chance • Behavioral and Social LearningApproach • personality shaped by learned behaviors • behavioral learning: adopting behaviors that have been associated with good outcomes • social learning: personality development also involves thought and cognition • social observation (bobo doll experiment) • watch video • HumanisticApproach • self-actualization (being the best person you can be) as core motive • free-will (people have complete control over their actions) • optimistic about human nature (people are inherently good) • approach came form the humanistic movement • Two prominent theorists: • Carl Rogers • achieve fulfillment by receiving unconditional positive regard • people need to feel completely accepted • Abraham Maslow • people can only achieve self-actualization after they have reached all of their needs from the hierarchy of needs (from bottom to top: physiological, safety and security, love and belonging, self-esteem, self-actualization) • BiologicalApproach • assumes that differences in personality are based in part on physiological differences • genes, central nervous system, neurotransmitters, hormones • Hans Eysenck model • genes—> arousal, sensitivity to stimulation—> personality, cognition, behavior • three dimensions of personality • neuroticism, extraversion, psychoticism • cortical arousal • introverts—higher baseline levels • extroverts—lower baseline levels • Twin studies: measuring the correlations of personality traits among twins • correlations between twins raised together and twins raised apart were very similar in the Minnesota Twin Study • Conclusions: • personality traits are at least partially heritable • much of the variability in personality is due to environmental factors • TraitApproach identifies major personality traits that are consistent across situations and stable across time • • comparative because the amount of traits in people can be compared between people • predict behaviors and important life outcomes • Big Five Model (O.C.E.A.N.) • openness to experience: how open people are to experience different things • conscientiousness: how reliable, organized, and dependable someone is • extraversion: outgoing • agreeableness: how well someone gets along with people • neuroticism: being sensitive to stress • traits are dimensional and change across lifespan • conscientiousness and agreeableness tend to increase

Step 2 of 3

Chapter 8, Problem 8-7 is Solved
Step 3 of 3

Textbook: Introduction to Algorithms
Edition: 3
Author: Thomas H. Cormen
ISBN: 9780262033848

Other solutions

People also purchased

Related chapters

Unlock Textbook Solution

Enter your email below to unlock your verified solution to:

The 0-1 sorting lemma and columnsort A compare-exchange